【问题标题】:Open Popup Dialog from expandableListviewGroup holding从 expandableListviewGroup 控股打开弹出对话框
【发布时间】:2019-09-26 20:03:17
【问题描述】:

我遇到了问题,在使用 Google 时找不到任何帮助。单击它时,我有一个包含一些信息的可扩展列表视图。现在我想添加一些东西,比如在持有 groupitem 时显示的弹出对话框。

有人知道怎么做吗?

这是我现在拥有的代码:

    setContentView(R.layout.activity_main);
    cocktailView=(ExpandableListView)findViewById(R.id.simple_cocktail_list);
    cocktailHash = new HashMap<>();

    final RequestQueue requestQueue = Volley.newRequestQueue(this);

    final StringRequest objectRequest = new StringRequest(
            Request.Method.GET,
            "http://datservice/all/cocktails",
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    JsonElement element = new JsonParser().parse(response);
                    cocktailList = new Gson().fromJson(element.getAsJsonArray(), new TypeToken<List<Cocktail>>() {}.getType());
                    onSuccess(cocktailList);
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    String test = error.toString();
                    //Log.e("Rest Response", error.toString());
                }
            }
    );

【问题讨论】:

    标签: android expandablelistview smartphone


    【解决方案1】:

    This answer 展示了如何在 子项 上捕获 long click。根据这个答案,您也可以在 group item 上捕获long click。这是一个例子,

    cocktailView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
                if (ExpandableListView.getPackedPositionType(id) == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
                    // Show your pop up dialog
                    new AlertDialog.Builder(view.getContext())
                            .setMessage("Your Message")
                            .show();
                    return true;
                }
                return false;
            }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-18
      • 1970-01-01
      • 2011-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多