Welcome Cardview

1

I have a welcome cardview. I would like to after the first preview the user pressed the Ok button, understood and the card quit and no longer appears.

I'vealreadyputXMLonClick:

<android.support.v7.widget.CardViewxmlns:card_view="http://schemas.android.com/apk/res-auto"
            android:id="@+id/cardView"
            style="@style/Material_Card_View"
            card_view:cardBackgroundColor="@color/colorPrimary"
            card_view:cardCornerRadius="@dimen/card_corner_radius"
            card_view:cardElevation="@dimen/card_elevation">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:id="@+id/cardbemvindo">

                <include layout="@layout/headline_16dp" />

                <include layout="@layout/supporting_text_24dp" />

                <include layout="@layout/divider" />

                <TextView
                    android:id="@+id/ok_button"
                    style="@style/Material_Action"
                    android:layout_marginLeft="8dp"
                    android:layout_marginRight="8dp"
                    android:drawableLeft="@drawable/ic_check"
                    android:drawablePadding="@dimen/big_padding"
                    android:text="@string/card_ok"
                    android:textColor="@color/white"
                    android:onClick="clickOK"/>
            </LinearLayout>

        </android.support.v7.widget.CardView>
    
asked by anonymous 20.07.2016 / 20:57

2 answers

1

Facin face ... save a value (1 and 0) as if it were a boolean in sheredPreferences and oncreate you add it if the value is 0, if it is a you draw the rest of the normal screen.

To do this you have to add the xmls and add it when false (when it is 0 in sheredpreference) and config when it clicks the button you can call a method in its oncreate class (in the activity that it is) and that is important kkkkk, when he clicks you poe to 1 not to appear more.

    
20.07.2016 / 22:01
0

As stated, you can save this state in SharedPreferences :

Here's an example:

    public static final String IS_SHOW = "IS_SHOW";
    public static final String PREFERENCES = "PREFERENCES";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    ...
   TextView.class.cast(findViewById(R.id.ok_button)).setOnClickListener(new  View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setIsShow(true, getApplicationContext());
            }
        });

        boolean isShow = getIsShow(getApplicationContext());

        cardView.setVisibility(isShow ? View.GONE : View.GONE);

   }


    public boolean getIsShow(final Context mContext){
        //Cria uma instancia do SharedPreferences
        final SharedPreferences prefs = mContext.getSharedPreferences(PREFERENCES, Context.MODE_PRIVATE);
        return prefs.getBoolean(IS_SHOW, false);
    }


    /**
     * Grava as informações do objeto em um SharedPreferences.
     * @param mContext
     */
    public void setIsShow(boolean isShow, final Context mContext){
        //Cria uma instancia do SharedPreferences
        SharedPreferences prefs = mContext.getSharedPreferences(PREFERENCES, Context.MODE_PRIVATE);
        // Criamos um instancia do editor, para salvamos os dados
        SharedPreferences.Editor editor = prefs.edit();
        // para que sempre atualize, passamos o valor do Sistema.
        editor.putBoolean(IS_SHOW, isShow)
        // Para que as informações sejam atualizadas
        editor.apply();
    }
    
20.07.2016 / 22:37