【问题标题】:Update all content inside Dialog.更新 Dialog 中的所有内容。
【发布时间】:2017-05-24 11:34:55
【问题描述】:

我在 Dialog 中创建了 GridView Gallery。这个画廊有一些页面,但现在我为每个页面创建了单独的对话框。所有这些对话框(图库页面)因当前进度(例如我在 4/12 页)标题和照片(对于每个页面我加载不同的图像)而彼此不同。我认为为每个页面创建新对话框并不是很好的做法,但是我应该如何在一个对话框中做呢?

我的一个对话框代码:

public void threeChoice()
    {
        Collections.sort(photoList = imageReader(photoDir,"1008"));
        inflater = this.getLayoutInflater();

        // Dialog layout
        v = inflater.inflate(R.layout.dialog_choice, null);

        progressDialog = (ProgressBar)v.findViewById(R.id.progressBar);
        //progressDialog = new ProgressBar(mContext);
        progressDialog.setMax(7);
        progressDialog.setProgress(3);


        gV = (GridView) v.findViewById(R.id.gridView);

        // GridAdapter (Pass context and files list)
        GridAdapter adapter = new GridAdapter(this, photoList);

        // Set adapter
        gV.setAdapter(adapter);



        final AlertDialog.Builder builder2 = new AlertDialog.Builder(this);
        builder2.setTitle("Album Page: 1008"); 

        builder2.setView(v);
        builder2.setPositiveButton("NEXT", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which)
            {
                NextPage(); //<-- go to next page
            }
        }).setNegativeButton("BACK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which)
            {
                PreviousPage(); //<-- Back to previous page
            }
        });

        gV.setOnItemClickListener(new AdapterView.OnItemClickListener()
        {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id)
            {
                Intent intent = new Intent(getApplicationContext(), PhotoDetails.class);
                intent.putExtra("image", photoList.get(position));
                startActivity(intent);
            }
        });

        builder2.setCancelable(false);
        final AlertDialog dialog = builder2.create();
        dialog.show();
    }

【问题讨论】:

    标签: android gridview dialog updates android-gridview


    【解决方案1】:

    您应该将NextPage();PreviousPage(); 的签名更改为NextPage(View v);PreviousPage(View v);。然后,您将能够使用您的 Dialog 布局 v 调用它们,并直接从您的函数中更新此布局。

    【讨论】:

    • 但是我只有 2 个布局,其中一个只有 gridView,第二个是项目(ImageView),所以如果我需要调用 imageReader 函数并执行更新适配器等其他操作,它会如何(查看 v)
    • v 不包含对话框中显示的所有视图?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-26
    相关资源
    最近更新 更多