I want to launch an intent but it gives me an error and I can't find the reason. Any suggestions. It gives me the error when creating the intent:
@Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
tempChild = (ArrayList<String>) Childtem.get(groupPosition);
TextView text = null;
if (convertView == null) {
convertView = minflater.inflate(R.layout.childrow, null);
}
text = (TextView) convertView.findViewById(R.id.textView1);
text.setText(tempChild.get(childPosition));
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dato = tempChild.get(childPosition);
Toast.makeText(activity, dato,
Toast.LENGTH_SHORT).show();
Intent intent = new Intent(NewAdapter.this, Ficha.class);
intent.putExtra("id", id);
activity.startActivity(intent);
}
});
return convertView;
}
NewAdapter.java is a class that extends from BaseExpandableListAdapter.
You are using the adapter as the context of the intent. I assume that 'activity' is the activity from which the adapter is called, so it would look like this:
What is definitely needed is the context of the Activity :
but it is important to mention that to do this, since it is done inside a class that extends from
BaseExpandableListAdapter
:you need a method that receives the context and that method is
setInflater()
:The class must receive the context in some way to use it in the
Intent
.