尝试在弹出窗口中设置列表视图的项目选定侦听器时遇到了一些问题。这是我的代码:
private void openPopUp() {
LayoutInflater layoutInflater = (LayoutInflater) getActivity()
.getBaseContext().getSystemService(
context.LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.event_attendee_pop,
null);
llAttendeeList = (LinearLayout) popupView
.findViewById(R.id.llAttendeeList);
attendeeListView = (ListView) popupView.findViewById(R.id.attendeelistview);
final PopupWindow popupWindow = new PopupWindow(popupView,
LayoutParams.WRAP_CONTENT, 450);
popupWindow.showAtLocation(popupView, Gravity.BOTTOM, 0, 70);
mAdapter = new ListAdapter(getActivity());
attendeeListView.setAdapter(mAdapter);
attendeeListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View item,
int position, long id) {
Log.i("HIIII","HIII");
String telNo = attendeeList.get(position)
.getTelNo();
Intent intentDialer = new Intent(Intent.ACTION_DIAL,Uri.parse("tel:1234-5678"));
startActivity(intentDialer);
}
});
}
当选择弹出窗口中列表视图中的项目时,我想打开一个拨号页面。但是,当我通过放置一条Log消息测试它时,当我从listview中选择项目时,它没有执行on item item selected listener。
有什么想法吗?提前谢谢。
答案 0 :(得分:1)
你必须使用另一个带布尔参数的构造函数,该构造函数允许对PopupWindow项进行聚焦:
public PopupWindow (View contentView, int width, int height, boolean focusable)
final PopupWindow popupWindow = new PopupWindow(popupView,LayoutParams.WRAP_CONTENT,450,true);