我有一个自定义的CursorAdapter,它看起来像:
public class LabelAdapter extends CursorAdapter {
Context con;
LayoutInflater mFactory;
public AlarmTimeAdapter(Context context, Cursor c) {
super(context, c);
con = context;
mFactory = LayoutInflater.from(con);
}
@Override
public void bindView(View view, final Context context, Cursor cursor) {
final String label2 = cursor.getString(AlarmData.ALARM_TITLE_INDEX);
..code to fill in the textview with whats in the cursor
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View ret = mFactory.inflate(R.layout.item_lv, parent, false);
return ret;
}
}
我的item_lv看起来像是:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:focusable="true"
>
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="14dp"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
我打电话的时候:
ListView lv = (ListView)findViewById(R.id.listview); //Listview is in the main.xml file
lv.setAdapter(new LabelAdapter(this, mCursor);
lv.setFocusable(true);
列表视图中的项目无法选择..有谁知道什么是错的?我已将项目设置为可聚焦,但无法单击它们。救命!谢谢!
答案 0 :(得分:0)
从RelativeLayout中移除物品的android:focusable =“true”。
答案 1 :(得分:0)
将onItemClickListener
设置为listView -
lv.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> adapter, View view, int position,
long arg3) {
});
答案 2 :(得分:0)
我相信答案非常简单。设置.xml中的textview应该是
Android:Clickable =“True”
这样做的原因是,如果您将其作为行放置,则必须可以点击它们才能识别点击事件。