Подтвердить что ты не робот

Элементы в раскрывающемся списке AutoCompleteTextView не отображаются. Как изменить свой цвет..?

Я сделал AutoCompletetextView. Элементы в раскрывающемся списке AutoCompleteTextView не отображаются. Как изменить цвет этих элементов.

Вот как это выглядит: - enter image description here

4b9b3361

Ответ 1

Просто укажем, что с помощью android.R.layout.simple_dropdown_item_1line он даст вам ту же проблему, с которой вы столкнулись выше. Поэтому вам лучше создать свой собственный TextView в файле .xml.

Ответ 2

Чтобы контролировать способ отображения элементов в вашем представлении автозаполнения, вы должны установить textViewResourceId в своем адаптере. Вы можете использовать ArrayAdapter и дать android.R.layout.simple_dropdown_item_1line как textViewResourceId, как показано ниже.

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line, yourList);
AutoCompleteTextView autocompleteView = (AutoCompleteTextView) findViewById(R.id.autocomplete_box);
autocompleteView.setAdapter(adapter);

ИЛИ

если вы хотите создать свой собственный стиль для отображаемых элементов, создайте XML с TextView в качестве корневого элемента, подобного этому (давайте назовите его my_custom_dropdown.xml черным текстом и белым фоном)

<?xml version="1.0" encoding="utf-8"?>
<TextView 
    xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:textSize="20sp" 
    android:padding="5sp"
    android:textColor="@color/black"
    android:background="@color/white"/>

Затем обратитесь к xml в вашем адаптере, как показано ниже:

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.my_custom_dropdown, yourList);

Ответ 3

Если изменение кода с "android.R.layout.simple_list_item_1" до "android.R.layout.simple_dropdown_item_1line" не работает для вас,

попробуйте написать этот код до setContentView

setTheme(android.R.style.Theme);

Это сработало для меня:)

Ответ 4

Просто используйте "android.R.layout.simple_list_item_1" вместо "android.R.layout.simple_dropdown_item_1line"..... ваша проблема будет решена...:)

Ответ 5

Я создаю пример проекта: AutoCompleteTextViewAdapter (Github Repo)

Вам нужно реализовать следующую строку исходного кода:

активность

ArrayAdapter<String> myCustomAdapter = new ArrayAdapter<String>(this, R.layout.text_custom_view, countriesNames);

final AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.auto_complete_text_view);
textView.setAdapter(myCustomAdapter);

XML с пользовательским TextView

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/country_name"
    style="@style/CustomTextView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:singleLine="true" />

Конечный результат

AutoCompleteTextViewAdapter

Ответ 6

Вот ответ в надежде, что другие принесут пользу

http://www.outofwhatbox.com/blog/2010/11/android-simpler-autocompletetextview-with-simplecursoradapter/

public class SelectState extends Activity {

final static int[] to = new int[] { android.R.id.text1 };  

    final static String[] from = new String[] { "state" };

    private TextView mStateCapitalView;
    private AutoCompleteTextView mStateNameView;
    private AutoCompleteDbAdapter mDbHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mDbHelper = new AutoCompleteDbAdapter(this);
        setContentView(R.layout.selectstate);
        Button confirmButton = (Button) findViewById(R.id.confirm);
        confirmButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                setResult(RESULT_OK);
                finish();
            }
        });

        mStateCapitalView = (TextView) findViewById(R.id.state_capital);
        mStateNameView = (AutoCompleteTextView) findViewById(R.id.state_name);

        // Create a SimpleCursorAdapter for the State Name field.
        SimpleCursorAdapter adapter = 
            new SimpleCursorAdapter(this, 
                    android.R.layout.simple_dropdown_item_1line, null,
                    from, to);
        mStateNameView.setAdapter(adapter);

        // Set an OnItemClickListener, to update dependent fields when
        // a choice is made in the AutoCompleteTextView.
        mStateNameView.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> listView, View view,
                        int position, long id) {
                // Get the cursor, positioned to the corresponding row in the
                // result set
                Cursor cursor = (Cursor) listView.getItemAtPosition(position);

                // Get the state capital from this row in the database.
                String capital = 
                    cursor.getString(cursor.getColumnIndexOrThrow("capital"));

                // Update the parent class TextView
                mStateCapitalView.setText(capital);
            }
        });

        // Set the CursorToStringConverter, to provide the labels for the
        // choices to be displayed in the AutoCompleteTextView.
        adapter.setCursorToStringConverter(new CursorToStringConverter() {
            public String convertToString(android.database.Cursor cursor) {
                // Get the label for this row out of the "state" column
                final int columnIndex = cursor.getColumnIndexOrThrow("state");
                final String str = cursor.getString(columnIndex);
                return str;
            }
        });

        // Set the FilterQueryProvider, to run queries for choices
        // that match the specified input.
        adapter.setFilterQueryProvider(new FilterQueryProvider() {
            public Cursor runQuery(CharSequence constraint) {
                // Search for states whose names begin with the specified letters.
                Cursor cursor = mDbHelper.getMatchingStates(
                        (constraint != null ? constraint.toString() : null));
                return cursor;
            }
        });
    }
}

Пожалуйста, проверьте строку    final static int [] to = new int [] {android.R.id.text1};