簡體   English   中英

無法使AutoCompleteTextView與其他組件一起顯示

[英]Cannot get AutoCompleteTextView to show with other components

我正在嘗試構建一個簡單的Android應用,其活動之一將是Google Places AutoCompleteTextView以及一個Button和其他幾個組件。 但是,似乎是AutoCompleteTextView組件不想與其他任何對象友好地玩耍的情況。 目前,我一次只能獲得一個( AutoCompleteTextView組件)或其他渲染。 這是我的代碼的相關部分:

activity_main.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="horizontal" >

    <AutoCompleteTextView
        android:id="@+id/autoCompleteTextView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:text="Please enter your place" >
        <requestFocus />
    </AutoCompleteTextView>

    <Button
        android:id="@+id/btnChangeDate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Change Date" />

    <TextView
        android:id="@+id/lblDate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Current Date (M-D-YYYY): "
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/tvDate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=""
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <DatePicker
        android:id="@+id/dpResult"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>

list_item.xml

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

GooglePlacesAutocompleteActivity.java

public class GooglePlacesAutocompleteActivity extends Activity implements OnItemClickListener {

    // class fields are here ...

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        setCurrentDateOnView();    // sets up the date picker
        addListenerOnButton();     // adds a listener to a Button

        // next three lines configure the Google Place autocomplete
        AutoCompleteTextView autoCompView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);
        autoCompView.setAdapter(new GooglePlacesAutocompleteAdapter(this, R.layout.list_item));
        autoCompView.setOnItemClickListener(this);
    }

    // more methods...
}

如果您需要更多信息在此處提供答案,請隨時問我,我會盡快發布。

嗨,您在LinearLayout中存在方向問題。 我想您想將AutocompleteTextView放在其余的頂部。 如果是這種情況,您可能應該添加一個嵌套的LinearLayout。

<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" >

      <AutoCompleteTextView
          android:id="@+id/autoCompleteTextView"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:ems="10"
          android:text="Please enter your place" >
          <requestFocus />
      </AutoCompleteTextView>

      <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="wrap_content"
          android:orientation="horizontal" >

          [your other items]

     </LinearLayout>

</LinearLayout>

如果這不是您要查找的內容,則只需將match_parent更改為wrap_content,以獲取AutocompleteTextView的寬度。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM