问题
Am using customDialog which i was customized to show list.my Requirement is Where ever having Edittext in my application.i need to show this dialog.am using Textwatcher in editext while user enter a number like if user enter 1 am passing it to that dialog class and done some functions to made a list like 10,100,1000,10000.
now once the user select any numbers from this list i want to set it into Editext.How can i do this? am trying this for a whole day?
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);
}
回答1:
Simply you can pass your EditText object to this method and inside the OnitemClickListener you can set text to the EditText using the values from your Arraylist.
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);
}
回答2:
I assume that the activity you pass as a parameter is the activity containing your EditText. So you can do something like this:
EditText editText = (EditText)activity.findViewById(theIDofYourTextEdit);
editText.setText(selectedAmount);
inside your onItemClick-method.
I hope this helps
来源:https://stackoverflow.com/questions/10634920/settext-to-edittextbox-from-dialog-content