本文介绍了如何调用驻留在ListView项按钮的onclick监听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有,我想点击列表视图按钮,但问题是,在点击,presently它无法识别监听呼叫是否是列表视图或一个按钮,
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,
在此先感谢...:)
推荐答案
不要设置列表视图监听器,如果你不想处理点击整个列表项。您可以设置个人看法监听器列表项像下面的例子给出:
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;
}
}
这篇关于如何调用驻留在ListView项按钮的onclick监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!