i have a button on the listview which i want to click ,but the problem is that on click ,presently it is not able to recognize the listener call whether it is of listview or a button,
thanks in advance... :)
i have a button on the listview which i want to click ,but the problem is that on click ,presently it is not able to recognize the listener call whether it is of listview or a button,
thanks in advance... :)
Do not set listener on listview if you don't want to handle click on entire list item. You can set listener for individual view on list item like given in below example:
public class MyArrayAdapter extends ArrayAdapter<Map<String, String>> {
private Context mContext;
public MyArrayAdapter(Context context, int textViewResourceId,
List<Map<String, String>> objects) {
super(context, textViewResourceId, objects);
mContext = context;
}
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(
R.layout.list_row, null, false);
}
final Map<String, String> data = (Map<String, String>) getItem(position);
ImageView imageView = (ImageView) convertView
.findViewById(R.id.imageView);
imageView.setImageResource(Integer.parseInt(data.get("image")));
TextView textView = (TextView) convertView
.findViewById(R.id.textViewTitle);
textView.setText(data.get("name"));
Button button = (Button) convertView
.findViewById(R.id.buttonShow);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mContext.startActivity(new Intent(mContext,
DetailActivity.class).putExtra(EXTRA_IMAGE_URL,
data.get("url")));
}
});
return convertView;
}
}
You need to add the button.setOnClickListener()
inside the getView()
function of the list adapter.
First you need create custom Adapter extends ArrayAdapter or BaseAdapter and he has getView method. inside this method you can set OnlickListener to button.
Link example create custom Adapter:
http://developer.android.com/reference/android/widget/Adapter.html