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 9179807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:53:34+00:00 2026-06-17T17:53:34+00:00

I have a listview of different data which are stored in DB and when

  • 0

I have a listview of different data which are stored in DB and when i click particular data it will show the details of that and also i have used adapter class through position of the listview, it gets the detail of the data to display.

I need to add search for the listview and from the result listview, if i click the data it should show the details. please, can any one provide the code for this.

public class CustomerAdapter extends BaseAdapter{

public CustomerAdapter(Context context) {    
    this.context = context;
    this.layoutInflater = LayoutInflater.from(context);
    reload(0, TAKE);
}


private void reload(int skip, int take)
{
    totalSize = customers.size();
    System.out.println("Total Size:   "+totalSize);
    loadedCustomer = loadCustomers(skip, take);
}

private ArrayList<HashMap<String, Object>> loadCustomers(int skip, int take)
{
    ArrayList<HashMap<String, Object>> arrayList = new ArrayList<HashMap<String,Object>>();  

    Query query = new Query();
    query.select("x.fname, x.lname, x.surrogateKey, x.id");
    query.from("Customer", "x");
    query.orderBy("id", SortOrder.ASCENDING);
    query.setTake(take);
    query.setSkip(skip);

    lowIndex = skip;
    highIndex = lowIndex;

    QueryResultSet rs = SUP101.SUP101DB.executeQuery(query);
    while(rs.next())
    {
        String fname = rs.getString(1);
        String lname = rs.getString(2);
        long sk = rs.getLong(3);

        HashMap<String, Object> tempHashMap = new HashMap<String, Object>();
        tempHashMap.put(NAME, " " + fname + " " + lname);  
        tempHashMap.put("sk", sk);
        arrayList.add(tempHashMap);

        highIndex++;
    }

    return arrayList;  
}



public int getCount() {
    return totalSize;
}


public Object getItem(int position) {
    reloadIfNeeded(position);
    return loadedCustomer.get(position - lowIndex);
}

@SuppressWarnings("unchecked")
public String getSK(int position)
{
    HashMap<String, Object> map = (HashMap<String, Object>)getItem(position);
    return map.get("sk").toString();
}


private void reloadIfNeeded(int newPosition)
{
    if(newPosition < lowIndex || newPosition >= highIndex)
    {
        int lowIndex = (newPosition);
        reload(lowIndex, TAKE);
    }
}

public void refreshUI(boolean force)
{
    if(force)
    {
        reload(lowIndex, TAKE);
        ((Activity)context).runOnUiThread(
                new Runnable()
                {
                    public void run()
                    {
                        CustomerAdapter.this.notifyDataSetChanged();    
                    }                        
                }
           );
    }
}

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


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

    TextView tv = null;
    if(convertView==null){
        convertView = layoutInflater.inflate(R.layout.customer, null);
    }
    tv = (TextView)convertView.findViewById(R.id.textView1);        
    reloadIfNeeded(position);        
    tv.setText(loadedCustomer.get(position - lowIndex).get(NAME).toString());
return convertView;
}

// mainmenu class

        Mainmenu.this.runOnUiThread(new Runnable()
                    {
                        public void run()
                        {
                            adapter1 = new CustomerAdapter(Mainmenu.this);
                            listView.setAdapter(adapter1);

                            array_sort = new ArrayList<String>();
                            adapter1 =  new CustomerAdapter(Mainmenu.this);
                            listView.setAdapter(adapter1);
                            inputSearch.addTextChangedListener(new TextWatcher() {

                                @Override
                                public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
                                    // When user changed the Text
                                    Mainmenu.this.adapter1.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                          
                                }
                            });
                            listView.setOnItemClickListener(new OnItemClickListener()
                            {
                                public void onItemClick(AdapterView<?> a, View v, int position, long id)
                                {
                                    Intent intent = new Intent(Mainmenu.this, Detailview.class);
                                    intent.putExtra("sk", adapter1.getSK(position));
                                    Mainmenu.this.startActivityForResult(intent, REQUEST_DETAIL);
                                }

                            });
                        }

                    });
                }
            }).start();
  • 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-17T17:53:35+00:00Added an answer on June 17, 2026 at 5:53 pm

    You can make use of FilterQueryAdapter interface as below:

      DataBaseHelper myDbHelper = new DataBaseHelper(this);
      FilterQueryProvider fqp = new myFilterQueryProvider(myDbHelper);
            <YourCursorAdapter>.setFilterQueryProvider(fqp);
            <YourListView>.setTextFilterEnabled(true); 
            <YourEditTextSearchbox>.addTextChangedListener(new TextWatcher()
            {
                @Override
                public void onTextChanged(CharSequence s, int start,
                        int before, int count) {
                    // TODO Auto-generated method stub
    
                }
                @Override
                public void beforeTextChanged(CharSequence s, int start,
                        int count, int after) {
                    // TODO Auto-generated method stub
    
                }
                @Override
                public void afterTextChanged(Editable s) {
                    // TODO Auto-generated method stub
                    this.adaptr.getFilter().filter(s);
                }               
            });
    
      public class myFilterQueryProvider implements FilterQueryProvider {
        DataBaseHelper myDbHelper;
        public myFilterQueryProvider(DataBaseHelper mdb) {
            myDbHelper = mdb;
        }
        public Cursor runQuery(CharSequence constraint) 
        { 
    
            try {
                myDbHelper.openDataBase();
            }catch(SQLException sqle){
                throw sqle;
            }
    
            sql =""; //Your DB Query here
            Cursor cursor = myDbHelper.getLobbyView(sql);
            return cursor; 
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have multiple tabs that have different data inside. The first tab has ListView
I have several similar user controls which display listviews of respectively different data entities.
enter code here I have a ListView that have a different Layout XML for
I have Process objects that are monitored from two different views. A Windows.Forms.ListView (actually
I have ListView that uses a GridView to display several columns of data. Two
I have a ListView in which I inflate 4 different layouts dynamically. In every
I've created a custom adapter implementation. I also have a few different view types
I am trying to separate different columns of data that appear in my listview.
i have a ListView for which i have made a custom adapter which extends
I have a custom ListView adapter which implements an ImageThreadLoader class. Unfortunately, the class

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.