I am trying to start a new activity from a custom onclick listener. But its unable to access MainActivity instance from onclick listener. Also, its showing wrong constructor for intent. Here is my code:
public class ChartClickListener implements OnClickListener {
private String ChartLink;
public ChartClickListener(String chartLink){
this.ChartLink=chartLink;
}
@Override
public void onClick(View view) {
// TODO Auto-generated method stub
Intent intent=new Intent(MainActivity.this,ChartImageActivity.class);
intent.putExtra("chartLink", ChartLink);
startActivity(intent);
}
}
Thanks for the help in advance.
pass activity context to custom onclick listener and use that context to startactivity
set setOnClickListener as
try like this
Hope It will work
I try this and it work, i want to show a Toast, and then transfer to a new Activity.
}
Modify your code as:
Replace
MainActivity.this
withview.getContext()
and it will work.