选择选项“其他”时,我想输入文本

Spinner spn;
........
adapterString = new String[]
{
    "A",
    "B",
    "Other"
};
ArrayAdapter<String> adptLubricatorType = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, adapterString);
spn.setAdapter(adptLubricatorType);
spn.setOnItemSelectedListener(listenerspn);
private Spinner.OnItemSelectedListener listenerspn = new Spinner.OnItemSelectedListener() {

    @Override
    public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
            long arg3) {


    }


下拉微调器并选择“其他”时,如何插入文本?

我希望我可以输入诸如edittext之类的信息,当我单击其他内容时,“其他”将会更改
到我刚刚输入的字符串

最佳答案

始终使用EditText,但在XML文件中将其可见性设置为INVISIBLE。然后,当您检测到所选项目为"Other"时,将VISIBILITY设置为VISIBLE。就像是

@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
        long arg3) {
   //get the item selected item. Compare to the itme for which you want to make the EditText visible
   if( spn.getSelectedItem().toString().equals("Other"){
       yourEditText.setVisibility(View.VISIBLE);
   }

}


然后,可以通过使用EditText等照常处理onClickListener
希望您能理解这个概念,否则请发表评论。

10-08 13:38