spinner项目未显示在android上

时间:2013-01-24 10:32:34

标签: android android-spinner

我必须开发android微调器应用程序。

此处,不显示spinner list item。为什么会出现此错误。请帮帮我,给我一个解决方案。

我使用了以下代码:

public class NewCustomer extends Activity{
private final String NAMESPACE = "http://admin.com";
private final String URL = "http://10.0.0.75:8085/AdminLogin/services/InsertSpinner?wsdl";
private final String SOAP_ACTION = "http://admin.com/insertData";
private final String METHOD_NAME = "insertData";
Button btninsert;
String selectedItem;
Spinner spinner;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.new_customer);

    btninsert = (Button)findViewById(R.id.register);
    btninsert.setOnClickListener(new View.OnClickListener() {
         public void onClick(View v) {

                               insertValues();
                       } 

         });
     }
     public void insertValues(){
      SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);


    PropertyInfo bcoun =new PropertyInfo();
    bcoun.setName("Bcountry");
    bcoun.setValue(selectedItem);
    bcoun.setType(String.class);
    request.addProperty(bcoun); 

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.setOutputSoapObject(request);
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

    try{
     androidHttpTransport.call(SOAP_ACTION, envelope);
        SoapPrimitive response = (SoapPrimitive)envelope.getResponse();

        TextView result = (TextView) findViewById(R.id.textView2);
        result.setText(response.toString());

       }
      catch(Exception e){

        }
    //attach the listener to the spinner
    spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
    //Dynamically generate a spinner data 
    createSpinnerDropDown();

     }
        private void createSpinnerDropDown() {

    //get reference to the spinner from the XML layout
    spinner = (Spinner) findViewById(R.id.tf_country);

    //Array list of animals to display in the spinner
    List<String> list = new ArrayList<String>();
    Intent in = getIntent();
    list.add("United Status");
       list.add("Afghanistan");
       list.add("Aland Islands");
       list.add("Albania");
       list.add("Algeria");

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            R.layout.row, R.id.country, list);


  // adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setPrompt("Choose a Country");

  // spinner.setTextColor("#FF0000");
    spinner.setAdapter(adapter);
    adapter.notifyDataSetChanged();
    spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());

     }
      public class MyOnItemSelectedListener implements OnItemSelectedListener {

     public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {

      selectedItem = parent.getItemAtPosition(pos).toString();

       }


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

                }

    public void onNothingSelected(AdapterView<?> parent) {
        // Do nothing.
    }

       }

我必须运行应用程序并单击微调框选择微调项目。但是,这里的微调器项目没有显示...为什么不显示微调器项目?我的代码有什么问题?请帮帮我。

1 个答案:

答案 0 :(得分:0)

我必须调用createSpinnerDropDown();在onCreate Method。这些工作现在很好。