0

How do I create search friends like this http://i.dailymail.co.uk/i/pix/2011/08/11/article-2024574-0D63567000000578-432_306x458.jpg dynamically in android ? I really appreciate any help .I have used autocompletetextview and it duplicates entry when I search ,asked here : https://stackoverflow.com/questions/21488902/autocompletetextview-dynamic-with-3-textview-and-1-imageview .Thanks in Advance.

Community
  • 1
  • 1
jason
  • 3,932
  • 11
  • 52
  • 123

1 Answers1

1

Try this Simple Code: (Without Using AutoCompleteTextView)

XML:

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <EditText
            android:id="@+id/editText1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Name" >

            <requestFocus />
        </EditText>
    </LinearLayout>

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>

</LinearLayout>

Java Activity Class:

public class SOF_AutoList extends Activity
{
    private ListView listview;
    private EditText edttxt;
    private ArrayAdapter<String> adapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sof__auto_list);

        ArrayList<String> data = new ArrayList<String>();
        for(int i=0;i<10;i++)
        {
            if(i==0 || i==1 || i==3)
            {
                data.add("Apple "+(i+1));
            }
            else if(i==4 || i==5)
            {
                data.add("Banana "+(i+1));
            }
            else
            {
                data.add("CArrot "+(i+1));
            }
        }

        listview = (ListView)findViewById(R.id.listView1);
        adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1,data);
        listview.setAdapter(adapter);

        edttxt = (EditText)findViewById(R.id.editText1);
        edttxt.addTextChangedListener(new TextWatcher()
        {

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                // TODO Auto-generated method stub
                adapter.getFilter().filter(s);
            }

            @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

            }
        });
    }


}
Sagar Shah
  • 4,272
  • 2
  • 25
  • 36
  • Hello Sagar.Can you please look into it ,I am unable to resolve this issue. http://stackoverflow.com/questions/21450774/how-to-dynamically-add-suggestions-to-autocompletetextview-with-preserving-chara .Thanks I would really appreciate if you can come up with a fix.Thanks for your time .Also I dont know what to do with `URL mUrl` – jason Feb 02 '14 at 03:58
  • Did you look into the Question Link I sent? Can you tell me how to fix it.Thanks – jason Feb 02 '14 at 06:45
  • Didn't get time yet. Will sure look in to this when get time. – Sagar Shah Feb 02 '14 at 08:40