1

こんにちは、ここで 1 つのアプリを実行しています。リスビューにクローンを表示する必要があり、そのリストビューに検索 (フィルター) アクションを設定する必要があります。以下のコードを使用してみましたが、ほとんど正常に動作しています。最初の文字を入力すると、リストビューの下に表示されることを意味します。その文字に関連する名前が表示されますが、両方の列に表示されます。入力 ?2列に基づいて名前をフィルタリングする必要がある任意の文字を使用してください。アイデアがある人は私に提案してください...

     ListMobileActivity.class: 
    public class ListMobileActivity extends Activity {EditText edittext;
 ListView listview;
 String qustion="?";

 String[] text = { "One", "Two", "Three", "Four", "Five", "Six", "Seven",
 "Eight", "Nine", "Ten" };

 String[] text1 = { "udya", "aswini", "radha", "padma", "ram", "harish", "parasd",
         "adi", "harbinder", "pandu" };


 int textlength = 0;
 ArrayList<String> text_sort = new ArrayList<String>();
 ArrayList<String> text_sort1 = new ArrayList<String>();


 public void onCreate(Bundle savedInstanceState)
 {

 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);

 edittext = (EditText) findViewById(R.id.EditText01);
 listview = (ListView) findViewById(R.id.ListView01);
 listview.setAdapter(new MyCustomAdapter(text, text1));
 edittext.addTextChangedListener(new TextWatcher()
 {

 public void afterTextChanged(Editable s)
 {

 }

 public void beforeTextChanged(CharSequence s, int start,
 int count, int after)
 {

 }

 public void onTextChanged(CharSequence s, int start,
 int before, int count)
 {

 textlength = edittext.getText().length();
 text_sort.clear();
 text_sort1.clear();

 for (int i = 0; i < text.length; i++)
 {



 if (textlength <= text[i].length())
 {

 if (edittext.getText().toString().
 equalsIgnoreCase((String) text1[i].subSequence(0, textlength)))
 {
 text_sort.add(text[i]);
 text_sort1.add(text1[i]);

 }

     if ((edittext.getText().toString()).

     equalsIgnoreCase((String) text[i].subSequence(0,textlength)))
     {
     text_sort.add(text[i]);
     text_sort1.add(text1[i]);

     } 




 }
 }

 listview.setAdapter(new MyCustomAdapter
 (text_sort, text_sort1));

 }
 });
 }

 class MyCustomAdapter extends BaseAdapter
 {

 String[] data_text;
 String[] data_text1;


 MyCustomAdapter()
 {

 }

 MyCustomAdapter(String[] text, String[] text1)
 {
 data_text = text;
 data_text1 = text1;

 }
 MyCustomAdapter(ArrayList<String> text, ArrayList<String> text1)
 {
 data_text = new String[text.size()];
 data_text1 = new String[text1.size()];


 for(int i=0;i<text.size();i++)
 {
 data_text[i] = text.get(i);
 data_text1[i] = text1.get(i);

 }

 }

 public int getCount()
 {
 return data_text.length;
 }

 public String getItem(int position)
 {
 return null;
 }

 public long getItemId(int position)
 {
 return position;
 }

 public View getView(int position, View convertView, ViewGroup parent)
 {

 LayoutInflater inflater = getLayoutInflater();
 View row;

 row = inflater.inflate(R.layout.list_item, parent, false);

 TextView textview = (TextView) row.findViewById(R.id.TextView01);
 TextView textview1 = (TextView) row.findViewById(R.id.TextView02);


 textview.setText(data_text[position]);
 textview1.setText(data_text1[position]);

 textview.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        String sss=qustion.concat(edittext.getText().toString());
        Log.i("sss--------------", ""+sss);
    }
});

 return (row);

 }
 }
  } 
4

1 に答える 1

-1

この例を試してください

Android でのリストビュー名検索

ここでは、編集テキストを入力するだけでリスト項目名を検索できます

于 2013-03-06T06:37:49.663 に答える