gpt4 book ai didi

java - 按下项目时 ListView 不触发

转载 作者:行者123 更新时间:2023-11-29 05:20:39 25 4
gpt4 key购买 nike

我所有的 View 和不可聚焦和不可点击的除了可点击但使其不可点击的开关仍然不会使 ListView 触发

 <?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

}});

最佳答案

对于 ListView,您需要设置 onItemClickListener 而不是 onItemSelectedListener像这样改变..

listView.setOnItemClickListener(new OnItemClickListener() {

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

}
});

关于java - 按下项目时 ListView 不触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24911267/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com