我有一個自定義的CursorAdapter,它看起來像:爲什麼我的listview不可選?
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);
在列表視圖中的項目都沒有可選擇..有誰知道最新錯誤?我已將項目設置爲可調焦,但無法點擊。幫幫我!謝謝!
爲此,你需要實現'onItemClickListener' – waqaslam 2012-03-16 15:27:45