当用户单击editText字段时,我需要显示该用户的微调器(动态)选择我需要设置Text for Edit文本的任何项目。如何做到这一点?
答案 0 :(得分:8)
public class Main extends Activity implements OnClickListener{
TextView textview_countries;
private String[] countries_list={"Philippines","Japan","Australia"};
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textview_countries=(TextView) findViewById(R.id.txtview_countries);
textview_countries.setInputType(InputType.TYPE_NULL); //To hide the softkeyboard
final ArrayAdapter<String> spinner_countries = new ArrayAdapter<String>(Main.this,android.R.layout.simple_spinner_dropdown_item, countries_list);
textview_countries.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
new AlertDialog.Builder(Main.this)
.setTitle("Select Countries")
.setAdapter(spinner_countries, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
textview_countries.setText(countries_list[which].toString());
dialog.dismiss();
}
}).create().show();
}
});
}
答案 1 :(得分:2)
您应该使用AutoCompleteTextView。
答案 2 :(得分:0)
OnClick
of TextView
,我已将AlertDailog框由MydataAdapter
组成,其中我已通过txt_show.setText(Arraylistdata[which].toString())
以显示在TextView
上
遵循以下代码:
txt_show.setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
new AlertDialog.Builder(MyActivity.this)
.setTitle("Select More Categories")
.setAdapter(MydataAdapter, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
txt_show.setText(Arraylistdata[which].toString());
dialog.dismiss();
}
}).create().show();
}
});