PopupWindow上的ListView侦听器不工作(Android)
我想显示一个具有Listview的弹出窗口,当我在Listview项目上单击时,执行一些操作。为了简化我的问题,我制作了下一个示例,其中显示了问题:即时单击listview不起作用 我的popupwindow自定义布局:PopupWindow上的ListView侦听器不工作(Android),android,google-maps,android-listview,Android,Google Maps,Android Listview,我想显示一个具有Listview的弹出窗口,当我在Listview项目上单击时,执行一些操作。为了简化我的问题,我制作了下一个示例,其中显示了问题:即时单击listview不起作用 我的popupwindow自定义布局: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_heig
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/tvName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15dp"
android:textStyle="bold"
android:gravity="center"/>
<ListView
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="5dp"
android:layout_width="wrap_content"
android:layout_height="110dp"
android:id="@+id/lvData"
android:headerDividersEnabled="false" />
<ImageButton
android:layout_width="40dp"
android:layout_height="40dp"
android:id="@+id/ibInfo"
android:layout_gravity="center"
android:src="@android:drawable/ic_menu_info_details"/>
我显示弹出窗口的地图活动:
public void onButtonClick(View view){
mPopupView = getLayoutInflater().inflate(R.layout.popupwindow_custom_layout, null);
TextView tvName = (TextView) mPopupView.findViewById(R.id.tvName);
ListView lvData = (ListView) mPopupView.findViewById(R.id.lvData);
ImageButton ibInfo = (ImageButton) mPopupView.findViewById(R.id.ibInfo);
TextView txtListTitle = new TextView(this);
ibInformacion.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("click on button");
}
});
txtListTitle.setText("List Title");
listaLineas.addHeaderView(txtListTitle);
ArrayList<String> list = new ArrayList<>();
tvNombre.setText("Main Title");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_spinner_item, list);
adapter.add("Test 1");
adapter.add("Test 2");
adapter.add("Test 3");
adapter.add("Test 4");
adapter.add("Test 5");
adapter.add("Test 6");
lvData.setAdapter(adapter);
lvData.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
System.out.println("Click on list item");
}
});
PopupWindow popupWindow = new PopupWindow(mPopupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
mPopupWindow.showAtLocation(this, Gravity.CENTER, 0, 0);
}
public void on按钮单击(查看){
mPopupView=GetLayoutFlater()。充气(R.layout.popupwindow\u custom\u布局,null);
TextView tvName=(TextView)mPopupView.findViewById(R.id.tvName);
ListView lvData=(ListView)mPopupView.findViewById(R.id.lvData);
ImageButton ibInfo=(ImageButton)mPopupView.findViewById(R.id.ibInfo);
TextView txtListTitle=新的TextView(此);
ibinfo.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
System.out.println(“单击按钮”);
}
});
setText(“列表标题”);
listaLineas.addHeaderView(txtListTitle);
ArrayList=新建ArrayList();
tvNombre.setText(“主标题”);
ArrayAdapter=新的ArrayAdapter(getApplicationContext(),android.R.layout.simple\u微调器\u项,列表);
适配器。添加(“测试1”);
适配器。添加(“测试2”);
适配器。添加(“测试3”);
适配器。添加(“测试4”);
添加适配器(“测试5”);
适配器。添加(“测试6”);
lvData.setAdapter(适配器);
lvData.setOnItemClickListener(新的AdapterView.OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父对象、视图、整型位置、长id){
System.out.println(“单击列表项”);
}
});
POPUPPINDOW POPUPPINDOW=新的POPUPPINDOW(mPopupView,ViewGroup.LayoutParams.WRAP_内容,ViewGroup.LayoutParams.WRAP_内容);
mPopupWindow.showAtLocation(this,Gravity.CENTER,0,0);
}
为什么ibInfo的setOnClickListener
工作正常,而lvData的setoninemclicklistener
(norsetOnClickListener
)却什么都不做?我错过了什么?(列表的卷轴工作正常)
注意:我无法设置
mPopupWindow.setFocusable(true)
,因为我将丢失对地图的单击(onmaplick
,onCameraChange
,等等)。尝试将其添加到列表视图中
android:descendantFocusability="blocksDescendants"
希望这能解决它 尝试将其添加到listView
android:descendantFocusability="blocksDescendants"
希望这能解决它