Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.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:如何使微调器看起来像textView,并用自定义listview单击微调器打开对话框_Android_Android Layout_Listview_Android Spinner - Fatal编程技术网

Android:如何使微调器看起来像textView,并用自定义listview单击微调器打开对话框

Android:如何使微调器看起来像textView,并用自定义listview单击微调器打开对话框,android,android-layout,listview,android-spinner,Android,Android Layout,Listview,Android Spinner,请任何人都可以告诉我如何设计这个布局与微调器 这是我第一次使用spinner屏幕 这是我的屏幕,单击“选择城市”微调器可打开带有custon listview的对话框 在选择对话框项时,它会显示在第一个屏幕中,这是微调器的功能 请任何人都可以建议我怎么做 提前感谢。您可以按照以下步骤操作 1) 有一个文本视图而不是微调器,单击它的侦听器 2) 在onClick事件上,启动具有列表视图的对话框 3) 从Listview/对话框中选择项目,然后在Listview中再次设置它。有关快速修复: 创

请任何人都可以告诉我如何设计这个布局与微调器

这是我第一次使用spinner屏幕

这是我的屏幕,单击“选择城市”微调器可打开带有custon listview的对话框

在选择对话框项时,它会显示在第一个屏幕中,这是微调器的功能

任何人都可以建议我怎么做


提前感谢。

您可以按照以下步骤操作

1) 有一个文本视图而不是微调器,单击它的侦听器

2) 在onClick事件上,启动具有列表视图的对话框

3) 从Listview/对话框中选择项目,然后在Listview中再次设置它。

有关快速修复:

  • 创建一个自定义的相对布局,并在第一个屏幕上写入pune的位置放置一个微调器。使微调器背景透明或与相对布局的颜色相同

  • 从xml设置微调器模式对话框模式:

    android:spinnerMode=“对话框”

  • 将新的onClickListener设置为相对布局并放入:

    mySpinner.performClick()

  • 最后,在微调器适配器中定义自定义微调器行布局,如第二个屏幕中所示


使用spinner_layout.xml中的文本视图指定布局

<?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="match_parent" >

<TextView 
    android:id="@+id/id_of_your_textView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

</LinearLayout>
应该足够了。 如果微调器项应显示复杂项,请不要忘记覆盖
getDropDownView(int-position、View-convertView、ViewGroup-parent)方法。

是否尝试将onClickListener设置为文本视图?在onClick()方法中,您可以使用listview显示自定义对话框。是的,但我的问题是,依赖性就像我选择国家然后自动更改城市一样。因此我使用spinner,因为它的onItemSelected方法很有用。因此,在spinner适配器中,您可以为您的spinner膨胀自定义UI。别忘了正确覆盖getDropDownView()和getView()方法Hanks适配器设计是句柄,但是,如何使微调器看起来像textview我将在下面添加一个答案。我无法理解你说的“看起来像textview”的确切意思但若你们将微调器的背景设置为透明,我想它会看起来像一个文本视图。我的意思是微调器视图看起来像一个简单的文本视图,点击打开列表对话框。我设置了spinner spinnerMode=“dialog”的属性,但如何使SpinnerView看起来像简单的textview
//members
    protected Context context;
    protected LayoutInflater inflater;
//constructor
public CustomArrayAdapter(Context context) {
        super(context, resource);
        this.context = context;
        inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
//override method getView
@Override
    public View getView(int position, View convertView, ViewGroup parent) {
            View element = inflater.inflate(R.layout.spinner_layout, parent, false);
            TextView textView = (TextView)element.findViewById(R.id.id_of_your_textView);
            textView.setText("blah-blah");
            return element;
        }