In my application, I have added one button named as 'add'. If I click that button, I want to perform some another activity. But if I click the button, nothing happens. Can anyone please tell me what is my mistake?
ListViewAdapter
class:
public class ListViewAdapter extends BaseAdapter {
// Declare Variables
Context context;
LayoutInflater inflater;
ArrayList<HashMap<String, String>> data;
ImageLoader imageLoader;
HashMap<String, String> resultp = new HashMap<String, String>();
public ListViewAdapter(Context context,
ArrayList<HashMap<String, String>> arraylist) {
this.context = context;
data = arraylist;
imageLoader = new ImageLoader(context);
}
@Override
public int getCount() {
return data.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
/* private view holder class */
private class ViewHolder {
Button Add;
}
public View getView(final int position, View convertView, ViewGroup parent) {
// Declare Variables
TextView title;
ViewHolder holder = null;
ImageView thumb_url;
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.listview_item, null);
holder = new ViewHolder();
holder.Add = (Button) convertView.findViewById(R.id.add);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
convertView.setTag(holder);
}
//View itemView = mInflater.inflate(R.layout.listview_item, parent, false);
// Get the position
resultp = data.get(position);
// Locate the TextViews in listview_item.xml
title = (TextView) convertView.findViewById(R.id.rank);
// Locate the ImageView in listview_item.xml
thumb_url = (ImageView) convertView.findViewById(R.id.flag);
// Capture position and set results to the TextViews
title.setText(resultp.get(MainActivity.TITLE));
// Capture position and set results to the ImageView
// Passes flag images URL into ImageLoader.class
imageLoader.DisplayImage(resultp.get(MainActivity.THUMB_URL), thumb_url);
// Capture ListView item click
Button Add = (Button) convertView.findViewById(R.id.add);
try {
holder.Add.setOnClickListener(new OnClickListener() {
@SuppressWarnings("unused")
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
try {
//call ur intent here
Intent in = new Intent(getApplicationContext(), First.class);
startActivity(in);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return convertView;
}
protected Context getApplicationContext() {
// TODO Auto-generated method stub
return null;
}
protected void startActivity(Intent in) {
// TODO Auto-generated method stub
}
}