Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android自定义微调器问题_Android_Spinner_Android Custom View - Fatal编程技术网

Android自定义微调器问题

Android自定义微调器问题,android,spinner,android-custom-view,Android,Spinner,Android Custom View,在我的应用程序中,我正在使用自定义微调器 为此,我遵循了一个教程 在学习本教程的过程中,我遇到了一个小问题,每当用户从“微调器”下拉列表中选择一个特定项目时,微调器的标题就会消失,并在该位置显示所选项目的名称,如下图所示 但是,这里我想要的是,应该有一个固定的标题,必须出现在微调器上。 另一个问题是,当我从下拉列表中进行选择时,上一个选中的项会显示在下拉列表中选中项的位置。 如图所示 activity_main.xml xmlns:tools="http://schemas.androi

在我的应用程序中,我正在使用自定义微调器

为此,我遵循了一个教程 在学习本教程的过程中,我遇到了一个小问题,每当用户从“微调器”下拉列表中选择一个特定项目时,微调器的标题就会消失,并在该位置显示所选项目的名称,如下图所示

但是,这里我想要的是,应该有一个固定的标题,必须出现在微调器上。 另一个问题是,当我从下拉列表中进行选择时,上一个选中的项会显示在下拉列表中选中项的位置。 如图所示

activity_main.xml
    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent" >

      <Spinner
          android:id="@+id/customspinner"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_alignParentTop="true"
          android:layout_marginTop="40dp"
          android:background="@drawable/btn_dropdown" 
         android:drawSelectorOnTop="true"/>


提前感谢

示例中显示的内容-“Planet”是布局xml中微调器上方的文本视图,无需将标题与微调器代码或其值关联,如果这是您的要求(?),则粘贴一个包含预期输出和当前xml的屏幕截图
    android:id="@+id/RelativeLayout1"

    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    android:orientation="horizontal"
    android:background="@drawable/spinner_background"
    >

         <TextView
             android:id="@+id/spinnerText"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:gravity="center"
             android:text="Spinner Items" />
    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return myList.size();
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View myCustomView=convertView;

        if(convertView==null)
        {
            LayoutInflater inflater=getLayoutInflater();
            myCustomView=inflater.inflate(R.layout.spinner_row, null);

            TextView tv=(TextView)myCustomView.findViewById(R.id.spinnerText);
            tv.setText(myList.get(position));
        }
        return myCustomView;
    }

}