从onclicklistener开始意图 [英] Starting intent from onclicklistener
本文介绍了从onclicklistener开始意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从一个自定义的onclick监听器启动一个新的活动。但它无法从听者的onclick访问MainActivity实例。此外,它显示了错误的意向构造。这里是我的code:
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);
}
}
感谢您提前帮助。
推荐答案
修改您的code为:
@Override
public void onClick(View view) {
// TODO Auto-generated method stub
Intent intent=new Intent(view.getContext(),ChartImageActivity.class);
intent.putExtra("chartLink", ChartLink);
startActivity(intent);
}
这篇关于从onclicklistener开始意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文