【问题标题】:ListView onItemSelected Listener not workingListView onItemSelected 侦听器不起作用
【发布时间】:2014-12-27 05:50:43
【问题描述】:

尝试在弹出窗口内设置列表视图的项目选定侦听器时遇到一些问题。这是我的代码:

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);
        }
    });
}

When the item from listview inside a popup window is selected, I wanted to open a dialer page.但是,当我通过放置一条日志消息对此进行测试时,当我从列表视图中选择项目时,它不会执行在项目上选择的侦听器。

有什么想法吗?提前致谢。

【问题讨论】:

  • 你的适配器有数据吗?您将数据放入适配器的什么位置??
  • @Rohit5k2 让我更新一下我的问题

标签: java android listview layout-inflater


【解决方案1】:

您必须使用另一个带有布尔参数的构造函数,该参数允许对 PopupWindow 项目进行聚焦:

public PopupWindow (View contentView, int width, int height, boolean focusable)

final PopupWindow popupWindow = new PopupWindow(popupView,LayoutParams.WRAP_CONTENT,450,true);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-20
    • 1970-01-01
    • 2017-09-27
    • 1970-01-01
    • 1970-01-01
    • 2013-04-30
    • 1970-01-01
    相关资源
    最近更新 更多