搜索查看的动作条:如何执行一个自定义列表视图与自定义适配器SQLite的搜索?自定义、适配器、视图、动作

2023-09-12 23:41:42 作者:取个真难

我有一个自定义的的ListView 有多个的EditText 和我想使搜索功能工作,只一个的EditText 取值。

我能够落实搜索查看动作条,到目前为止,但我不知道如何搜索在使用onQueryTextChange我SQLite数据库/提交方法。

我找遍了整个YouTube和谷歌,但没有找到绝对没有与自定义列表视图的工作明确很有帮助。我能找到有没有SQLite的数据的简单列表视图工作的一些不错的例子,但我不知道如何去适应那些我的情况...我真的需要帮助,请!

如果你需要的任意的其他信息,请随时提问,我会发布的时候了。非常感谢你!

code

查看我的customAdapter的的

 公开查看getView(INT的立场,观点来看,一个ViewGroup父){
    Cliente cliente = lista.get(位置);

    如果(查看== NULL)
    {
        LayoutInflater充气=(LayoutInflater)context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        鉴于= inflater.inflate(R.layout.single_row_listar_cliente,NULL);
    }

    TextView的txtNome =(TextView中)view.findViewById(R.id.tv_cliente_nome);
    txtNome.setText(cliente.getNome());

    TextView的txtSobrenome =(TextView中)view.findViewById(R.id.tv_cliente_sobrenome);
    txtSobrenome.setText(cliente.getSobrenome());

    //
    按钮BTN =(按钮)view.findViewById(R.id.btn_cliente_opcoes);


    btn.setOnClickListener(新View.OnClickListener(){
        @覆盖
        公共无效的onClick(视图v){
            Log.d(工作,K);
            //Mensagem.Msg(ListarCliente,成骨不全症,1000);
        }
    });


    返回查看;
}
 

解决方案 Android自定义视图仿瀑布布局

如果您使用ArrayAdapter,它根据简单的方法用getFilter(),这将筛选出的数据列表中搜索文本提供。 但使用相同的功能与数据库,你需要使用的CursorAdapter :文档

其中规定的方法 setFilterQueryProvider(filterQueryProvider) 当你需要传递数据库类的文字,并根据查询。 请参阅下面的教程,它提供了这个确切的实现:

的http://www.mysample$c$c.com/2012/07/android-listview-cursoradapter-sqlite.html

希望这有助于!

I have a custom ListView with multiple EditTexts and I would like to make the searching function work with only one of the EditTexts.

I was able to implement the SearchView on the ActionBar so far, but I have no idea how to search within my SQLite database using the onQueryTextChange/Submit methods.

I looked ALL over the youtube and google and could not find absolutely nothing explicitly helpful on working with a custom listview. I was able to find some nice examples on working with a simple listview without SQLite data, but I am not sure how to adapt those to my case... I really need help, please!!

If you need any other info, please feel free to ask and I will post right away. Thank you very much!

CODE

View of my customAdapter

public View getView(int position, View view, ViewGroup parent) {
    Cliente cliente = lista.get(position);

    if(view == null)
    {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.single_row_listar_cliente, null);
    }

    TextView txtNome = (TextView) view.findViewById(R.id.tv_cliente_nome);
    txtNome.setText(cliente.getNome());

    TextView txtSobrenome = (TextView) view.findViewById(R.id.tv_cliente_sobrenome);
    txtSobrenome.setText(cliente.getSobrenome());

    //
    Button btn = (Button) view.findViewById(R.id.btn_cliente_opcoes);


    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.d("working", "k");
            //Mensagem.Msg(ListarCliente, "oi",1000);
        }
    });


    return view;
}

解决方案

If you use ArrayAdapter, it provides easy method getFilter() which will filter data out in the list according to search text. But to use same functionality with database you need to use CursorAdapter : Documentation

Which provides method setFilterQueryProvider(filterQueryProvider) Where you need to pass the text and according query in database class. See below tutorial which provides exact implementation of this:

http://www.mysamplecode.com/2012/07/android-listview-cursoradapter-sqlite.html

Hope this helped!