-2

我必须在适配器类的列表视图项中单击图像时导航到另一个活动。这是我的适配器类:

 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);

有什么建议么??

4

4 回答 4

0

利用

ActivityName.this.startActivity(intent) 

在你的情况下使用

 a.startActivity(intent) 

或检查您的清单中是否声明了 UserSetting 活动。

于 2013-01-21T10:38:06.837 回答
0

试试这个链接

context.startActivity(context, GoToClass.class);
于 2013-01-21T10:42:34.213 回答
0

改用活动上下文..

activity.startActivity(intent);
于 2013-01-21T10:44:30.270 回答
0

尝试这个:

  Intent intent = new Intent(RestaurantAdapter.this, UserSettings.class);

            startActivity(intent);
于 2013-01-21T10:40:47.310 回答