0

I like to add addTextChangedListener into my listView but after run it, it doesn't show anythings in screen, just a blank screen. The logcat also gives nothing but only show out a tab which is "ActivityThread.performLaunchAcitvity(ActivityThread$ActivityClientRecord,Intent)line:2205" and its below display "Source not found" with a button(Edit Source Lookup Path).. I have tried some way but can't find a way to make it work so far..

here is the MainActivity:

public class MainActivity extends ListActivity {

ListView lv;
EditText inputSearch;
DefaultHttpClient httpclient;
HttpPost httppost;
HttpResponse response;
InputStream is;
BufferedReader reader;
StringBuilder sb;
String line,result;
String[] people;


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

    getList();

    lv= (ListView) findViewById(R.id.list_view);
    inputSearch= (EditText) findViewById(R.id.inputSearch);

    inputSearch.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
            if(s.length()==0){
                lv.clearTextFilter();
            }
        }
        public void beforeTextChanged(CharSequence s, int start, int count, int after){
        }
        public void onTextChanged(CharSequence s, int start, int before, int count)
        {
            lv.setTextFilterEnabled(true);
            lv.setFilterText(s.toString());
        }

    });
}

public void getList(){
    new Thread(){
        public void run(){
            try{
                 httpclient = new DefaultHttpClient();
                 httppost = new HttpPost("http://www.kryptoquest.com/testing/testList.php");
                 response = httpclient.execute(httppost);
                 is = response.getEntity().getContent();
            }catch(Exception e){
                Log.e("log_tag", "Error:"+e.toString());
            }

            //convert response to string
            try{
                    reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
                    sb = new StringBuilder();
                    line = null;
                    while ((line = reader.readLine()) != null) {

                            sb.append(line + "\n");

                    }
                    Log.d("test",sb.toString());
                    is.close();

                    result = sb.toString();

                    people = result.split("[*]");

                    runOnUiThread(new Runnable()
                    {
                        public void run(){
                            ArrayAdapter<String> list = new ArrayAdapter<String>(MainActivity.this,R.layout.list_item, R.id.user_name,people);
                            lv.setAdapter(list); 
                        }
                    });


            }catch(Exception e){
                    Log.e("log_tag", "Error converting result "+e.toString());
            }
        }
    }.start();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}
}

activity_main.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

 <!--Editext for Search -->
<EditText android:id="@+id/inputSearch"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:hint="Search.."
    android:inputType="textVisiblePassword"/>

<!--List View -->
<ListView
    android:id="@+id/list_view"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />

</LinearLayout>

list_item.xml:

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

<!--Single ListItem -->

<!--User Name -->
<TextView android:id="@+id/user_name"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="10dip"
    android:textSize="16dip"
    android:textStyle="bold"/>   

</LinearLayout>

In additionally, I have added the uses-permission android:name="android.permission.INTERNET">in its Manifest.

Thanks in advance.

  • Post all of your Logcat errors, so we can see what is happening. – Sam Nov 15 '12 at 05:38
  • 11-15 17:03:18.528: E/AndroidRuntime(23630): FATAL EXCEPTION: main 11-15 17:03:18.528: E/AndroidRuntime(23630): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.testlistview/com.example.testlistview.MainActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' 11-15 17:03:18.528: E/AndroidRuntime(23630): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2205) 11-15 17:03:18.528: E/AndroidRuntime(23630): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2240) – Raphael Thomas Liewl Nov 15 '12 at 09:11
  • 11-15 17:03:18.528: E/AndroidRuntime(23630): at android.app.ActivityThread.access$600(ActivityThread.java:139) 11-15 17:03:18.528: E/AndroidRuntime(23630): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262) 11-15 17:03:18.528: E/AndroidRuntime(23630): at android.os.Handler.dispatchMessage(Handler.java:99) 11-15 17:03:18.528: E/AndroidRuntime(23630): at android.os.Looper.loop(Looper.java:156) 11-15 17:03:18.528: E/AndroidRuntime(23630): at android.app.ActivityThread.main(ActivityThread.java:4987) – Raphael Thomas Liewl Nov 15 '12 at 09:12
  • 11-15 17:03:18.528: E/AndroidRuntime(23630): at java.lang.reflect.Method.invokeNative(Native Method) 11-15 17:03:18.528: E/AndroidRuntime(23630): at java.lang.reflect.Method.invoke(Method.java:511) 11-15 17:03:18.528: E/AndroidRuntime(23630): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 11-15 17:03:18.528: E/AndroidRuntime(23630): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 11-15 17:03:18.528: E/AndroidRuntime(23630): at dalvik.system.NativeStart.main(Native Method) – Raphael Thomas Liewl Nov 15 '12 at 09:12
  • 11-15 17:03:18.528: E/AndroidRuntime(23630): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' 11-15 17:03:18.528: E/AndroidRuntime(23630): at android.app.ListActivity.onContentChanged(ListActivity.java:250) 11-15 17:03:18.528: E/AndroidRuntime(23630): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:273) 11-15 17:03:18.528: E/AndroidRuntime(23630): at android.app.Activity.setContentView(Activity.java:1892) – Raphael Thomas Liewl Nov 15 '12 at 09:13
  • 11-15 17:03:18.528: E/AndroidRuntime(23630): at com.example.testlistview.MainActivity.onCreate(MainActivity.java:38) 11-15 17:03:18.528: E/AndroidRuntime(23630): at android.app.Activity.performCreate(Activity.java:4538) 11-15 17:03:18.528: E/AndroidRuntime(23630): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071) 11-15 17:03:18.528: E/AndroidRuntime(23630): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161) 11-15 17:03:18.528: E/AndroidRuntime(23630): ... 11 more – Raphael Thomas Liewl Nov 15 '12 at 09:13
  • Thanks, I spotted the problem right away. But next time click "edit" in the lower left hand of your question and add the LogCat to the question itself. It's easier for you and me. :) – Sam Nov 15 '12 at 17:43

1 Answers1

0

From your LogCat:

Your content must have a ListView whose id attribute is 'android.R.id.list'

Which means change the id of your ListView to this:

<!--List View -->
<ListView
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />

ListActivities require a ListView in the layout with this exact id.

Sam
  • 86,580
  • 20
  • 181
  • 179
  • Thanks,it's work for me!! But there is a problem occurs, that is, a black box appears when the edit box is pressed, the image like this: – Raphael Thomas Liewl Nov 16 '12 at 05:42
  • I don't see a link to the image... Could you try again? – Sam Nov 16 '12 at 05:52
  • Thanks,it's work for me!! But there is another problem occurs, that is, a black box appears when the edit box is pressed, the image like this: [http://www.kryptoquest.com/testing/list.png](http://www.kryptoquest.com/testing/list.png) can it to be removed? – Raphael Thomas Liewl Nov 16 '12 at 06:42
  • Yikes! Maybe [this question](http://stackoverflow.com/q/4281838/1267661) will help you. – Sam Nov 16 '12 at 07:05
  • Em...Sam, it's still doesn't work for me, the "Suggested Words" still displaying. Or it's the problem of devices? i used with HTC Desire V – Raphael Thomas Liewl Nov 16 '12 at 09:47