我的所有观看次数都不可聚焦且不可点击,但可点击但无法点击的开关仍然不会使列表视图触发
<?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方法
中的OnItemSelectedListenerlistView.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
}});
答案 0 :(得分:3)
对于ListView
,您需要设置onItemClickListener
而不是onItemSelectedListener
像这样的通道..
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// perform your operation
}
});