【问题标题】:Why --> "ListPopupWindow: Could not call getMaxAvailableHeightMethod.... Using the public version"?为什么 --> “ListPopupWindow: 无法调用 getMaxAvailableHeightMethod.... 使用公共版本”?
【发布时间】:2017-08-26 07:10:18
【问题描述】:

我尝试在片段的 alertdialog 中创建一个 list popup(名为 drop list)窗口。

但在设置锚点和适配器后,我收到错误提示:

“I/ListPopupWindow:无法在 PopupWindow 上调用 getMaxAvailableHeightMethod(View, int, boolean)。使用公共版本。”

如何解决这个问题?请帮忙。

下面是我的代码:

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.dblistview, container, false);

    final MyDBHandler dbHandler = new MyDBHandler(getActivity(), null,null,1);
    DBReader dbReader = new DBReader(getActivity());
    ListView dbListView  = (ListView) v.findViewById(R.id.dbListing);

    if (dbHandler.dbSelectQuery("*",null) != null){
        dbCustomAdapter dbListViewAdapter = new dbCustomAdapter(getActivity(),
                R.layout.dbadapterview, dbHandler.dbSelectQuery("*",null));
        dbListView.setAdapter(dbListViewAdapter);
        dbListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View v, int i, long l) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getContext());

                TextView goodTV= (TextView) v.findViewById(R.id.goodTV);
                final ListPopupWindow droplist = new ListPopupWindow(getContext());
                droplist.setAnchorView(goodTV);

                ArrayList<String> disntictList = dbHandler.selectDisntictQuery(MyDBHandler.COLUMN_party);
                ArrayAdapter<String> adapter = new ArrayAdapter<>(getContext(),android.R.layout.simple_list_item_1,disntictList);
                droplist.setAdapter(adapter);

                for (String item : disntictList){
                    Log.i("Item name", item);
                }

                View mView = getActivity().getLayoutInflater().inflate(R.layout.listview_filterbox,null);
                mView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        try {
                            droplist.show();
                        } catch (Exception e) {
                            Toast.makeText(getContext(), "Height null?",Toast.LENGTH_LONG).show();
                        }
                    }
                });


                builder.setCancelable(true);
                builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Toast.makeText(getContext(), "Ok clicked",Toast.LENGTH_LONG).show();
                    }
                });

                builder.setView(mView);


                AlertDialog dialog = builder.create();
                dialog.show();

            }
        });

    } else {
        Toast.makeText(getActivity(), "Database currently empty...",Toast.LENGTH_LONG).show();
    }

    return v;
}

【问题讨论】:

    标签: android dialog fragment


    【解决方案1】:

    哦,我终于明白了。 我犯了两个错误:

    1. 对于OnClickListener对于TextView,应该是

      goodTV.setOnClickListener(new View.OnClickListener()....

      而不是

      mView.setOnClickListener(new View.OnClickListener()....

    2. dblistView.setOnItemClickListener 中定义我的TextView。因为我在 dblistView.setOnItemClickListener 中附加了我自己的名为 mView 的 XML 布局,所以对于

      TextView goodTV= (TextView) mView.findViewById(R.id.goodTV);

      代替:

      TextView goodTV= (TextView) v.findViewById(R.id.goodTV);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-09
      • 2022-01-06
      • 1970-01-01
      • 2022-01-24
      • 2015-02-01
      • 2012-03-07
      • 1970-01-01
      相关资源
      最近更新 更多