0

I have some code that displays a ListView and allows an item to be clicked to take it to a single view activity. However, for some reason the onClickListener isn't working. I thought that this may be due to the EditText being focusable. However, upon setting this to false, I found it was not the case.

listview_item.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5sp"
android:textSize="15dp"
android:inputType="textMultiLine">


</TextView>

3 Answers3

0

Remove the inputType attribute on you TextView layout:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/text"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:padding="5dp"
          android:textSize="15sp"/>

Also as you can see I'm using the match_parent and wrap_content for width and height respectively. fill_parent is deprecated now.

Match parent means it will fit the whole ListView in width and wrap content is that the hieght will span as much as needed, therefore the whole text will be visible, even if it's multi-line.

Another note: for text sizes you use sp for widths, heights, etc you use dp. Worthy article explains it further.

Community
  • 1
  • 1
Simas
  • 43,548
  • 10
  • 88
  • 116
0

Background tasks once executed will not have a handle. So your listview listener will be killed. You need to remove it from the background and have it in your onCreate. You can set a flag in postExecute and do implementation if it is dependent on that.

JourneyWithAndroid
  • 250
  • 2
  • 5
  • 19
0

Use android:descendantFocusability="blocksDescendants" in your list item layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:descendantFocusability="blocksDescendants">

    <TextView 
        android:id="@+id/text"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="5sp"
        android:textSize="15dp"
        android:inputType="textMultiLine" />

</LinearLayout>

Replaced fill_parent by match_parent as it's deprecated.

Juanjo Vega
  • 1,410
  • 1
  • 12
  • 20