Home>

I want to use ListView in PopupWindow.

Error message

ListView is displayed, but no text is displayed
What's wrong?
Addendum
2019/12/05 13:23
Text was displayed when tapping the line.
I want to display PopupWindow without tapping when it is displayed.
Thank you in advance.

Applicable source code

PopupWindow layout

<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
    android: layout_width = "match_parent"
    android: layout_height = "match_parent"
    android: orientation = "vertical"
    android: padding = "8dp">
    <!-Header display area->
    <LinearLayout
        android: id = "@ + id/linearLayout1"
        android: layout_width = "fill_parent"
        android: layout_height = "40dp"
        android: layout_gravity = "top"
        android: background = "@ color/yellow">
        <TextView
            android: id = "@ + id/text"
            android: layout_width = "wrap_content"
            android: layout_height = "wrap_content"
            android: layout_gravity = "center"
            android: layout_weight = "1"
            android: gravity = "top | center"
            android: text = "<Destination/Grouping No.>"
            android: textColor = "# 000000"
            android: textSize = "32sp"
            android: textStyle = "bold" />
    </LinearLayout>
    <LinearLayout
        android: layout_width = "fill_parent"
        android: layout_height = "40dp"
        android: layout_gravity = "top"
        android: background = "@ color/yellow">
    </LinearLayout>
    <!-Main display (title)->
    <LinearLayout
        android: layout_width = "match_parent"
        android: layout_height = "wrap_content"
        android: orientation = "horizontal">
        <TextView
            android: id = "@ + id/title1"
            android: layout_width = "match_parent"
            android: layout_height = "wrap_content"
            android: layout_marginRight = "@ dimen/dp_s"
            android: layout_marginBottom = "@ dimen/dp_s"
            android: layout_weight = "1"
            android: layout_gravity = "center"
            android: background = "@ color/title"
            android: gravity = "center"
            android: padding = "@ dimen/dp_m"
            android: text = "\ nTitle 1 \ n"android: textColor = "# 000000"
            android: textSize = "@ dimen/sp_s" />
        <TextView
            android: id = "@ + id/title2"
            android: layout_width = "match_parent"
            android: layout_height = "wrap_content"
            android: layout_marginRight = "@ dimen/dp_s"
            android: layout_marginBottom = "@ dimen/dp_s"
            android: layout_weight = "1"
            android: layout_gravity = "center"
            android: background = "@ color/title"
            android: gravity = "center"
            android: padding = "@ dimen/dp_m"
            android: text = "\ nTitle 2. \ n"
            android: textColor = "# 000000"
            android: textSize = "@ dimen/sp_s" />
        <TextView
            android: id = "@ + id/title3"
            android: layout_width = "match_parent"
            android: layout_height = "wrap_content"
            android: layout_marginRight = "@ dimen/dp_s"
            android: layout_marginBottom = "@ dimen/dp_s"
            android: layout_weight = "1"
            android: layout_gravity = "center"
            android: background = "@ color/title"
            android: gravity = "center"
            android: padding = "@ dimen/dp_m"
            android: text = "\ ntitle3 \ n"
            android: textColor = "# 000000"
            android: textSize = "@ dimen/sp_s" />
    </LinearLayout>
    <!-Main display (details)->
    <ListView
        android: id = "@ + id/listView"
        android: layout_width = "match_parent"
        android: layout_height = "0dp"
        android: layout_margin = "5dp"
        android: background = "@ color/white"
        android: layout_weight = "1" />
    <!-Button display area->
    <LinearLayout
        android: layout_width = "match_parent"
        android: layout_height = "wrap_content"
        android: gravity = "top | center"
        android: visibility = "visible"
        android: background = "@ color/yellow">
        <Button
            android: id = "@ + id/close_button"
            android: layout_width = "200dp"
            android: layout_height = "wrap_content"
            android: layout_gravity = "center"
            android: gravity = "top | center"
            android: textSize = "28sp"
            android: text = "close" />
    </LinearLayout>
</LinearLayout>


Java source code

public void makeDeliveredtoData (int detailNo, List<Data>dataList, View v, Resources res) {int gdetailNo = detailNo;
        ArrayList<DeliveredtoData>deloveredtoList = new ArrayList<DeliveredtoData>();
        DeliveredtoData data;
        Data work;
        Data target;
        for (int i = 0;i<= dataList.size ()-1;i ++) {
            target = new Data ();
            target = dataList.get (i);
            if (detailNo == target.getShuyakuFlg ()) {
                data = new DeliveredtoData ();
                work = dataList.get (i);
                data.setSeihin (work.getSeihin ());
                data.setDetailNo (work.getDetailNo ());
                data.setGroupNo (work.getGroupNo ());
                data.setDestinationName (work.getDestinationName ());
                data.setLoke (work.getLoke ());
                deloveredtoList.add (data);
            }
        }
        final ArrayList rows = new ArrayList ();
        for (int i = 0;i<= deloveredtoList.size ()-1;i ++) {
            DeliveredtoData deloveredtoData = new DeliveredtoData ();
            deloveredtoData = deloveredtoList.get (i);
            rows.add ("Oh");
        }
        mPopupWindow = new PopupWindow (con);
        // 1 General method
        LayoutInflater inflater = LayoutInflater.from (con);
        // Layout settings
        View popupView = inflater.inflate (R.layout.popup_layout, null);
        popupView.findViewById (R.id.close_button) .setOnClickListener (new View.OnClickListener () {
            @Override
            public void onClick (View v) {
                if (mPopupWindow.isShowing ()) {
                    mPopupWindow.dismiss ();
                }
            }
        });
        ListView listView = new ListView (con);
        listView = (ListView) popupView.findViewById (R.id.listView);
        mPopupWindow.setContentView (popupView);
        // Background settings
        mPopupWindow.setBackgroundDrawable (res.getDrawable (R.drawable.popup_background));
        // Setting for not being caught by other views when tapping
        mPopupWindow.setOutsideTouchable (true);
        mPopupWindow.setFocusable (true);
        // Display size setting This time width 800dp
        float width = TypedValue.applyDimension (TypedValue.COMPLEX_UNIT_DIP, 800, res.getDisplayMetrics ());
        mPopupWindow.setWindowLayoutMode ((int) width, WindowManager.LayoutParams.WRAP_CONTENT);
        mPopupWindow.setWidth ((int) width);
        mPopupWindow.setHeight (WindowManager.LayoutParams.WRAP_CONTENT);
        // ArrayAdapter<String>adapter = new ArrayAdapter<String>(con, android.R.layout.simple_list_item_1);
        ArrayAdapter adapter = new ArrayAdapter (con, android.R.layout.simple_expandable_list_item_1, rows);
        // Adapter specification
        listView.setAdapter (adapter);
        // display in the center of the screen
        mPopupWindow.showAtLocation (v, Gravity.CENTER, 0, 0);
    }
  • Answer # 1

    I'm happy to inform you that this has been resolved.
    The text color of ListView was Kimo.
    It is different if you customize it, but despite the text color being white
    White was specified as the background color. .
    This is an elementary mistake.
    I'm very sorry for the noise.