Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

zarah hafeez
zarah hafeez
317 Points

How to make a prev button funtionality?

I' making an app having 40 quotes, I already made a functionality for next quote, but what will be functionality of previous quote using button? My next button code is below:

package com.example.i7.fun_quotes;

import java.util.Random;

public class FunObject {

private String[] mFacts = new String[]{

        "The best word is Allah’s book. The best path is Muhammad’s path.",

        "The most dutiful amongst you is the one who learns and teaches the Qur'an.",

        "Every human being is born as a Muslim.",

        "Those that have a sparkle of arrogance will never enter paradise.",
        "Those servers whose feet got dusty on Allah’s path won’t touch hellfire.",

        "Nothing more than the believer’s good manner will weigh on the scale on Judgement Day.",
        "Allah loves the small deeds that are done constantly.",

        "The initiator of a good deed will get the same reward as the one who adapts this deed.",

        "Those that believe in Allah and in Judgement day shall either talk good things or remain silent.",

        "The best of you is the one with best character.",

        "A believer won’t redo the same mistake.",

        "The best among you is the one who’s useful for his family.",

        "The food you eat for which you have worked hard for is the best food.",

        "Purity comes from faith.",

        "Allah won’t appreciate your outer appearance and your wealth, but what’s in your heart and your deeds.",

        "Only by narrating everything you hear to others you’ll do many sins.",

        "Beware of speculations. Words which are based on speculations are the biggest lies.",

        "A Muslim is someone from whose hand and tongue others are safe from.",

        "A Muslim won’t stop listening to good advises until he’s entered paradise (ghanna).",

        "Allah won’t be merciful to those who aren’t merciful to others.",

        "The one who sleeps with a full stomach knowing that his neighbour is hungry doesn’t believe in me.",

        "Those who aren’t merciful to the little ones and don’t respect the old ones, aren’t from us.",

        "The things you don’t wish for yourself, don’t wish them for others, either.",

        "Never underestimate a good deed, even if it’s a smiling face to a fellow Muslim.",

        "Smiling is like giving alms (sadaqa).",

        "It is unlawful for a Muslim to be disgruntled to a fellow Muslim for more than three days.",

        "The giving hand is better than the one that takes.",

        "A good word is like giving alms (sadaqa).",

        "All Muslims are a part of one body.",

        "A Muslim is a mirror to a Muslim.",

        "Mankind is like the points of a comb. They’re balanced.",

        "Spread the Islamic greeting (salam) among yourselves.",

        "A Muslim is a Muslim’s fellow.",

        "Fasting(saum) is a Muslim’s shield.",

        "The ritual prayer (salat) is the divine light (nur).",

        "Every step you take to perform the ritual prayer (salat) is like giving alms (sadaqa) for Allah.",

        "The best deed for Allah is the ritual prayer (salat) which is done on time.",

        "The ritual prayer (salat) is the Muslim’s ascension.",

        "Patience (sabir) and invocation (du'a) are the best two weapons of a Muslim.",

        "There’s nothing more precious for Allah, than invocation (du'a)."


        };

public String GetFact(){

    String fact ="";
    Random randomnumbergenerator = new Random();
    int RandomNumber = randomnumbergenerator.nextInt(mFacts.length);
    fact = mFacts[RandomNumber];

    return fact;
}

}