Thursday, June 23, 2011

[android-developers] dynamic list view i.e like phone book error

Hi guys,
I am trying to develop a list view, which contains country names and
on top of it i have a AutoCompleteTextView, so when ever i will search
for a particular string my list will get populated. but i m unable to
do that. means i want to show the matching names in the list view.
like our phones contact list.
so finally i replaced the AutoCompleteTextView with simple textview,
to do the same logic and failed again.

please
check my code
i have searched on net abt TextWatcher ,, and bit confused abt it..

*********************************************************************************************

package com.example;


import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class HelloListView extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);


ListView lv= (ListView) findViewById(R.id.listview);

AutoCompleteTextView lv1= (AutoCompleteTextView)
findViewById(R.id.searchText);


ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.simple_list_item_1, COUNTRIES);
lv1.setAdapter(adapter);

lv.setAdapter(new ArrayAdapter<String>(this,
R.layout.simple_list_item_1, COUNTRIES));

lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Toast.makeText(getApplicationContext(), ((TextView)
view).getText(),
Toast.LENGTH_SHORT).show();
}
});
}
static final String[] COUNTRIES = new String[] {
"Afghanistan", "Albania", "Algeria", "American Samoa","india",
"pakistan", "SriLanka"};
}

****Thanks
Atik

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment