繁体   English   中英

奇怪的微调器。 如何解决?

[英]Strange Spinner. How to fix it?

这是我用于填充微调器的代码。 看起来奇怪又丑陋。

    @Override
    protected void onPostExecute(final List<String> result) {
        System.out.println("Result: " + result);
        final SpinnerAdapter adapter = new ArrayAdapter<String>(SearchTopActivity.this, android.R.layout.simple_spinner_dropdown_item, new String[]{"test1", "test2"});
        countrySpinner.setAdapter(adapter);
    }

<Spinner
    android:id="@+id/countrySpinner"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

在此处输入图片说明

如何解决这个问题

在此处输入图片说明

我认为发生这种情况是因为您使用了布局文件。 尝试使用:

android.R.layout.simple_spinner_item

(SearchTopActivity.this, android.R.layout.simple_spinner_dropdown_item, new String[]{"test1", "test2"})更改此设置

android.R.layout.simple_spinner_dropdown_item to android.R.layout.simple_spinner_item

请参阅http://developer.android.com/resources/tutorials/views/hello-spinner.html

尝试这个

@Override
    protected void onPostExecute(final List<String> result) {
        System.out.println("Result: " + result);
    final String[] test = new String[] { "test1", "test2" };

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, test);
    countrySpinner.setAdapter(adapter);
}
and xml as::

<Spinner
    android:id="@+id/countrySpinner"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />

我遇到了同样的问题,我只是通过扩展BaseAdapter并实现SpinnerAdapter编写了自己的适配器。 我也写了一个项目布局:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/tvParticipantSpinnerName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>

而且微调器的行为正常。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM