2014-04-29 7 views
0

나는 EditText editValue;Spinner spinnerActions을 가지고 있습니다.EditText 입력에 따라 동적으로 회 전자 값을 변경하는 방법

난 dinamically 사용자가 EditText

예컨대 삽입했는지 입력 Spinner있어서의 어댑터를 설정할

if(editValue.getText().equals("something"){ 
    spinnerActions.setAdapter(adapter1); 
} 
else if(editValue.getText().equals("something"){ 
    spinnerActions.setAdapter(adapter2); 
} 
else{ 
    //show warning if the user try to select a value of the spinner 
} 

내가 어떻게 이런 일을 할 수 있습니까?

답변

1

내가 분을 얻을 때 더 완전한 대답을 게시하려고합니다 관련이있는 경우

PS 첫 번째 값은 모든 어댑터에 대해 동일합니다. 첫째로 당신은 당신이보기를 얻을되면, 예를 들어

if(editValue.equals("something")) 
    spinnerActions.setAdapter(adapter1); 
+0

Adapter는 감사의 데이터를 변경합니다. 좋은 해결책. – AndreaF

0
(위에서), 그런 다음 그에 따라 어댑터를 설정할 수 있습니다

EditText editText = (EditText) findViewById(R.id.edit_text_id); 
editText.addTextChangedListener(new TextWatcher() { 

    @Override 
    public void onTextChanged(CharSequence s, int start, int before, 
      int count) { 
     // TODO use this to set your new string value 
     editValue = s;  // this won't work directly, but it is the idea of what you want to accomplish 
    } 
} 

텍스트의 변화를 확인하기 위해 리스너를 설정해야합니다 구현해야

당신은 spinnerAdapter 설정이 필요하고, 입력 텍스트에 따라

final Spinner spinner = (Spinner) findViewById(R.id.spinner); 
    final EditText editText = (EditText) findViewById(R.id.editText1); 
    Button button = (Button) findViewById(R.id.submit); 

    final List<String> stringList = new ArrayList<String>(); 
    final ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(ListEditActivity.this, 
       android.R.layout.simple_spinner_item); 

    spinner.setAdapter(spinnerAdapter); 

      button.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View v) { 
        // clear the array list 
        stringList.clear(); 
        // add the default item at first 
        stringList.add("FIRST ITEM"); 

        if (editText.getText() != null && editText.getText().length() > 0) { 
         String input = editText.getText().toString(); 

         if (input.toLowerCase().equalsIgnoreCase("one")) { 
          // add the spinner items for this input 
          stringList.add("ONE"); 
         } else if (input.toLowerCase().equalsIgnoreCase("two")) { 
          // add the spinner items for this input 
          stringList.add("TWO"); 
         } else { 
          // show dialog that invalid input 
          return; 
         } 
         // update the adapter with new data 
         spinnerAdapter.clear(); 
         // adding the item will also notify the spinner to refresh the list 
         spinnerAdapter.addAll(stringList); 
        } 
       } 
      }); 
관련 문제