我有一个listView插入到一个对话框中,当我点击列表中的项目时它没有响应动作,我已经设置了听众,但我不明白为什么{{1}没有被调用。
onItemClickListener
list_item_to_meet.xml
public void init() {
toMeetDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
toMeetDialog.setContentView(R.layout.person_to_meet);
listOfPersonToFollow = (ListView) toMeetDialog.findViewById(R.id.list_view_to_meet);
confirmButton = (Button) toMeetDialog.findViewById(R.id.button_to_meet);
confirmButton.setOnClickListener(this);
listOfPersonToFollow.setOnItemClickListener(this);
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(mapsActivity, R.layout.list_item_to_meet, mapsActivity.getPersonToFollow());
listOfPersonToFollow.setAdapter(arrayAdapter);
toMeetDialog.show();
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(mapsActivity, "hello", Toast.LENGTH_SHORT);
}
person_to_meet.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="26dp" />
这段代码有什么问题? 提前谢谢。
答案 0 :(得分:0)
我遇到过在列表行中设置按钮的OnClickListener
使得'blockDescendants'徒劳无功的情况。设置OnClickListener
后,使该按钮无法通过setFocusable(false)
和setFocusableInTouchMode(false)
关注。
试试这个:
public void init() {
toMeetDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
toMeetDialog.setContentView(R.layout.person_to_meet);
listOfPersonToFollow = (ListView) toMeetDialog.findViewById(R.id.list_view_to_meet);
confirmButton = (Button) toMeetDialog.findViewById(R.id.button_to_meet);
confirmButton.setOnClickListener(this);
confirmButton.setFocusable(false);
confirmButton.setFocusableInTouchMode(false);
listOfPersonToFollow.setOnItemClickListener(this);
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(mapsActivity, R.layout.list_item_to_meet, mapsActivity.getPersonToFollow());
listOfPersonToFollow.setAdapter(arrayAdapter);
toMeetDialog.show();
}