在 Intent(Android) 中传递 AlertDialog 元素

Pass the AlertDialog Element in Intent(Android)

到处谷歌搜索后我遇到了问题找不到如何将警报对话框元素或弹出元素存储在变量中。

例如, 在我的 Popup Window 中,我有从 json 到 php 的 Principal、Incharge 和 Teacher 等值。

我不想像在 Intent 中传递 (Principal) 那样移动 Intent 中的选定项。

我正在为此努力。请帮忙!

AlertDialog.Builder builderSingle = new AlertDialog.Builder(context);
        builderSingle.setIcon(R.drawable.logo);
        builderSingle.setTitle("Select One Recipent:-");

        final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(context,
                android.R.layout.select_dialog_singlechoice);
        for (i = 0; i < myData.length; i++) {
            arrayAdapter.add(myData[i]);
            selecteditem = myData[i]; /// Should be the selected item but its not i know
        }

        builderSingle.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });

        builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                String strName = arrayAdapter.getItem(which);
                AlertDialog.Builder builderInner = new AlertDialog.Builder(context);
                builderInner.setMessage(strName);
                 Intent intent = new Intent(context,send_communication_to.class);
                 intent.putExtra("Authoritytype", selecteditem);
                 context.startActivity(intent);

而不是intent.putExtra("Authoritytype", selecteditem); 使用 intent.putExtra("Authoritytype", strName );

存储在 selecteditem 中的值始终是 myData 中的最后一项,因为 selecteditem 值是在 for 循环中设置的

for (i = 0; i < myData.length; i++) {
            arrayAdapter.add(myData[i]);
            selecteditem = myData[i]; /// Should be the selected item but its not i know
        }

替换 String strName = arrayAdapter.getItem(which);

selecteditem = arrayAdapter.getItem(which);