我已经制作了一个BaseAdapter,当项目被选中时(橙色背景)没有显示行上的onclick效果。
我想知道出现OnClickedItem效果需要什么。我试图在列表中设置OnItemClickListener,但它没有帮助。
这是我的代码:
private class MyAdapter extends BaseAdapter{
private Bingo activity;
public MyAdapter(Bingo context){
this.activity = context;
items = new ArrayList<String>();
}
public void add(String item){
items.add(item);
notifyDataSetChanged();
}
public void clear(){
items.clear();
notifyDataSetChanged();
}
private ArrayList<String> items;
public int getCount() {
return items.size();
}
public Object getItem(int position) {
return items.get(position);
}
public long getItemId(int position) {
return position;
}
public boolean isEnabled(int position){
return true;
}
public View getView(int position, View convertView, ViewGroup parent) {
if(position == getCount() - 5 && getCount() < 100){
Log.d("dbg","Autoadding...");
activity.add();
}
View view = null;
if (convertView == null) {
Log.i("dbg","new:"+position);
view = View.inflate(activity, R.layout.item, null);
}
else {
Log.i("dbg","recycle:"+position);
view = convertView;
}
TextView text = (TextView)view.findViewById(R.id.text);
text.setText(items.get(position)+" -------> pos:"+position);
return view;
}
}
夸大的item.xml ......
LinearLayout
android:id="@+id/root"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:layout_marginRight="10dp"
android:src="@drawable/icon"
LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFF"
android:singleLine="true"
Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OK"
android:layout_gravity="right"
android:gravity="center_horizontal"
android:inputType="textUri"
/LinearLayout
/LinearLayout
答案 0 :(得分:2)
试试这个 对于ListView,
final ListView list = (ListView) findViewById(R.id.list);
list.setItemsCanFocus(false);
另外,请确保Button inside list item设置为focusable false
android:focusable="false"
android:focusableInTouchMode="false"
答案 1 :(得分:1)
哦,我想我发现了问题...它的按钮......如果我从充气的视图中删除按钮,可以选择行....如果按钮在那里我只能点击/专注于按钮......