0

我正在使用我定制为显示列表的customDialog。我的要求是在我的应用程序中有Edittext的地方。我需要显示这个对话框。我在editext中使用Textwatcher,而用户输入一个数字,就像用户输入1时将它传递给那个对话框类并完成了一些功能来制作一个像 10,100,1000,10000 这样的列表。

现在,一旦用户从此列表中选择了任何数字,我想将其设置为 Editext。我该怎么做?我要尝试一整天吗?

public static void amount_dialog(final Activity activity,String str)
{
     amount=str;

     sequence_number();//from this method am generating list and setting it into my Arraylist

     dialog=new  Dialog(activity,R.style.CustomDialogTheme);    

     dialog.setContentView(R.layout.customdialog);

     ListView listView=(ListView) dialog.findViewById(R.id.listView12);              
     adapter=new ArrayAdapter<String>(activity,R.layout.list2,R.id.list_text1, strings);
     listView.setAdapter(adapter);  
     listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            selected_amount=adapter.getItem(arg2);

            dialog.dismiss();


        }
    });


     dialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;

     dialog.show();
     dialog.setCanceledOnTouchOutside(true);


}
4

2 回答 2

0

只需将 EditText 对象传递给此方法,在 OnitemClickListener 中,您就可以使用 Arraylist 中的值将文本设置为 EditText。

public static void amount_dialog(final Activity activity,String str,EditText edittextObject)
{
     amount=str;

     sequence_number();//from this method am generating list and setting it into my Arraylist

     dialog=new  Dialog(activity,R.style.CustomDialogTheme);    

     dialog.setContentView(R.layout.customdialog);

     ListView listView=(ListView) dialog.findViewById(R.id.listView12);              
     adapter=new ArrayAdapter<String>(activity,R.layout.list2,R.id.list_text1, strings);
     listView.setAdapter(adapter);  
     listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            selected_amount=adapter.getItem(arg2);
             edittextObject.setText("get the value from arraylist here");
            dialog.dismiss();


        }
    });


     dialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;

     dialog.show();
     dialog.setCanceledOnTouchOutside(true);


}
于 2012-05-17T11:39:23.160 回答
0

我假设您作为参数传递的活动是包含您的 EditText 的活动。所以你可以做这样的事情:

EditText editText = (EditText)activity.findViewById(theIDofYourTextEdit);
editText.setText(selectedAmount);

在您的 onItemClick 方法中。

我希望这有帮助

于 2012-05-17T11:43:24.433 回答