Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: help Text Watcher , List compare .logical error with afterTextChanged
    primarykey
    data
    text
    <p>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 <strong>content</strong> and now i want to perform search operation on this <strong>content</strong> list and display the result in <strong>listview</strong> </p> <p>here is the code</p> <pre><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&lt;String&gt; content ; AutoCompleteTextView actv; List&lt;String&gt; arr_sort; ArrayAdapter&lt;String&gt; 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&lt;String&gt;(); 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 &lt; 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&lt;String&gt;(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&lt;content.size();i++) { if(len&lt;=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&lt;String&gt;(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( } </code></pre> <p>here is the main.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;AutoCompleteTextView android:id="@+id/autoCompleteTextView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text=" " &gt; &lt;/AutoCompleteTextView&gt; &lt;TextView android:id="@+id/textView1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="TextView" /&gt; &lt;ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:drawSelectorOnTop="false" &gt; &lt;/ListView&gt; &lt;/LinearLayout&gt; </code></pre> <p>here is txt file</p> <pre><code>joke happy hota happy okgame ok happy okgame asitis happy okgame happy oktested happy happy </code></pre> <p>i guess there is logical error in afterTextChanged but cant figure it out.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload