user3740085
user3740085

Reputation: 244

Listview click listener not responding

I have a list view and want to perform clickable event on it. I did it before. but now its not working. I have added my XML as well. I just need to move from one actvity to other on click in list view.

      CustomFinalSubmit_ItemDetail item = new  CustomFinalSubmit_ItemDetail(Final_Submit.this , R.layout.customview_finalsubmit_itemdetails, itemInfo);
    itemList.setAdapter(item);
    itemList.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int position,
                long arg3) {
            FinalSubmitItem pos = itemInfo.get(position);
            String itemType = pos.getItemType();
            String itemCountry = pos.getItemCountry();
            String itemSerial = pos.getItemNo();
            pos.setChecked(true);

            Intent inn = new Intent(getApplicationContext(), FinalSubmitDetails.class);
            inn.putExtra("itemType", itemType);
            inn.putExtra("itemCountry", itemCountry);
            inn.putExtra("itemSerial", itemSerial);
            startActivity(inn);
        }

    });

Here is my main Xml:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/green">  
<LinearLayout 
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill"
android:layout_marginTop="10dip"
android:orientation="vertical"
android:background="#0B3B0B">
<ListView 
 android:id="@+id/CustomerDetailList"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:background="@color/yellow"/>

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dip"
    android:orientation="vertical">
   <LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <TextView 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="3"
        android:id="@+id/Itemtype"
        android:paddingTop="5dp"
        android:background="@color/green"
        android:textColor="@color/yellow"
        android:layout_marginLeft="5dip"
        android:text="Item Type"/>
    <TextView 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="3"
        android:paddingTop="5dp"
        android:id="@+id/txtcountry"
        android:background="@color/green"
        android:textColor="@color/yellow"
        android:text="Country"/>
    <TextView 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="3"
        android:paddingTop="5dp"
        android:id="@+id/txtItemNumber"
        android:background="@color/green"
        android:textColor="@color/yellow"
        android:text="Item No."/>
     <CheckBox 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="4"
        android:id="@+id/itemChck"
        android:button="@drawable/custom_checkbox"
        android:paddingTop="5dp"
        android:padding="5dp"/>  
        </LinearLayout>  
 <View
  android:layout_width="match_parent"
  android:layout_margin="5dp"
  android:layout_height="1dp"
  android:background="@color/white"/> 
<ListView 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/itemList"
    android:background="#088A08"
    android:divider="@color/white"
    android:dividerHeight="1dp"/>
</LinearLayout>

</LinearLayout>
</LinearLayout>

Upvotes: 1

Views: 176

Answers (3)

user3740085
user3740085

Reputation: 244

I did it this way:

            convertView.setOnClickListener(new View.OnClickListener() {                 
                @Override
                public void onClick(View v) {
                                     your code
                }});

Just add this much code to my customview

Upvotes: 1

Pankaj Arora
Pankaj Arora

Reputation: 10274

in the widgets(Textview or button whatever it is) of your inflator layout just add:

android:focusable="false"
android:focusableInTouchMode="false"

and in parent layout of your inflator add:

android:descendantFocusability="blocksDescendants" 

Upvotes: 0

cYrixmorten
cYrixmorten

Reputation: 7108

Recently I had the same problem after adding a ToggleButton to my list items. The solution for me was to add android:descendantFocusability="blocksDescendants" to the layout of the item.

Here is the whole XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="5dp"
    android:padding="5dp"
    android:paddingLeft="15dp"
    android:descendantFocusability="blocksDescendants" >

    <TextView
        android:id="@+id/watch_roadName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:text="Addresse"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textStyle="bold" />

    <ToggleButton
        android:id="@+id/watch_button_arrived"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/watch_roadName"
        android:layout_alignParentRight="true"
        android:textOn="@string/arrived"
        android:textOff="@string/arrived"
        android:text="@string/arrived" />

</RelativeLayout>

Similar answers to the same issue can be found here:

How to fire onListItemClick in Listactivity with buttons in list?

and here

Android custom ListView with ImageButton is not getting focus

Upvotes: 0

Related Questions