我必须导航到适配器类的listview项目中的另一个活动。 这是我的适配器类:
public class RestaurantAdapter extends BaseAdapter {
private Activity activity;
private ArrayList<String> rest,location,id;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader;
Context c;
public RestaurantAdapter(Activity a,Context context, ArrayList<String> restaurants, ArrayList<String> location2 ,ArrayList<String> restid) {
activity = a;
rest=restaurants;
location=location2;
id=restid;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// imageLoader=new ImageLoader(activity.getApplicationContext());
c=context;
}
public int getCount() {
return rest.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.listview_layout, null);
vi.setClickable(true);
vi.setFocusable(true);
TextView text=(TextView)vi.findViewById(R.id.txt);;
TextView f=(TextView)vi.findViewById(R.id.cur);;
TextView r=(TextView)vi.findViewById(R.id.resid);;
ImageView image=(ImageView)vi.findViewById(R.id.list_image);
text.setText(rest.get(position));
f.setText(location.get(position));
r.setText(id.get(position));
image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent=new Intent(c,UserSettings.class);
intent.putExtra("id",id.get(position) );
intent.putExtra("resname", rest.get(position));
intent.putExtra("location", location.get(position));
c.startActivity(intent);
}
});
return vi;
}
但它在这一行上给我例外
c.startActivity(intent);
任何建议??
答案 0 :(得分:0)
使用
ActivityName.this.startActivity(intent)
在你的情况下使用
a.startActivity(intent)
OR 检查您的Manifest中是否声明了UserSetting活动..
答案 1 :(得分:0)
试试这个:
Intent intent = new Intent(RestaurantAdapter.this, UserSettings.class);
startActivity(intent);
答案 2 :(得分:0)
试试这个link
context.startActivity(context, GoToClass.class);
答案 3 :(得分:0)
请改用活动上下文..
activity.startActivity(intent);