将数据从对话框传递到新活动

将数据从对话框传递到新活动

本文介绍了将数据从对话框传递到新活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将数据从对话框传递到新的活动。因此,基本上,我想在对话框中执行的操作例如具有名称:John ,当我单击确定按钮时,它将打开一个新活动,但我希望该 John 设置在我的新活动的编辑框中

I am trying pass data from my dialog box to a new Activity. So basically what i want to do for example in my Dialog box i have Name: John, when i click on my okay button it opens a new activity but i want that John to be set in my edit box on my new activity:

这是我的活动,其中我的对话框代码是:

Here is my Activity where my Dialog box code is:

 list.setOnItemClickListener(new AdapterView.OnItemClickListener() {



        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            /** To change selected state view */
            view.setSelected(true);
            HashMap<String, Object> obj = (HashMap<String, Object>) ADAhere.getItem(position);
            String SlectedName = (String) obj.get("NAME");
            String SlectedPrice = (String) obj.get("PRICE");
            String SlectedSize = (String) obj.get("SIZE");
            String SlectedRange = (String) obj.get("RANGE");
            String SlectedSupp = (String) obj.get("SUPPLIER");
           // Toast.makeText(getActivity().getApplicationContext(), SlectedName, Toast.LENGTH_SHORT).show();

            final Dialog dialog = new Dialog(getActivity());
            dialog.getWindow();
            //dialog.setTitle("Confirm your Vote");
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setContentView(R.layout.diaglog);

            final TextView VName = (TextView) dialog.findViewById(R.id.Name);
            final TextView VRange = (TextView) dialog.findViewById(R.id.Range);
            final TextView VSUPPLIER = (TextView) dialog.findViewById(R.id.Supplier);
            final TextView VSIZE = (TextView) dialog.findViewById(R.id.Size);
            final TextView VPrice = (TextView) dialog.findViewById(R.id.Price);


            VName.setText(SlectedName);
            VRange.setText(SlectedRange);
            VSUPPLIER.setText(SlectedSupp);
            VSIZE.setText(SlectedSize);
            VPrice.setText(SlectedPrice);
            dialog.show();
            Button cancelBtn = (Button) dialog.findViewById(R.id.cancel_btn);
            cancelBtn.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    dialog.dismiss();
                }
            });
            Button UpdateBtn = (Button) dialog.findViewById(R.id.btn_update);
            UpdateBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent i = new Intent(getActivity().getApplicationContext(),Upvalence.class);
                    startActivity(i);
                }
            });
            Button deleteBtn = (Button) dialog.findViewById(R.id.btn_delete);
            deleteBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent i = new Intent(getActivity().getApplicationContext(),Upvalence.class);
                    startActivity(i);
                }
            });


            dialog.show();

        }
    });

所以我想通过 VName.setText(SlectedName); 转到新活动:

so i want to pass VName.setText(SlectedName); to a new activity:

 name1.setText(dialogactivityname);


推荐答案

额外传入:

而不是:

Intent i = new Intent(getActivity().getApplicationContext(),Upvalence.class);
startActivity(i);

您应该输入名称

Intent i = new Intent(getActivity().getApplicationContext(),Upvalence.class);
i.putExtra("string", SlectedName);
startActivity(i);

然后,在您的Upvalence活动中:

Then, on your Upvalence activity:

 @Override
 protected void onCreate(@Nullable Bundle savedInstanceState) {
    Bundle arguments = this.getIntent().getExtras();
    String yourString = arguments.getString("string");
 }

这篇关于将数据从对话框传递到新活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 23:16