在Spinner选择上显示EditText项

时间:2014-04-02 08:57:51

标签: android android-edittext spinner

我在微调器中有一组项目,在点击时我想在EditText中显示相应的文本。我怎么能做到这一点。我想过使用switch但它对字符串不起作用。我希望有人告诉我这样做的正确方法。

我希望EditText数组(mysuburb)相应地响应Spinner项目(mystate)点击。

代码: -

    String[] mysuburb =new String[]{"sub1" ,"sub2","sub3","sub4","sub5","sub6"};




    String[] mystate= new String[]{"NSW","Victoria","Qld","NT","WA","SA"};      
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getActivity(), R.layout.listrow, mystate);
   // LTRadapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
    state.setAdapter(adapter);  

            state.setOnItemSelectedListener(new OnItemSelectedListener() {

                        public void onItemSelected(AdapterView<?> arg0, View arg1,int pos, long arg3) {
                            // TODO Auto-generated method stub

                            sstate =  state.getSelectedItem().toString();

                    /*  String sub= state.getItemAtPosition(0).toString();

                        if(sub=="sub1")
                            suburb.setText("sub1") ;  */



                             suburb.setText(arg0.getItemAtPosition(pos).toString()); 



                        }

                        public void onNothingSelected(AdapterView<?> arg0) {
                            // TODO Auto-generated method stub

                        }
                    });

1 个答案:

答案 0 :(得分:1)

 state.setOnItemSelectedListener(new OnItemSelectedListener() {

                    public void onItemSelected(AdapterView<?> adapterView, View view,int i, long l) {

            sstate =  state.getSelectedItem().toString();
            suburb.setText(sstate);

} }