Using the Image button, in each list item row and trying to start a new activity

advertisements

I am using image button, in each listview item row and trying to start a new activity using Button onClick listener, but getting:- the source attachment does not contain source for the ComponentName.class

package com.example.androidhive;

public class LazyAdapter extends BaseAdapter {

protected static final Context Context = null;
private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader; 

public LazyAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
    activity = a;
    data=d;
    inflater = (LayoutInflater)activity.
  getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    imageLoader=new ImageLoader(activity.getApplicationContext());
}

public int getCount() {
    return data.size();
}

public Object getItem(int position) {
    return position;
}

public long getItemId(int position) {
    return position;
}

public View getView(int position, View convertView, ViewGroup parent) {
    View vi=convertView;
    if(convertView==null)
        vi = inflater.inflate(R.layout.list_row, null);

    TextView title = (TextView)vi.findViewById(R.id.title);
    TextView artist = (TextView)vi.findViewById(R.id.description);
    TextView duration = (TextView)vi.findViewById(R.id.cost);
    TextView regular = (TextView)vi.findViewById(R.id.regular);
    TextView small = (TextView)vi.findViewById(R.id.small);
    TextView large = (TextView)vi.findViewById(R.id.large);
    ImageView thumb_image=(ImageView)vi.findViewById(R.id.item_image);
    ImageButton btn_add=(ImageButton)vi.findViewById(R.id.addorder);

    HashMap<String, String> song = new HashMap<String, String>();

    song = data.get(position);

    // Setting all values in listview
    title.setText(song.get(CustomizedListView.KEY_TITLE));
    artist.setText(song.get(CustomizedListView.KEY_DESC));
    duration.setText(song.get(CustomizedListView.KEY_COST));
    regular.setText(song.get(CustomizedListView.KEY_REGULAR));
    small.setText(song.get(CustomizedListView.KEY_SMALL));
    large.setText(song.get(CustomizedListView.KEY_LARGE));

    imageLoader.DisplayImage(song.get(CustomizedListView.KEY_THUMB_URL), thumb_image);

    btn_add.setOnClickListener(new OnClickListener()
    {
        public void onClick(View v)
        {
           Intent intent = new Intent(Context, FinalOrder.class);
           startActivity(intent);
        }
    });

    return vi;

   }

protected void startActivity(Intent intent) {
    // TODO Auto-generated method stub

}

  }


your adapter is returning you a view. right?

now in your onitemclickListener

ImageButton myImageButton = (ImageButton) view.findViewById(R.id.addorder);

now apply onclicklistener on your myImageButton.