使用我自定义的customDialog来显示list.my要求就是在我的应用程序中有Edittext.i需要在editext中使用Textwatcher显示此dialog.am,而用户输入一个数字,如果用户输入凌晨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);
}
答案 0 :(得分: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);
}
答案 1 :(得分:0)
我假设您作为参数传递的活动是包含EditText的活动。 所以你可以这样做:
EditText editText = (EditText)activity.findViewById(theIDofYourTextEdit);
editText.setText(selectedAmount);
在你的onItemClick方法中。
我希望这会有所帮助