我已通过为每一行扩展ListView
来实施自定义LinearLayout
。每行都有一个小缩略图,一个文本和一个check box
。 list view
已正确部署,我可以毫无问题地滚动和浏览它。
但是ListView
似乎根本没有响应setOnItemClickListener()
,所以我必须通过在每行的文本getView()
中设置点击监听器来找到解决方法当我试图重用adapter
时,这显然会产生问题。有没有人有解决方案?
答案 0 :(得分:44)
试试这个 对于ListView,
final ListView list = (ListView) findViewById(R.id.list);
list.setItemsCanFocus(false);
另外,请确保CheckBox内的列表项设置为focusable false
android:focusable="false"
android:focusableInTouchMode="false"
答案 1 :(得分:6)
对于将项目视图设置为CheckBox的ListView
android:focusable="false"
android:clickable="false"
答案 2 :(得分:0)
您是否在扩展适配器类中创建了任何ViewHolder?如果是,那么在setOnItemClickListener()中创建一个占位符的实例可能会像这样工作。
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
View rowView = v;
if (rowView == null) {
LayoutInflater inflater = this.getLayoutInflater();
// GET INFLATE OF YOUR LAYOUT.
rowView = inflater.inflate(R.layout.projectpeopledescrate, null);
// CUSTOM ViewHolder Class Created in Adapter.
// name,title,comment are my components on the same listview clicked item.
PPDViewHolder viewHolder = new PPDViewHolder();
viewHolder.name = (TextView) rowView.findViewById(R.id.ppeopledescrvname);
viewHolder.title = (TextView) rowView.findViewById(R.id.ppeopledescrvtime);
viewHolder.comment = (TextView) rowView.findViewById(R.id.ppeoplervcomment);
viewHolder.hiddenLayout = (RelativeLayout) rowView.findViewById(R.id.hiddenCommentPanel);
rowView.setTag(viewHolder);
}
// ANOTHER object instance to apply new changes.
PPDViewHolder holder = (PPDViewHolder) rowView.getTag();
// I've setted up visibility over the components. You can set your onClickListener over your buttons.
holder.comment.setVisibility(View.GONE);
holder.name.setVisibility(View.GONE);
holder.title.setVisibility(View.GONE);
holder.hiddenLayout.setVisibility(View.VISIBLE);
holder.hiddenLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.MATCH_PARENT));
holder.hiddenLayout.bringToFront();
}
希望,你想要一样的东西。祝你好运!
答案 3 :(得分:0)
我有这段代码
this.mListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Log.v(TAG,"loul");
}
});
但它不起作用
所以我让juste把一个onItemSelectedListener放在它下面并且它工作Oo:
this.mListView.setItemsCanFocus(false);
this.mListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
Log.v(TAG,"loul");
}
});
//listener for nothing but it allow OnItemClickListener to work
this.mListView.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
答案 4 :(得分:0)
设置这些属性:
v.imageView.setFocusable(false);
v.imageView.setFocusableInTouchMode(false);
用于 list_item.xml 文件中的所有UI元素。
如果您的适配器集中未解决此问题:
Virtus