1

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

            }});
user3553551
  • 75
  • 1
  • 7

1 Answers1

3

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

        }
    });
kalyan pvs
  • 14,486
  • 4
  • 41
  • 59