Android AutoCompleteTextview 点击不起作用

Android AutoCompleteTextview click not working

我尝试了 AutoCompleteTextView 并获取了值,但我无法在 autocompletetextview 的点击事件中获取值,这是我的布局

 <AutoCompleteTextView
    android:id="@+id/atv_places"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:layout_below="@+id/lin"
    android:layout_gravity="center"
    android:layout_marginLeft="25dp"
    android:layout_marginRight="25dp"
    android:layout_marginTop="10dp"
    android:background="@drawable/et_chat"
    android:drawableLeft="@drawable/searchblue"
    android:drawablePadding="4dp"
    android:dropDownVerticalOffset="5dp"
    android:dropDownWidth="match_parent"
    android:hint="Search contacts..."
    android:scrollHorizontally="true"
    android:textColor="@color/Black"
    android:textCursorDrawable="@drawable/color_cursor"
    android:textSize="16dp"
    android:visibility="gone" /> 

和我的点击事件代码,以获取我通过适配器填充的值。我无法获取点击值或无法使用 toast。

  atvPlaces = (AutoCompleteTextView) v.findViewById(R.id.atv_places);

    mTxtPhoneNo = (AutoCompleteTextView) v.findViewById(R.id.mmWhoNo);
    mAdapternew = new SimpleAdapter(getActivity(), mPeopleList,
            R.layout.row, new String[] { "Name", "Phone" }, new int[] {
                    R.id.textView1, R.id.textView2 });
    atvPlaces.setAdapter(mAdapternew);
    atvPlaces.setThreshold(1);

    atvPlaces.setOnItemClickListener(new OnItemClickListener() {

        @SuppressWarnings("unchecked")
        @Override
        public void onItemClick(AdapterView<?> av, View arg1, int index,
                long arg3) {

            Toast.makeText(getActivity(), "auto", Toast.LENGTH_LONG).show();
            Map<String, String> map = (Map<String, String>) av.getItemAtPosition(index);

            String name  = map.get("Name");
            String number = map.get("Phone");
            atvPlaces.setText(""+name+"<"+number+">");  

        }



    });

我没有明白你的代码有什么问题,但下面是我根据你的代码制作的代码,它工作正常,请你自己检查。

 AutoCompleteTextView atvPlaces = (AutoCompleteTextView) findViewById(R.id.atv_places);
        ArrayList<HashMap<String,String>> mPeopleList=new ArrayList<>();
        HashMap h1 = new HashMap<String, String>();
        h1.put("Name","name1");
        mPeopleList.add(h1);

        HashMap h2 = new HashMap<String, String>();
        h2.put("Name","name2");
        mPeopleList.add(h2);

        final SimpleAdapter myAdapter = new SimpleAdapter(this, mPeopleList,
                android.R.layout.simple_spinner_dropdown_item, new String[] { "Name"}, new int[] {
                android.R.id.text1});

        atvPlaces.setAdapter(myAdapter);
        atvPlaces.setThreshold(1);

        atvPlaces.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> av, View arg1, int index,
                                    long arg3) {

                Toast.makeText(MainActivity.this, "auto", Toast.LENGTH_LONG).show();
                HashMap<String, String> map = (HashMap<String, String>) av.getItemAtPosition(index);

                String name  = map.get("Name");
                String number = map.get("Phone");

            }



        });