gpt4 book ai didi

android - ListView 搜索

转载 作者:行者123 更新时间:2023-11-30 00:29:41 27 4
gpt4 key购买 nike

这是我使用自定义适配器的代码,我用 mysql 数据填充了 ListView ,但在 edittext 中进行搜索显示零结果。

        lst=(ListView) findViewById(R.id.listViews);
search = (EditText) findViewById(R.id.search);


items=new ArrayList<Client_information>();
adapter=new Client_storeAdapter(getApplicationContext(),items);

lst.setAdapter(adapter);

Thread thread=new Thread(doInBackground);
thread.start();

search.addTextChangedListener(new TextWatcher() {

@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
adapter.getFilter().filter(cs);
adapter.notifyDataSetChanged();
Log.d("hello", "hello");
}

@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { }

@Override
public void afterTextChanged(Editable arg0) {}
});

}
Runnable doInBackground=new Runnable()
{

@Override
public void run()
{
items = Client_service.getAllRadioclient(myValue);
runOnUiThread(runOnUi);
}

};

Runnable runOnUi=new Runnable()
{

@Override
public void run()
{
for(Client_information radioitems:items)
{
adapter.add(radioitems);
}

adapter.notifyDataSetChanged();
}

};

}

这是我使用自定义适配器的代码,我用 mysql 数据填充了 ListView ,但在 edittext 中进行搜索显示零结果。

最佳答案

inputSearch.addTextChangedListener(new TextWatcher() {
     
    @Override
    public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
        // When user changed the Text
        MainActivity.this.adapter.getFilter().filter(cs);  
    }
     
    @Override
    public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
            int arg3) {
        // TODO Auto-generated method stub
         
    }
     
    @Override
    public void afterTextChanged(Editable arg0) {
        // TODO Auto-generated method stub                         
    }
});

在Manifest.xml中

android:windowSoftInputMode="stateHidden"

像这样

 <activity
android:name=".MainActivity"
android:label="@string/title_activity_main"
android:windowSoftInputMode="stateHidden">

关于android - ListView 搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22603236/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com