2014-10-01 2 views
0

약간 혼란스럽고 회 전자에서 선택된 정보를 어떻게 사용할 수 있는지에 대한 아이디어가 필요합니다. 먼저 스피너는 AsyncTask를에이 코드에 의해, 웹 서비스를 통해 채워집니다회 전자의 선택된 항목을 사용하십시오.

@Override 
     protected Void doInBackground(Void... unused) { 
      ... 
      ... 
      ... 
      HttpTransportSE transportSE = new HttpTransportSE(URL); 
      try{ 
       //Web service call 
       transportSE.call(SOAP_ACTION_BRING_NEEDS, envelope); 

       //create SoapPrimitive and obtain response 
       resultsRequestSOAP = (SoapObject)envelope.getResponse(); 

       int intPropertyCount = resultsRequestSOAP.getPropertyCount(); 
       strNeeds = new String[intPropertyCount]; 

       for(int i= 0;i< intPropertyCount; i++) 
       {       
        //Format the information from the web service 
        Object property = resultsRequestSOAP.getProperty(i); 
        if (property instanceof SoapObject) { 
         SoapObject needsList = (SoapObject) property; 
         strNeeds[i] = needsList.getProperty("Descripcion").toString(); 
        } 
       } 

을 다음 postExecute에 나는 방법 spinnerNeeds()를 호출 회 전자를 채우기 : 것은이 때문이다

public void spinnerNeeds() { 
     //Needs Spinner Control 
     spnNeeds = (Spinner)findViewById(R.id.spnNeeds); 
     ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, strNeeds); 
     adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
     spnNeeds.setAdapter(adapter); 
     spnNeeds.setSelection(1); 

     spnNeeds.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 
      @Override 
      public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { 
       //Todo 
      } 
      @Override 
      public void onNothingSelected(AdapterView<?> parent) { 
      } 
     }); 
    } 

을 스피너는 strNeeds []에 속성 ("Descripcion")으로 채워지지만 웹 서비스 응답에는 3 개의 속성이 있으며 정보가 다른 활동으로 보내지도록 다른 속성 호출 "Codigo"가 필요합니다. 내가 필요로하는 "코디고"로 검증 할 수있는 옵션을 스피너에서 선택한 후에 어떻게 검증 할 수 있습니까?

"Descripcion"속성을 사용하여 다른 String [] strCode를 만들고 FOR() 속성에 "Codigo"속성을 저장하려고 생각했습니다 ...하지만 회 전자에서 옵션을 선택하면 어떻게됩니까? 그 strCode 유효성을 검사 ??

PD : 우세 값을 포함하지 않는 "Codigo"속성 값이 상기 제 1,2,3,4 아니다 .... 예들은 임의의 값을 가질 ...

답변

0

대답은 것 매우 복잡하지만 일단 이해하면 매우 간단합니다. 먼저, 3 개의 속성 (Description, Codigo ..)이있는 NEED라고하는 객체를 만들어야합니다. 다음으로 String 유형의 arrayadapter를 사용하는 대신 NEED 유형의 arrayadapter를 사용하십시오. 그런 다음 사용자 정의 클래스 인 NEED에서 toString() 메서드를 재정의하여 스피너에 표시해야하는 속성 값을 반환합니다. 이제 선택한 항목이 'Codigo'속성 값을 가져 오는 NEED 개체를 반환합니다.

class Need{ 
String description, codigo, property3; 
public Need(String desc, String codigo, String prop3) 
{ 
this.description = desc;//similarly for other 2 properties 
} 
@override 
private String toString() 
{ 
return this.description; 
} 
} 

strNeeds = new Need[intPropertyCount]; 
for(){ 
strNeeds[i] = new Need(); 
} 

ArrayAdapter<Need> adapter = new ArrayAdapter<Need>(this,android.R.layout.simple_list_item_1,  strNeeds); 
관련 문제