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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:28:47+00:00 2026-05-30T14:28:47+00:00

facing problem in searching and displaying the list using text watcher. it is a

  • 0

facing problem in searching and displaying the list using text watcher.
it is a simple search operation in the List.
firstly the data is retrieved from the .txt line by line.
first word of string is stored in the list content and now i want to perform search operation on this content list and display the result in listview

here is the code

enter code here

package com.android;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

import android.app.ListActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.ListView;
import android.widget.TextView;

public class MyListDemoActivity extends ListActivity {
    /** Called when the activity is first created. */
    TextView tv;
    // final String[] values=new String[]{"android","Windows",
    // "ios","BlackBerry","Java",".Net","WebOS", "Ubuntu", "Windows7"};
    //String[] content;
    List<String> content ;

    AutoCompleteTextView actv;
    List<String> arr_sort;
    ArrayAdapter<String> adapter;
    ListView lv;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


        String line = " ";
        LineNumberReader linenoreader = null;
        StringTokenizer stringtokanixer = null;
        content=new ArrayList<String>();
        lv=(ListView)findViewById(android.R.id.list);

        try {

            InputStream istream = getResources().openRawResource(R.raw.hihihi);
            InputStreamReader streamreader = new InputStreamReader(istream);

            linenoreader = new LineNumberReader(streamreader);
            linenoreader.mark(15);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }// try catch ends here



        Log.v("getting", "working");

        for (int i = 0; i < 6; i++) {
            try {
                line = linenoreader.readLine();
            } catch (IOException e) {

                e.printStackTrace();
            }
            Log.v("getting", line);
            stringtokanixer = new StringTokenizer(line);

            String st=stringtokanixer.nextToken();
            content.add(st);    
        }// for ends here

                    adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,content);
        //          setListAdapter(adapter);

                    lv.setAdapter(adapter);
                    tv= (TextView)findViewById(R.id.textView1);



                    actv=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
                    actv.addTextChangedListener(new TextWatcher() {
                        int len=0;
                        @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

                            len=actv.getText().length();

                            for(int i=0;i<content.size();i++)
                            {
                                if(len<=content.get(i).length())
                                {
                                    if(actv.getText().toString().equalsIgnoreCase((String) content.get(i).subSequence(0, len)))
                                    {

                                        arr_sort.add(content.get(i));

                                    }


                                }

                            }

                            adapter=new ArrayAdapter<String>(MyListDemoActivity.this,android.R.layout.simple_list_item_1,arr_sort);
                            setListAdapter(adapter);
                        }
                    }); // text watcher class ends here



    }// on create ends here
    public void onListItemClick(ListView ls,View v, int position,long id) {
      tv.setText(content.get(position));

      //tv.setText(content[position]) // in case of string

    }// endsd here onListItemClick(
}

here is the main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <AutoCompleteTextView
        android:id="@+id/autoCompleteTextView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text=" " >

      </AutoCompleteTextView>


    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="TextView" />

    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:drawSelectorOnTop="false"
         >
    </ListView>

</LinearLayout>

here is txt file

joke happy 
hota happy okgame
ok happy okgame
asitis happy 
okgame happy 
oktested happy happy 

i guess there is logical error in afterTextChanged but cant figure it out.

  • 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-05-30T14:28:49+00:00Added an answer on May 30, 2026 at 2:28 pm

    solved

    im working on icecream sandwitch…
    it worked with this code…

    public void onTextChanged(CharSequence s, int start, int before,
                        int count) {
                        arr_sort = new ArrayList<String>();
    
                        len = actv.getText().length();
    
                        for (int i = 0; i < content.size(); i++) {
                            if (len <= content.get(i).length()) {
                                if (actv.getText()
                                        .toString()
                                        .trim()
                                        .equalsIgnoreCase(
                                                (String) content.get(i).subSequence(0,
                                                        len))) {
    
                                    arr_sort.add(content.get(i));
                                    Log.v("infor loop afterTextChanged", s.toString());
                                }
    
                            }
    
                        }
    
            //          adapter.notifyDataSetChanged();
    
                        adapter = new ArrayAdapter<String>(MyListDemoActivity.this,
                            android.R.layout.simple_list_item_1, arr_sort);
                        setListAdapter(adapter);
    
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am facing problem in getting Facebook data I am using Facebook SDK for
I am facing such problem in which 's is present in data. while searching
I'm currently facing in problem using Core Data. I have two entities A and
I am facing problem while trying to open a simple text file in C#.
I've been searching through forums to find a solution for the problem I'm facing
I'm facing a problem with IE6. I took the toggle function from this website
I'm facing a problem while unit testing my forms. The problem is that data
Im facing problem when trying to apply data annotation. In my case im passing
I'm facing problem when migrate my web app project from development server to live
I'm facing problem in showing FolderBrowserDialog instance created and called from a non-UI thread.

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.