SoFunction
Updated on 2025-04-05

Detailed explanation of the simple application of Android pop-up window ListPopupWindow

Overview

Common pop-up windows have menus or Dialogs, but more user-friendly and customizable is PopupWindow
If you just display the list data or pop-up list selection, just use ListPopupWindow directly, and you don’t have to set the layout separately.
If you want to be more diverse, then customize a layout and use PopupWindow, it is not complicated.

usage

Custom ListPopupWindow class

public class ChargeItemSumPop extends ListPopupWindow {

 public ChargeItemSumPop(Context context) {
  super(context);
 }
}

Properties settings

Because there is already a list control inside, there is no need to bind the layout

setHeight(.WRAP_CONTENT);
setWidth(600);
setModal(true);
setBackgroundDrawable(new ColorDrawable(0xCC000000));

Bind Adapter

//Add the data you want to displayCalendar calendar = ();
int year = ();
List<Integer> lstYear = new ArrayList<>();
for(int i = 2015; i <= year; i++){
    (i);
}
ArrayAdapter<Integer> adapter = new ArrayAdapter<>(context, .simple_spinner_dropdown_item, lstYear);
setAdapter(adapter);

Activity monitoring

ChargeDateYearPop pop = new ChargeDateYearPop(this);
((adapterView, view, i, l) -> {
    ((().getItem(i)));
    ();
});
();
();

Complete pop-up category

The difference between it and ordinary pop-up windows is that it is a list, so it is necessary to bind Adapter for display.

public class ChargeDateYearPop extends ListPopupWindow {

    public ChargeDateYearPop(Context context) {
        super(context);
        setHeight(800);
        setWidth(200);
        setModal(true);
        setBackgroundDrawable(new ColorDrawable(0xCC000000));
        initView(context);
    }

    private void initView(Context context) {
        Calendar calendar = ();
        int year = ();
        List<Integer> lstYear = new ArrayList<>();
        for(int i = 2015; i <= year; i++){
            (i);
        }
        (lstYear);
        (lstYear);
        ArrayAdapter<Integer> adapter = new ArrayAdapter<>(context, .simple_spinner_dropdown_item, lstYear);
        setAdapter(adapter);
    }
}

Activity

private void showChargeDateYear(){
    ChargeDateYearPop pop = new ChargeDateYearPop(this);
    ((adapterView, view, i, l) -&gt; {
        ((().getItem(i)));
        ();
        //Operations of overloading data, etc.        //(getChargeDate());
    });
    ();
    ();
}

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.