0

オンライン サーバーからアプリにダウンロードしたデータのテーブルがあります。クリックすると AlertDialog が表示される検索ボタンがあり、ユーザーに検索テキストを入力してもらいます。次のようになります。

public void buscar() {
    final EditText myView = new EditText(getApplicationContext());
    myView.setHint("Introduce texto aqui");
    AlertDialog.Builder alt_bld = new AlertDialog.Builder(this);
    alt_bld.setView(myView);
    alt_bld.setMessage("Introduce el texto o nombre del medio que deseas buscar:")

            .setCancelable(false)
            .setPositiveButton("Listo", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {

                }
            })
            .setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });

    TextWatcher filterTextWatcher = new TextWatcher() { 
        public void beforeTextChanged(CharSequence s, int start, int count,int after)
        {
        }
        public void onTextChanged(CharSequence s,int start, int before,int count)   
        {  
        }

        @Override
        public void afterTextChanged(Editable arg0) 
        {  
        }
    };
    buscartext = myView.getText();
    myView.addTextChangedListener(filterTextWatcher);
    AlertDialog alert = alt_bld.create();
    alert.setTitle("Buscar");
    alert.setIcon(R.drawable.searcha);
    alert.show();
}

警告ダイアログを表示して検索テキストを要求することで機能しますが、明らかにどのように機能するのか正確にはわかりません。onTextChanged と afterTextChanged 内でこれを試しました。

for(webResult currentItem: arrayOfWebData)
    {
        //Check if the Medio property of the current item matches the search
        if(currentItem.Medio.equals(s))
        { 
            FilteredArrayOfWebItems.add(currentItem);
        }
     } 
            // here call my list adapter to display items

webResult はインターネットからのテーブルであり、aFilteredArrayOfWebItems は検索結果のリストであることを意図していますが、機能しません。currentItem.Medio.equals(s) がテーブルの 1 つの列のみをチェックしていることはわかっていますが、複数の列を検索する必要があることに加えて、.equal のため、その行は検索に適していません。 searchtext%) 検索? このtextWatcherを使用するか、テーブルを検索するために別の方法を使用する必要がありますか?

4

0 に答える 0