2012-10-15 4 views
-1

Salut, je dois développer un exemple de spinner.spinner sélectionné dans android

liste

est ajouté sur la boîte de 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"); 

Ici le statut devient de liste d'état activité précédente value.other est defaulty Q, P, F, I et C.because la première liste est affichée drainant status only.so seulement je dois ajouter le statut ici first.ahere dd toutes les valeurs dans la liste, y compris la réplication puis en utilisant pour la vérification de la boucle pour l'état actuel et essayer de supprimer de la liste.ce concept est utilisé ici.

Ceci est mon code:

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. 
    } 
    } 

Ici mon application est la force closed.also obtenir l'erreur suivante sur ma fenêtre de la console:

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 

s'il vous plaît me donner une solution pour cela.

+0

Vérifiez la ligne à InsertionExample.java:122 –

+0

J'ai trouvé la solution pour cela. – user1676640

Répondre

0

utilisation de cette condition:

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

Espérons qu'il est travaillé pour tous.

Questions connexes