user3553551
user3553551

Reputation: 75

Listview not firing when item is pressed

all my views and non focusable and non clickable except the switch which is clickable but making it non clickable still doesn't make the list view fire

 <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/timed_events_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:clickable="false"
        android:descendantFocusability="blocksDescendants"
        android:focusable="false"
        android:focusableInTouchMode="false"
         >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
             >

            <TextView
            android:id="@+id/event_name"
            android:layout_width="wrap_content"
            android:layout_height="25dp"
            android:textSize="20sp"
            android:textStyle="bold"
            android:singleLine="true"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:clickable="false"
            />
            <TextView
            android:id="@+id/event_time"
            android:layout_width="wrap_content"
            android:layout_height="26dp"
            android:singleLine="true"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:clickable="false"
            />
        </LinearLayout>

        <Switch
            android:id="@+id/state"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:onClick="isActivated"
            android:focusable="false"
            android:focusableInTouchMode="false"  
            />

    </RelativeLayout>

below is the OnItemSelectedListener which is in the onCreate method

listView.setOnItemSelectedListener( new OnItemSelectedListener(){
            @Override
            public void onItemSelected(AdapterView<?> parent, View view,
                    int position, long id) {
                Toast.makeText(ActivityContext, "its working", Toast.LENGTH_LONG).show();
                Intent intent ;
                if(listAdapter.getItemViewType(position) == 1){
                    intent = new Intent(ActivityContext,Volume.class);
                    Volume.currentPref((SoundDetails) timers.get(position),position);
                } else{
                    intent = new Intent(ActivityContext,Message.class);
                    Message.currentMessage((MessageListDetails) timers.get(position),position);
                }
                startActivity(intent); 
            }
            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
                // TODO Auto-generated method stub

            }});

Upvotes: 1

Views: 92

Answers (1)

kalyan pvs
kalyan pvs

Reputation: 14590

For ListView you need to set onItemClickListener instead of onItemSelectedListener chanage like this..

listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            // perform your operation

        }
    });

Upvotes: 3

Related Questions