更新Dialog中的所有内容。

时间:2017-05-24 11:34:56

标签: android gridview dialog updates android-gridview

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

我的一个Dialogs代码:

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();
    }

1 个答案:

答案 0 :(得分:0)

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