简体   繁体   English

在Android中隐藏微调框并单击按钮显示

[英]Hide spinner in Android and display with the click of a button

I have created a spinner in my app which i want to be invisible when someone press the sos button then it should be visible for the user to select one option in it how can i solve it? 我已经在我的应用程序中创建了一个微调器,当有人按下sos按钮时我想使其不可见,然后用户可以在其中选择一个选项以使其可见,我该如何解决呢? 这是我创造的结果

I have created a spinner in my app which i want to be invisible when someone press the sos button 我在我的应用程序中创建了一个微调器,当有人按下sos按钮时我希望它不可见

You can set a listener on the button that will set the visibility of the spinner. 您可以在将设置微调器可见性的按钮上设置一个侦听器。

Ex. 例如

sosButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        mySpinner.setVisibility(View.GONE);
    }
});

it should be visible for the user to select one option in it how can i solve it? 用户应该在其中选择一个选项,这应该是可见的,我该如何解决呢?

I'm not sure what this means. 我不确定这是什么意思。 I thought you wanted the spinner to be invisible? 我以为您希望微调框不可见?

You can use the below code to hide and show the Spinner 您可以使用以下代码隐藏和显示微调框

//hide
spinner.setVisibility(View.GONE);

//show
spinner.setVisibility(View.VISIBLE);

Also,you can use the below code snippet to get the item selected by user; 另外,您可以使用下面的代码片段获取用户选择的项目;

spinner.setOnItemSelectedListener(this);

...

public void onItemSelected(AdapterView<?> parent, View view, int pos,long id) {
    Toast.makeText(parent.getContext(), 
    "OnItemSelectedListener : " + parent.getItemAtPosition(pos).toString(),
    Toast.LENGTH_SHORT).show();
}

//Hide //隐藏

spinner.setVisibility(View.GONE); spinner.setVisibility(View.GONE);

//Show //节目

spinner.setVisibility(View.VISIBLE); spinner.setVisibility(View.VISIBLE);

Android: How to make a Spinner invisible and then visible again? Android:如何使微调框不可见,然后再次可见?

@HumanOidRoBo you can do it by this code.. @HumanOidRoBo可以通过此代码来完成。

 <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:text="Optional"
                android:textSize="20sp" />


            <Spinner
                android:id="@+id/mySpinner"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:visibility="gone"
                android:layout_marginLeft="5dp">

            </Spinner>
        </LinearLayout>

and in class add this on click event of SOS 并在课堂上添加SOS的点击事件

sosButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
    mySpinner.setVisibility(View.VISIBLE); // for Show 

    // or
    mySpinner.setVisibility(View.GONE);   // for Hide
}  
}); 

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

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