[英]spinner item in android
Hi i have to develop one spinner example in android.here i have to used below code: 嗨,我必须在android中开发一个微调器示例。在这里,我必须使用以下代码:
public class InsertionExample extends Activity {
private final String NAMESPACE = "http://xcart.com";
private final String URL = "http://192.168.1.168:8089/XcartLogin/services/update?wsdl";
private final String SOAP_ACTION = "http://xcart.com/insertData";
private final String METHOD_NAME = "insertData";
Button btninsert;
String selectedItem;
private int i;
static final String KEY_NAME = "orderid";
static final String KEY_STATUS = "status";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.change_status);
Intent in = getIntent();
String status = in.getStringExtra(KEY_STATUS);
String[] DayOfWeek = {status, "Q", "P", "F", "I", "C"};
for(i=1;i<DayOfWeek.length();i++){
if(DayOfWeek.get(i).equals(status)) {
DayOfWeek.remove(DayOfWeek.get(i));
}
}
Spinner spinner = (Spinner) findViewById(R.id.spinner1);
btninsert = (Button)findViewById(R.id.btn_insert1);
btninsert.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent in = getIntent();
String orderid = in.getStringExtra(KEY_NAME);
String status = in.getStringExtra(KEY_STATUS);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo unameProp =new PropertyInfo();
unameProp.setName("Status");//Define the variable name in the web service method
unameProp.setValue(selectedItem);//Define value for fname variable
unameProp.setType(String.class);//Define the type of the variable
request.addProperty(unameProp);
PropertyInfo idProp =new PropertyInfo();
idProp.setName("Orderid");//Define the variable name in the web service method
idProp.setValue(orderid);//Define value for fname variable
idProp.setType(String.class);//Define the type of the variable
request.addProperty(idProp);
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){
}
}
});
//create an ArrayAdaptar from the String Array
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.row, R.id.country, DayOfWeek);
//set the view for the Drop down list
spinner.setAdapter(adapter);
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.
}
}
This is my for loop: 这是我的for循环:
for(i=1;i<DayOfWeek.length();i++){
if(DayOfWeek.get(i).equals(status)) {
DayOfWeek.remove(DayOfWeek.get(i));
}
}
Here i got below error on for loop: Cannot invoke length() on the array type 在这里,我在for循环上遇到以下错误: 无法在数组类型上调用length()
Cannot invoke get(int) on the array type String[] 无法在数组类型String []上调用get(int)
How can i remove this above error.please help me. 我该如何删除上述error.please帮助我。 String[]
串[]
Use: 采用:
DayOfWeek.length // no function!
and 和
DayOfWeek[i] // operator []
and read these documents: Java tutorial 并阅读以下文档: Java教程
and by the way: You can't remove items from an Array in Java. 顺便说一句:您无法从Java中的数组中删除项目。 As @Gabriel said, maybe an ArrayList is better suited for your needs here.
正如@Gabriel所说,也许ArrayList更适合您的需求。
String[] DayOfWeek is a table. String [] DayOfWeek是一个表。 If you want to get it's lenght just use DayOfWeek.lenght .
如果您想获得它的长度,请使用DayOfWeek.lenght。 Without ().
没有()。 And you don't get item on position i by DayOfWeek.get(i) but DayOfWeek[i].
而且您不会通过DayOfWeek.get(i)获得位置i上的项目,而是DayOfWeek [i]。 It's Java.
是Java。 Not C#.
不是C#。
It's DayOfWeek.length
, not DayOfWeek.length()
. 它是
DayOfWeek.length
,不是DayOfWeek.length()
。 It's a (final) variable of the array, not a method call. 这是数组的(最终)变量,而不是方法调用。
In your case, an ArrayList<String>
will serve you better, seeing you want to remove from the array (which you can't). 在您的情况下,
ArrayList<String>
会为您提供更好的服务,因为您希望从数组中删除(您不能这样做)。
You cannot delete an element from an array. 您不能从数组中删除元素。 You better use an arraylist which has an option to alter your data in the arraylist.
您最好使用一个arraylist,该列表具有一个选项,可以更改您在arraylist中的数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.