Reputation: 9023
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
View v = null;
if( convertView != null )
v = convertView;
else
v = inflater.inflate(R.layout.child_row, parent, false);
Color c = (Color)getChild( groupPosition, childPosition );
TextView color = (TextView)v.findViewById( R.id.childname );
if( color != null )
color.setText( c.getColor() );
TextView rgb = (TextView)v.findViewById( R.id.rgb );
if( rgb != null )
rgb.setText( c.getRgb() );
// CheckBox cb = (CheckBox)v.findViewById( R.id.check1 );
// cb.setChecked( c.getState() );
Button btnPlay=(Button)v.findViewById(R.id.Play);
Button btnDelete=(Button)v.findViewById(R.id.Delete);
Button btnEmail=(Button)v.findViewById(R.id.Email);
btnPlay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Log.i("TEST ", "play btn cliked");
Intent i=new Intent(this,FindFilesByType.class);//THIS IS NOT ALLOWED IN MY CODE
}
});
return v;
}
In the code above, I've written my adapterclass. There are 3 buttons in my explandable list as a child. I want to call another Java class on button's click event, so, when I am using:
Intent i=new Intent(this,FindFilesByType.class);
I am getting this:
The constructor Intent(new View.OnClickListener(){}, Class<FindFilesByType>) is undefined
Remove arguments to match 'Intent'
What is wrong with what I am doing?
Upvotes: 0
Views: 933
Reputation: 9023
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
View v = null;
if (convertView != null)
v = convertView;
else
v = inflater.inflate(R.layout.child_row, parent, false);
Rington c = (Rington) getChild(groupPosition, childPosition);
TextView color = (TextView) v.findViewById(R.id.childname);
if (color != null)
color.setText(c.getColor());
TextView rgb = (TextView) v.findViewById(R.id.rgb);
if (rgb != null)
rgb.setText(c.getRgb());
Button btnPlay = (Button) v.findViewById(R.id.Play);
Button btnDelete = (Button) v.findViewById(R.id.Delete);
Button btnEmail = (Button) v.findViewById(R.id.Email);
btnPlay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
//code
}
});
btnDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
//code
}
});
btnEmail.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
//code
}
});
return v;
}
this above methos into the adapter class this is fully working code for me :)
Upvotes: 0
Reputation: 2683
At the start, create intance variable before onCreate() method like
public static InstanceTest instance;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
instance=this;
}
And called that variable in your child on click event
public void onClick(View arg0) {
Intent i=new Intent(instance,FindFilesByType.class);//This time it will be allowed
}
Hope this can help.
Upvotes: 1
Reputation: 3772
The this
object in your Intent constructor is the anonymous OnClickListener class instance, as opposed to your current context. What you need to do is to use the current context in that constructor like:
Intent i = new Itent(getContext(), FindFilesByType.class);
Upvotes: 1