-1

こんにちは、スピナーの例を 1 つ作成する必要があります。

リストはスピナーボックスに追加されます:

List<String> list = new ArrayList<String>();
Intent in = getIntent();

String status = in.getStringExtra(KEY_STATUS);
list.add(status);
list.add("Q");
list.add("P");
list.add("F");
list.add("I");
list.add("C");

ここでは、ステータスは以前のアクティビティ ステータス値から取得されます。その他のリストはデフォルトで Q、P、F、I、および C です。最初のリストは以前のステータスのみが表示されるためです。最初にここにステータスを追加するだけです。ここですべての値を dd に追加しますレプリケーションを含むリストを作成し、for ループ チェックを使用して現在のステータスを確認し、リストから削除しようとします。この概念はここで使用されます。

これは私のコードです:

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);
    final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    setContentView(R.layout.change_status);
    if (customTitleSupported) {
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
    }

    final TextView myTitleText = (TextView) findViewById(R.id.mytitle);
    if (myTitleText != null) {
        myTitleText.setText("Change Order Status");
    }
  /*  Intent in = getIntent();

    // Get XML values from previous intent
    String orderid = in.getStringExtra(KEY_NAME);

    // Displaying all values on the screen
    TextView lblName = (TextView) findViewById(R.id.textView1);


    lblName.setText(orderid); */


    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){

           }
              }
    });

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

    }

    //Add animals into spinner dynamically
     private void createSpinnerDropDown() {

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

    //Array list of animals to display in the spinner
    List<String> list = new ArrayList<String>();
    Intent in = getIntent();

    String status = in.getStringExtra(KEY_STATUS);
    list.add(status);
    list.add("Q");
    list.add("P");
    list.add("F");
    list.add("I");
    list.add("C");
    for(i=0;i<((TextView) list).length();i++){
        if(list.get(i).equals(status)) {
                list.remove(list.get(i));
        }
     }
    //create an ArrayAdaptar from the String Array
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, list);
    //set the view for the Drop down list
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    //set the ArrayAdapter to the spinner
    spinner.setAdapter(adapter);
    adapter.notifyDataSetChanged();
    //attach the listener to the spinner
    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.
    }
   }

ここで私のアプリは強制的に閉じられています.また、コンソールウィンドウに次のエラーが表示されます:

  10-15 16:34:02.021: D/dalvikvm(2203): GC_EXTERNAL_ALLOC freed 947 objects / 65120 bytes in 61ms
  10-15 16:39:29.661: D/dalvikvm(2203): GC_FOR_MALLOC freed 5616 objects / 350760 bytes in 56ms
  10-15 16:39:30.342: D/dalvikvm(2203): GC_FOR_MALLOC freed 8368 objects / 548488 bytes in 52ms
  10-15 16:39:32.082: W/drawable(2203): Bad element under <shape>: margin
  10-15 16:39:32.092: W/drawable(2203): Bad element under <shape>: margin
  10-15 16:39:32.172: D/dalvikvm(2203): GC_FOR_MALLOC freed 5508 objects / 311288 bytes in 51ms
   10-15 16:39:32.172: I/dalvikvm-heap(2203): Grow heap (frag case) to 2.912MB for 87396-byte allocation
   10-15 16:39:32.232: D/dalvikvm(2203): GC_FOR_MALLOC freed 136 objects / 5536 bytes in 52ms
    10-15 16:39:32.292: D/dalvikvm(2203): GC_FOR_MALLOC freed 0 objects / 0 bytes in 58ms
   10-15 16:39:32.292: I/dalvikvm-heap(2203): Grow heap (frag case) to 2.990MB for 87396-byte allocation
   10-15 16:39:32.352: D/dalvikvm(2203): GC_FOR_MALLOC freed 70 objects / 2880 bytes in 55ms
    10-15 16:39:32.671: D/dalvikvm(2203): GC_FOR_MALLOC freed 6159 objects / 257232 bytes in 57ms
    10-15 16:39:33.042: D/dalvikvm(2203): GC_FOR_MALLOC freed 20488 objects / 928728 bytes in 55ms
     10-15 16:39:36.112: D/AndroidRuntime(2203): Shutting down VM
     10-15 16:39:36.112: W/dalvikvm(2203): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
     10-15 16:39:36.142: E/AndroidRuntime(2203): FATAL EXCEPTION: main
     10-15 16:39:36.142: E/AndroidRuntime(2203): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androidlogin.ws/com.androidlogin.ws.InsertionExample}: java.lang.ClassCastException: java.util.ArrayList
      10-15 16:39:36.142: E/AndroidRuntime(2203):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
     10-15 16:39:36.142: E/AndroidRuntime(2203):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
     10-15 16:39:36.142: E/AndroidRuntime(2203):    at android.app.ActivityThread.access$2300(ActivityThread.java:125)
     10-15 16:39:36.142: E/AndroidRuntime(2203):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
      10-15 16:39:36.142: E/AndroidRuntime(2203):   at android.os.Handler.dispatchMessage(Handler.java:99)
      10-15 16:39:36.142: E/AndroidRuntime(2203):   at android.os.Looper.loop(Looper.java:123)
      10-15 16:39:36.142: E/AndroidRuntime(2203):   at android.app.ActivityThread.main(ActivityThread.java:4627)
       10-15 16:39:36.142: E/AndroidRuntime(2203):  at java.lang.reflect.Method.invokeNative(Native Method)
      10-15 16:39:36.142: E/AndroidRuntime(2203):   at java.lang.reflect.Method.invoke(Method.java:521)
     10-15 16:39:36.142: E/AndroidRuntime(2203):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
      10-15 16:39:36.142: E/AndroidRuntime(2203):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
     10-15 16:39:36.142: E/AndroidRuntime(2203):    at dalvik.system.NativeStart.main(Native Method)
     10-15 16:39:36.142: E/AndroidRuntime(2203): Caused by: java.lang.ClassCastException: java.util.ArrayList
     10-15 16:39:36.142: E/AndroidRuntime(2203):    at com.androidlogin.ws.InsertionExample.createSpinnerDropDown(InsertionExample.java:122)
       10-15 16:39:36.142: E/AndroidRuntime(2203):  at com.androidlogin.ws.InsertionExample.onCreate(InsertionExample.java:101)
  10-15 16:39:36.142: E/AndroidRuntime(2203):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
   10-15 16:39:36.142: E/AndroidRuntime(2203):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
  10-15 16:39:36.142: E/AndroidRuntime(2203):   ... 11 more
   10-15 16:39:38.791: D/dalvikvm(2210): GC_EXTERNAL_ALLOC freed 976 objects / 66240 bytes in 50ms

これに対する解決策を教えてください。

4

1 に答える 1

0

この条件を使用します。

for(i=0;i<list.size();i++){
        if(list.get(i).equals(status)) {
                list.remove(list.get(i));
        }
 }

うまくいけば、それはすべての人にとってうまくいきます。

于 2012-10-15T11:34:09.440 に答える