【问题标题】:PopWindow always show at last in ListView...!PopWindow 总是最终显示在 ListView 中......!
【发布时间】:2015-05-11 11:40:07
【问题描述】:


我在 android PopupWindow 上工作。在这个应用程序中,我创建了 1 个自定义 ListView。现在我想在用户点击自定义ListViewTextView 时显示PopupWindow
我的问题是:
PopupWindow 总是最后显示TextView,即使我先点击或点击其他TextView
我该如何解决这个问题。??

ListView的TextView。

holder.end.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                int[] location = new int[2];
                holder.end.getLocationOnScreen(location);
                p = new Point();
                p.x = location[0];
                p.y = location[1];
                if (p != null){
                    showPopup(context,p);
                    holder.popupText.setText(holder.end.getText().toString());
                }
            }
        });

我的 popupWindow 函数。

private void showPopup(final Activity context, Point p) {

        // Inflate the popup_layout.xml
        LinearLayout viewGroup = (LinearLayout)context.findViewById(R.id.layoutPopup);
        LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View layout = layoutInflater.inflate(R.layout.popup_layout, viewGroup);

        holder.popupText = (TextView) layout.findViewById(R.id.showPopUp);
        // Creating the PopupWindow
        final PopupWindow popup = new PopupWindow(context);
        popup.setContentView(layout);
        popup.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT);
        popup.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
        popup.setFocusable(true);

        int OFFSET_X = 30;
        int OFFSET_Y = 30;

        popup.setBackgroundDrawable(new BitmapDrawable());
        popup.showAtLocation(layout.findViewById(R.id.showPopUp), Gravity.NO_GRAVITY, p.x + OFFSET_X, p.y + OFFSET_Y);

    }

【问题讨论】:

    标签: android listview android-popupwindow


    【解决方案1】:

    使用此代码更改您的点击侦听器。它应该可以工作。

    holder.end.setOnClickListener(new View.OnClickListener() {
    
            @Override
            public void onClick(View v) {
                int[] location = new int[2];
                v.getLocationOnScreen(location);
                p = new Point();
                p.x = location[0];
                p.y = location[1];
                if (p != null){
                    showPopup(context,p);
                    holder.popupText.setText(holder.end.getText().toString());
                }
            }
        });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-10
      • 1970-01-01
      • 2021-12-19
      相关资源
      最近更新 更多