搜索像facebook这样的朋友

时间:2014-02-01 17:44:04

标签: android

如何在android中动态创建像http://i.dailymail.co.uk/i/pix/2011/08/11/article-2024574-0D63567000000578-432_306x458.jpg这样的搜索朋友?我真的很感激任何帮助。我使用了autocompletetextview,当我搜索时它重复输入,在这里询问:https://stackoverflow.com/questions/21488902/autocompletetextview-dynamic-with-3-textview-and-1-imageview。谢谢你。

1 个答案:

答案 0 :(得分:1)

试试这个简单代码:不使用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活动类:

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

            }
        });
    }


}