如何在Android中获取对话框值并在列表视图中显示?

时间:2019-03-23 14:25:04

标签: android

我想从对话框中获取值并在列表视图中显示,但是我不知道如何设置显示。有人可以帮我解决这个问题。预先感谢。

public void popup_addBT() {
        tv_addBT.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                final Dialog dialog = new Dialog(context);
                dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                dialog.setContentView(R.layout.popup_add_bluetooth);
                dialog.setCancelable(true);

                LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                final View view1 = inflater.inflate(R.layout.popup_add_bluetooth, null, false);
                ((Activity) context).getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
                dialog.setContentView(view1);
                final Window window = dialog.getWindow();
                window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
                window.setGravity(Gravity.CENTER);
                dialog.show();

                Button btn_saveBTAddress = (Button) dialog.findViewById(R.id.btn_saveBTAddress);

                btn_saveBTAddress.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {

                        EditText et_BTName1 = dialog.findViewById(R.id.et_add_BTName);
                        EditText et_BTAddress1 = dialog.findViewById(R.id.et_add_BTAddress);

                        String et_BTName = et_BTName1.getText().toString();
                        String et_BTAddress = et_BTAddress1.getText().toString();

                       /* ArrayList<String> arrayList = new ArrayList<>();
                        arrayList.add(et_BTName);
                        arrayList.add(et_BTAddress);
*/                      ArrayList<ModelList> alldata = new ArrayList();
                        alldata.add(et_BTName); //.. add all items needed
                        alldata.add(et_BTAddress); //.. add all items needed
                        DeviceListAdapter adapter = new DeviceListAdapter (context, alldata);
                        listView.setAdapter(adapter);

                        dialog.dismiss();

0 个答案:

没有答案