2014-04-02 28 views
1

我有一组微件中的项目和他们的点击我想在EditText中显示相应的文本。我如何才能做到这一点。我想过使用开关,但它不适用于字符串。我希望有人告诉我这样做的正确方法。显示微调选项上的EditText项目

我想让EditText数组(mysuburb)根据微调项目(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 

         } 
        }); 
+2

后你的代码。 – Hariharan

+0

你试过了什么?显示你的代码。 – SilentKiller

+0

您是否使用Bean类对象来填充微调器?先显示代码。 – Dhaval

回答

1
state.setOnItemSelectedListener(new OnItemSelectedListener() { 

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

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

}}

+1

请同时添加在哪里写这行代码,如在微调项目选择回调? – AndiGeeky

相关问题