Cardview of welcome

Asked

Viewed 287 times

1

I got a welcome cardview. I would like after the first view the user pressed the Ok button, understood and the card left and no longer appears. Cardview de bem vindo

I already put onClick in XML:

            <android.support.v7.widget.CardView xmlns: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>

2 answers

1

facin cara... saves a value(1 and 0) as if it were a boleano in sheredPreferences and oncreate Voce adds it if the value is 0 , if it is a Voce draws the rest of the normal screen.

to do so You have to put the xmls apart and add it when it is false (when it is 0 in sheredpreference) and config so that when he clicks the You can call a method in the class of his oncreate (in the Activity that he is) and, this is important kkkkk,when he clicksVoce poe for 1 not to appear anymore.

  • Although the tips to use the sheredPreferences are great, I still prefer and find it simpler to use the local bank (Sqlite)

  • the problem in using the sqlite and that would be depleted, and would spend time doing this, and would lose efficiency, more and an option, and is to like...

0

As said, you can save this state on SharedPreferences:

Follow 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();
    }
  • Eai Thiago. I did by your example what you tell me but is giving an error when I execute. java.lang.Classcastexception: android.widget.Linearlayout cannot be cast to android.widget.Button In my cardview I am working with includes, so I gave the id to relatiive. I edited my question and put the code there. Check there, please.

  • Then the ok_button is a Textview and not a Button ! Try it like this: Textview.class.cast(findViewById(R.id.ok_button)). setOnClickListener

  • Got it? Put it there if you have any questions! We’re here to help!

  • I was able to put it in. But it still gives the same error. = (. I did like this: Textview.class.cast(findViewById(R.id.cardView)). setOnClickListener(new View.Onclicklistener() { ....

  • So! you have to respect what is stated in your XML

  • So brother, oh. I’m half layman in Java yet. I just copied your code and put it there. I know it’s not even a method to learn. It’s just that I have a tight deadline to deliver my app. = ( But thanks for the help bro. I’ll give another one studied here.

  • The element that has the id cardView is a Cardview then you’ll have to cast for a Cardview . the Element ok_button is a Textview then the cast is to Textview ! I will correct my answer !

  • Ta blz then bro. If you correct I will take your answer and play there. In case of any error I will search here. Thank you for the expensive strength.

  • Hahaha! I suggest paying attention to the mistakes! They show what we are doing wrong! Good luck there !

  • Blz guy. Suggestion noted. Thanks for the help. Abs.

Show 5 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.