Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8331707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:29:46+00:00 2026-06-09T02:29:46+00:00

I have an EditText and Custom ListView Adapter connected sqllite db. I can add,

  • 0

enter image description here

I have an EditText and Custom ListView Adapter connected sqllite db.
I can add, remove and edit records. The next goal is filter the records by EditText.
I wroted this codes but It didn’t filtered correctly.

private EditText et_search_filter;
private TextWatcher watcher_search_filter;
et_search_filter = (EditText) findViewById(id.et_search_box);
et_search_filter.addTextChangedListener(watcher_search_filter);

watcher_search_filter = new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) {
    adapter.getFilter().filter(s);              
}

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

public void afterTextChanged(Editable s) {
}

};

Here my cursor method:

public ArrayList<Item> item_get_all() {
    ArrayList<Item> itemList = new ArrayList<Item>();

    String selectQuery = "SELECT * FROM " + TABLE_ITEMS;

    SQLiteDatabase db = this.getWritableDatabase();

    Cursor cursor = db.rawQuery(selectQuery, null);

    if (cursor.moveToFirst()) {
        do {
            Item dbitems = new Item();
            dbitems.setID(Integer.parseInt(cursor.getString(cursor.getColumnIndex(items_id))));
            dbitems.setName(cursor.getString(cursor.getColumnIndex(items_item_name)));
            dbitems.setBrand(cursor.getString(cursor.getColumnIndex(items_brand)));
            dbitems.setItemType(cursor.getString(cursor.getColumnIndex(items_type)));
            dbitems.setModel(cursor.getString(cursor.getColumnIndex(items_model)));
            dbitems.setNote(cursor.getString(cursor.getColumnIndex(items_note)));
            dbitems.setPurchaseFrom(cursor.getString(cursor.getColumnIndex(items_purchase_from)));
            dbitems.setPurchasePrice(cursor.getString(cursor.getColumnIndex(items_price)));
            dbitems.setPurchaseDate(cursor.getLong(cursor.getColumnIndex(items_purchase_date)));
            itemList.add(dbitems);              
        } while (cursor.moveToNext());
    }
    db.close();
    return itemList;
}

And I called cursor adapter like this:

public void getItemList() {     
    ArrayList<Item> itemArray = new ArrayList<Item>();      
    itemArray = db.item_get_all();      
    adapter = new ItemAdapter(this, R.layout.items_row, itemArray);
    ilistViewItems.setAdapter(adapter);                     
}

Here are my ItemAdapter.java and Item_row.xml files:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <TextView
        android:id="@+id/tv_item_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:text="@string/nullstr"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#ffffff"
        android:textSize="13dp"
        android:textStyle="bold" />
    <TextView
        android:id="@+id/tv_item_brand"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/tv_item_name"
        android:text="@string/nullstr"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="#bbbbbb"
        android:textSize="11dp" />
    <TextView
        android:id="@+id/tv_purchase_date"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/tv_item_name"
        android:text="@string/nullstr"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="#aabbbb"
        android:textSize="11dp" />
</RelativeLayout>

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import db.Item;
public class ItemAdapter extends ArrayAdapter<Item>{
private ArrayList<Item> items;
private TextView item_name;    
private TextView item_brand;
private TextView item_purchase_date;      

public ItemAdapter(Context context, int textViewResourceId, ArrayList<Item> objects) {
    super(context, textViewResourceId, objects);
    this.items = objects;

}

public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = vi.inflate(R.layout.items_row, null);
    }

    item_name = (TextView) convertView.findViewById(R.id.tv_item_name);    

    item_brand = (TextView) convertView.findViewById(R.id.tv_item_brand);
    item_purchase_date = (TextView) convertView.findViewById(R.id.tv_purchase_date);       

    item_name.setText(items.get(position).getName());       
    item_brand.setText("[" + items.get(position).getItemType() + "] " + items.get(position).getBrand() + " " + items.get(position).getModel());
    item_purchase_date.setText(items.get(position).getPurchasedDateStr());

    return convertView;
}   

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T02:29:47+00:00Added an answer on June 9, 2026 at 2:29 am

    Rewrite

    Have you implemented Item’s toString() method?

    public class Item {
        ...
    
        // Define a method to return a String that describes each Item, preferably unique String
        public String toString() {
            return name + "  " + brand + "  " + model + "  " + type;
        }
    }
    

    When I use this method with every thing you have posted, the EditText filters the ListView just fine. Let me know if this simple change works for you.

    Efficiency

    I want to point out a few tricks for your existing code to run faster.

    Look at your database adapter’s get_item_all() method.

    • For a new Cursor you only need to call moveToNext(), this will return true while there is valid data to be read.
    • IDs in SQliteDatabases are long data types. You should change the id in Item from an int to a long and use Cursor.getLong().
    • You search for each column’s index for every item. Find the indices once and store them locally.

    All together, this is more efficient:

    int idIndex = cursor.getColumnIndex(items_id);
    int nameIndex = cursor.getColumnIndex(items_item_name);
    //etc.
    
    while (cursor.moveToNext()) {
        Item dbitems = new Item();
    
        dbitems.setID(cursor.getLong(idIndex));
        dbitems.setName(cursor.getString(nameIndex));
        ...
        itemList.add(dbitems);              
    }
    

    Next, look at Item.getView().

    • You only need to create one LayoutInflater and store it in the class. I suggest initializing it in your constructor.
    • You use findViewById() and item.get(position) multiple times every time getView() is called. Whenever the user scrolls the ListView the adapter uses getView() to display each row, you only need to call findViewById() when convertView is null.

    All together:

    Create a variable called LayoutInflater mInflater and initialize it in your constructor:

    mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    

    In your ItemAdapter add this nested class:

    public class ViewHolder {
        TextView name;
        TextView brand;
        TextView purchase_date;
    }
    

    In getView():

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        Item item = (Item) getItem(position);
        if(convertView == null) {
            convertView = mInflater.inflate(R.layout.list_item, parent, false);
    
            viewHolder = new ViewHolder();
            viewHolder.name = (TextView) convertView.findViewById(R.id.tv_item_name);
            viewHolder.brand = (TextView) convertView.findViewById(R.id.tv_item_brand);
            viewHolder.purchase_date = (TextView) convertView.findViewById(R.id.tv_purchase_date);
            convertView.setTag(viewHolder);
        }
        else
            viewHolder = (ViewHolder) convertView.getTag();
    
        viewHolder.name.setText(item.getName());
        viewHolder.brand.setText("[" + item.getItemType() + "] " + item.getBrand() + " " + item.getModel());
        viewHolder.purchase_date.setText(item.getPurchasedDateStr());
        return convertView;
    }
    

    Do you see how much less work happens if convertView has already been created? Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have custom listview with editText and edit the edittext data on tapping edittext
I have a Listview with custom cursor adapter. I'm trying to prevent input in
We have created custom listview by using the Base adapter. List view contains Text
I have a custom listView with a textView, editText and a Button on a
I have a ListView with a custom adapter. It countains CheckBoxes. When one of
I have a custom listView with editText in each row to carry value entered
I have a custom ListView which contains one TextView (Of numbers) and one EditText
I have a custom EditText MomentumEditText that I have in a layout in xml
I have a custom dialog with one editText view and two buttons ok and
I have an EditText and a Button set next to each other on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.