开发者

Problem with my custom dialog which is having dynamic data

开发者 https://www.devze.com 2023-03-12 11:14 出处:网络
I have a usecase like repeatedly calling the sam开发者_运维知识库e dialog box with different values. I am using the same dialog creating code for that. First time the sent data is populated to dialog

I have a usecase like repeatedly calling the sam开发者_运维知识库e dialog box with different values. I am using the same dialog creating code for that. First time the sent data is populated to dialog box. but next time the dialog box not getting rebuilt with different values when i call the same for next time.

Code is here

            dialog.setContentView(R.layout.orderdialog);
            dialog.setTitle("Selected Item");
            dialog.setCanceledOnTouchOutside(true);

            System.out.println(selected);  // here i am sending different values eachtime. But not updating in dialog.

            TextView selectedItem = (TextView)dialog.findViewById(R.id.itemName);
            selectedItem.setText(selected);


You can use the android alert builder to show dynamic data:

new AlertDialog.Builder(this)
    .setTitle("your title name")
    .setMessage("here you can write your dynamic data as string or integer")
    .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        public void onClick(/* don't remember the signature by heart... */) { 
            // continue with delete
        }
     })
    .setNegativeButton("No", new DialogInterface.OnClickListener() {
        public void onClick(/* don't remember the signature by heart... */) { 
            // do nothing
        }
     })
     .show();


Instead of calling showDialog(id); and creating dialog in oncreatDialog function

create the dialog and show it in you on click function itself:

like this:

            public void onClick(View v) {
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setTitle("State");
                builder.setItems(m_arrStateNames, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        m_nSelStateIdx = which;
                        showState();

                        dialog.dismiss();
                   }
                });
                builder.show();
            }
        });
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号