我正在使用适配器类来填充我的列表视图,但是我的列表视图中的每个项目都有两个文本视图,我想要setOnClick监听器。所以我将它设置在适配器类中,当我尝试显示吐司时它工作正常。可以显示吐司但不能启动活动
但问题是我不能在OnClickListener的startActivity。该应用程序崩溃。请帮助或建议一种替代方法来实现相同。 该活动已在Manifest中提及。
这是我的代码: -
public class Adapter_NearMe_TyreWorx extends ArrayAdapter<List_NearMe> implements View.OnClickListener {
ArrayList<List_NearMe> arraylist;
private Context context;
private List<List`enter code here`_NearMe> list;
public Adapter_NearMe_TyreWorx(Context context, int resource, List<List_NearMe> objects) {
super(context, resource, objects);
this.context = context;
this.List = objects;
arraylist = new ArrayList<List_NearMe>();
arraylist.addAll(List);
}
TextView Btn_Call;
String Fac_landmark;
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.canvas_two, parent, false);
List_NearMe list= list.get(position);
String Fac_name=list.getName();
Fac_landmark=list.getLandmark();
String Fac_gMap=list.getgMap();
String Fac_contact=list.getContact();
TextView distance=(TextView)view.findViewById(R.id.fac_distance);
TextView Fac_Name=(TextView)view.findViewById(R.id.fac_name);
TextView Fac_Address=(TextView)view.findViewById(R.id.fac_address);
Btn_Call=(TextView)view.findViewById(R.id.btn_call);
TextView Btn_Go=(TextView)view.findViewById(R.id.btn_go);
Btn_Go.setOnClickListener(this);
return view;
}
public void onClick(View v) {
Toast.makeText(getContext(),"Toast text",LENGTH.SHORT).show(); //working toast code
Intent intent = new Intent(getContext(), SampleActivity.class);
getContext().startActivity(intent);
}
}
您可以在崩溃后发布logcat吗?并且SampleActivity类的代码 – NitroNbg