Boa noite, estou tentando chamar uma activty por um Adapter por meio de intent, mas dá o seguinte erro:
FATAL EXCEPTION: main Process: com.compscitutorials.basigarcia.navigationdrawervideotutorial, PID: 20374 android.content.ActivityNotFoundException: Unable to find explicit activity class {com.compscitutorials.basigarcia.navigationdrawervideotutorial/br.com.projeto.caminhossembarreiras.activity.Activity_Acess}; have you declared this activity in your AndroidManifest.xml? at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1885) at android.app.Instrumentation.execStartActivity(Instrumentation.java:1697) at android.app.Activity.startActivityForResult(Activity.java:4557) at android.app.Activity.startActivityFromFragment(Activity.java:4543) at android.app.Activity$HostCallbacks.onStartActivityFromFragment(Activity.java:6623) at android.app.Fragment.startActivity(Fragment.java:1092) at android.app.Fragment.startActivity(Fragment.java:1071) at br.com.projeto.caminhossembarreiras.AcessFragment.onItemClick(AcessFragment.java:39) at android.widget.AdapterView.performItemClick(AdapterView.java:310) at android.widget.AbsListView.performItemClick(AbsListView.java:1145) at android.widget.AbsListView$PerformClick.run(AbsListView.java:3049) at android.widget.AbsListView$3.run(AbsListView.java:3886) at android.os.Handler.handleCallback(Handler.java:746) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5443) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Fragment do Adapter:
public class AcessFragment extends Fragment implements AdapterView.OnItemClickListener {
private ListView lista;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_acess, container, false);
lista = (ListView) rootView.findViewById(R.id.lista);
lista.setAdapter(new AdapterAcess(getContext()));
lista.setOnItemClickListener(this);
return rootView;
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int idx , long id) {
if (idx == 0) {
Intent it = new Intent(getContext(), Activity_Acess.class);
startActivity(it);
} else if (idx == 1) {
} else if (idx == 2) {
} else if (idx == 3) {
} else if (idx == 4) {
}
}
XML:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="@+id/lista"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#ececec"
android:padding="10dp"
android:dividerHeight="2sp"
/>
Adapter:
public class AdapterAcess extends BaseAdapter {
private String[] itens = new String[]{"Acessibilidade", "Seus Direitos", "Outros"};
private Context context;
public AdapterAcess(Context context){
super();
this.context = context; // O context é necessario para criar a view.
}
@Override
public int getCount() {
return itens.length; // Retorna a quantida de itens do adapter.
}
@Override
public Object getItem(int position) {
return itens[position]; // Retorna o objeto para esta posição.
}
@Override
public long getItemId(int position) {
return position; // Retorna o id do obejto para esta posição;
}
@Override
// Retorna o view para esta posição.
public View getView(int position, View convertView, ViewGroup parent) {
String lista = itens[position];
TextView t = new TextView(context);
float dip = 50;
float densidade = context.getResources().getDisplayMetrics().density; // Densidade da tela.
int px = (int) (dip * densidade + 0.5f);
t.setHeight(px);
t.setText(lista);
return t;
}
}