按下项目时Listview不会触发

时间:2014-07-23 13:04:24

标签: java android

我的所有观看次数都不可聚焦且不可点击,但可点击但无法点击的开关仍然不会使列表视图触发

 <?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>
下面的

是OnCreate方法

中的OnItemSelectedListener
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

            }});

1 个答案:

答案 0 :(得分:3)

对于ListView,您需要设置onItemClickListener而不是onItemSelectedListener 像这样的通道..

listView.setOnItemClickListener(new OnItemClickListener() {

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

        }
    });