1

特定の値のセットからデータを取得するオートコンプリート テキスト ビューを作成しました。ユーザーが提供された値からのみ選択できるようにし、他の選択肢に進むことができないようにしたいと考えています。

私は長い間実行可能な答えを探していましたが、手に入れることができませんでした。この点で何か助けていただければ幸いです。

PS: 私はすでに明らかなテキスト変更ウォッチャー メソッドなどを試しており、より価値のあるものを探していることに注意してください。ありがとうございました!:)

要求されたコード: (通常の基本的なオートコンプリート 1)

   autoText.setAdapter(this, android.R.layout.simple_dropdown_item_1line,arr);
   autoText.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                tool = my_adapter.getItem(position).toString();
            }
        });
   autoText.setOnItemSelectedListener(this);
   public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) 
{
    Intent i=new Intent(this,Home.class);
    startActivity(i);       
}

public void onNothingSelected(AdapterView<?> arg0)
{
}

public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,long arg3) 
{
    Intent i=new Intent(.this,Home.class);
    startActivity(i);       
}

public void afterTextChanged(Editable arg0)
{   }
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
        int arg3) 
{   }
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) 
{
    tool=null;
       // trying to capture the value of item selected in variable *tool*.
}
4

2 に答える 2

0

xml のオートコンプリート ビューで数字タグを使用する...、または inputType タグを使用する

于 2013-05-20T09:38:15.827 に答える
0

これを確認してください.しかし、私はテキストウォッチャーを使用しています.私はそれを試していません.自分でそれを行い、エラーをチェックする必要があります.

String[] YourArray={"foo","foo1","foo2"};
autoText.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub

            boolean flag=true;

            for(int i=0;i<YourArray.length;i++)
            {
            if(YourArray[i].contains(text.getText().toString()))
            {
                flag=false;
            }

            }

            if(flag==false)
            {
                String a=text.getText().toString();

                String b=a.substring(0, s.length()-1);

                text.setText(b);//If the text input by user is not in the array, we undo the user input by removing last character from edit text.

            }


        }
于 2013-05-20T10:27:59.950 に答える