我必须开发 android spinner 应用程序。
此处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.
}
}
我必须运行应用程序并单击选择微调器项目的微调器框。但是,这里没有显示微调器项目......为什么没有显示微调器项目?我的代码有什么问题?请帮我。