导航抽屉中的自动完成文本视图不显示结果

时间:2016-02-12 08:36:15

标签: android xml arraylist autocomplete

我尝试在AutocompleteTextView菜单的顶部使用NavigationDrawer来显示Array-List。我可以打字,但我没有得到任何结果。请帮助,我认为是因为观点。这是主要活动

Detalles.java

 NavigationView navigationView = null;
    Toolbar toolbar = null;
    AutoCompleteTextView autoTextView;
    String[] ciudades;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_detalles);


        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);



        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();

        navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);


        LayoutInflater inflator = (LayoutInflater) this
                .getSystemService(this.LAYOUT_INFLATER_SERVICE);
        View v = inflator.inflate(R.layout.nav_header_detalles, null);

        autoTextView  = (AutoCompleteTextView) v.findViewById(R.id.autoTextView);
        ciudades = getResources().getStringArray(R.array.ciudades);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(),android.R.layout.simple_dropdown_item_1line,ciudades);

        autoTextView.setAdapter(adapter);
        autoTextView.setThreshold(1);
    }

The **nav_header_detalles.xml** file which contains the AutoComplete TextView:

    <?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="wrap_content"
    android:background="@drawable/side_nav_bar"
    android:paddingBottom="6dp"
    android:paddingLeft="6dp"
    android:paddingRight="6dp"
    android:paddingTop="6dp"
    android:theme="@style/ThemeOverlay.AppCompat.Dark"
    android:orientation="vertical"
    android:gravity="bottom"
    android:padding="6dp"
    android:id="@+id/autoLayout">



    <AutoCompleteTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/autoTextView"
        android:ems="10"
        android:hint="@string/autoTextViewHint" />

</LinearLayout>

The main xml: activity_detalles.xml:

       <?xml version="1.0" encoding="utf-8"?>
      <android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start"
    android:theme="@style/AppTheme">


    <include
        layout="@layout/app_bar_detalles"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_detalles"
        app:menu="@menu/activity_detalles_drawer" />

    </android.support.v4.widget.DrawerLayout>

字符串“在strings.xml中的ciudades:

<string-array name="ciudades">
    <item>Albacete</item>
    <item>Alcala de Henares</item>
    <item>Alcobendas</item>
    <item>Alcorcon</item>
    <item>Algeciras</item>
    <item>Alicante</item>
    <item>Almeria</item>
    <item>Almoradi</item>
    <item>Altea</item>
    <item>Badalona</item>
</string-array>

它看起来像这样: NOT SHOWING RESULTS

1 个答案:

答案 0 :(得分:0)

好吧,我自己找到了答案,虽然这与我在乞讨时想要的有点不同。 解决方案是:

1)在$ DrawerLayout的$ NavigationView中删除app:header声明。

2)在我的案例中将其包含在$ MainActivity:Detalles中:     navigationView =(NavigationView)findViewById(R.id.nav_view);         navigationView.setNavigationItemSelectedListener(本);

    LayoutInflater inflator = (LayoutInflater) this
            .getSystemService(this.LAYOUT_INFLATER_SERVICE);
    View v = inflator.inflate(R.layout.nav_header_detalles, null);
    navigationView.addHeaderView(v);

    autoTextView  = (AutoCompleteTextView) v.findViewById(R.id.autoTextView);
    ciudades = getResources().getStringArray(R.array.ciudades);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(navigationView.getContext(),android.R.layout.simple_dropdown_item_1line,ciudades);
    autoTextView.setAdapter(adapter);
    autoTextView.setThreshold(1);