i've a problem with my ListView: the (customized) items are only clickable on the divider. I've looking a few hours for a solution but nothing worked for me.
android:descendantFocusability="blocksDescendants" dosen't work correctly. Setting focusable=„false“ on each childitem dosen't work too. does anyone know a solution for this issue?
ItemLayout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:paddingTop="@dimen/padding"
android:paddingBottom="@dimen/padding"
android:paddingLeft="@dimen/padding"
android:paddingRight="@dimen/padding"
android:layout_width="match_parent"
android:descendantFocusability="blocksDescendants"
android:layout_height="wrap_content" >
<TextView
android:layout_width="match_parent"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_height="wrap_content"
style="@style/elremFontMedium"
android:id="@+id/detailNoticeText" />
</LinearLayout>
This ist my ListView
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/detailNoticeListView"/>
As Adapter I used a CursorAdapter
public class NoticeAdapter extends CursorAdapter {
public NoticeAdapter(Context context, Cursor cursor) {
super(context, cursor, 0);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View retView = inflater.inflate(R.layout.contact_detail_notice_item, parent, false);
return retView;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView textViewNotice = (TextView) view.findViewById(R.id.detailNoticeText);
textViewNotice.setText(cursor.getString(cursor.getColumnIndex(DatabaseHelper.NOTICE_TABLE_COLUMN_TEXT)));
}
}
The onItemClick is in my Fragmant
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
switch(adapterView.getId()) {
case R.id.detailNoticeListView:
Cursor cursor = mNoticeAdapter.getCursor();
cursor.moveToPosition(i);
TextView textView = (TextView) view.findViewById(R.id.detailNoticeText);
Bundle bundle = new Bundle();
bundle.putString(NoticeDialog.EDIT_TEXT_ID, cursor.getString(cursor.getColumnIndex("_id")));
bundle.putString(NoticeDialog.EDIT_TEXT, textView.getText().toString());
NoticeDialog noticeDialog = new NoticeDialog();
noticeDialog.setTargetFragment(this, 0);
noticeDialog.setArguments(bundle);
noticeDialog.show(getFragmentManager(),"noticeDialog");
break;
}
}
I've solved the problem. The reason was that I modify the TextView Style like this.
<style name="elremFontMedium" parent="@android:style/TextAppearance.Medium">
<item name="android:textSize">20dp</item>
<item name="android:textIsSelectable">true</item>
</style>
The problem was <item name="android:textIsSelectable">true</item>
.
So I removed this attribute and all works fine.