dimanche 5 mai 2019

Random predefined Text in Viewflipper?

i´m new and try to make an app that shows predefined text´s (let´s say recipes). I want to have two buttons to go to the next or the previous recipe. I also want a random button and view the current recipe (1/100,2/100...).

I have the two buttons "next" and "previous", for this i´ve used a viewFlipper. But can´t find a solution for the "random"-button and the current number.

MainActivity.java:

    {
        viewFlipper = findViewById(R.id.view_flipper);

        viewFlipper.getDisplayedChild();
    }
    }



public void previousView(View v){
    viewFlipper.showPrevious();
}

public void nextView(View v)  {
    viewFlipper.showNext();
}

public void random(View v) {
    viewFlipper.showNext();
}

XML:

<ViewFlipper
    android:id="@+id/view_flipper"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:layout_gravity="center">

    <TextView
        android:id="@+id/text_view_id"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="Text 1"
        android:layout_gravity="center"
        />

    <TextView
        android:id="@+id/text_view_id2"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="Text 2"
        android:layout_gravity="center"
        />

    <TextView
        android:id="@+id/text_view_id3"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="Text 3"
        android:layout_gravity="center"
        />



</ViewFlipper>

I don´t have to get answers like "Copy this code to this spot".

I just want to know:

  • Is a viewFlipper the right thing for this app?
    • If yes, which function do i need to get a random recipe?
    • If no, which function should i use instead?
  • Which function do i need to view the current (page)?

Every little bit will help.




Aucun commentaire:

Enregistrer un commentaire