2010-11-24 83 views
3

當用戶點擊editText字段我需要從該用戶顯示微調(動態)選擇我需要設置文本編輯文本的任何項目。如何做到這一點?在單擊Android中的編輯文本時顯示微調?

+0

是的..你可以通過peter knego指出它完全正確。 – 2010-11-24 11:19:08

+0

冷藏到我的帖子bellow http://stackoverflow.com/questions/4266075/show-spinner-at-the-time-of-clicking-edit-text-in-android/14845943#14845943 – Cjames 2013-02-13 03:35:29

回答

2

您應該使用AutoCompleteTextView

+0

它會給列表在編輯/授予用戶輸入的時間。在項目選擇後,我需要將數據庫和列表中的項目顯示給用戶。我希望將項目文本設置爲EditText – Tester 2010-11-24 11:33:52

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(); 
     } 
    }); 
} 
相關問題