gpt4 book ai didi

java - Android 中的微调项目

转载 作者:行者123 更新时间:2023-12-02 00:10:26 26 4
gpt4 key购买 nike

嗨,我必须在 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.
}
}

这是我的 for 循环:

  for(i=1;i<DayOfWeek.length();i++){
if(DayOfWeek.get(i).equals(status)) {
DayOfWeek.remove(DayOfWeek.get(i));
}
}

这里我在 for 循环中遇到以下错误:无法对数组类型调用 length()
无法对数组类型调用 get(int) 字符串[]

我怎样才能消除上面的错误。请帮助我。 字符串[]

最佳答案

用途:

DayOfWeek.length // no function!

DayOfWeek[i] // operator []

并阅读这些文档: Java tutorial

顺便说一句:您无法从 Java 中的数组中删除项目。正如@Gabriel 所说,也许 ArrayList 更适合您的需求。

关于java - Android 中的微调项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12911785/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com