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

Eleni Minadaki
Eleni Minadaki
3,687 Points

stuck with a for loop in my app..

Hello treehousers, i try to make an app something like the diary for a month and i thought to make the texts change with a for loop because i want change in sequence and not with random. But as i expect i stuck because something i have to delete or to add in my main or in another class and i don't know what. If anyone can give a suggestion i appreciate! i am new in android and java and if i don't make step by step the lessons i stuck 1) The problem i have know is that when the app runs the colors change with the random But the text didn't, 2) i delete the random (as lesson says )from the factBookClass and create a for. 3)Below i will write my code for i) my main with the name ThoughtOfTheDayActivity.java ii)the FactBook.java and iii)ColorWheel.java (the only problem in colorwheel is that the color in the end " int colorAsInt = Color.parseColor(color);" is red but i don't have a warning why). i have write 31 articles for each day,something like a diary But instead of 31 i will write "5)......;" to don't be more tedious. Thanks a lot for any help you could give me.

FACTBOOK.JAVA public class FactBook { public static void main(String [] args){ String[] mFacts; mFacts = new String[5]; mFacts[0]...; mFacts[1]...; mFacts[2]...; mFacts[3]...; mFacts[4]...;

int i; for(i=0; i<mFacts.length; i++) { System.out.println(mFacts[i]);

};

public String getFact(){

String fact = "";
//Random randomGenerator = new Random();

// int randomNumber = randomGenerator.nextInt(mFacts.length);

// fact = mFacts[randomNumber];

return fact;

THOUGHTOFTHEDAYACTIVITY.JAVA

import android.app.Activity; import android.graphics.Color; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast;

import java.util.Random;

public class ThoughtOfTheDayActivity extends Activity {

public static final String TAG = ThoughtOfTheDayActivity.class.getSimpleName();

private FactBook mFactBook = new FactBook(); private ColorWheel mColorWheel = new ColorWheel();

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_thought_of_the_day); final TextView factLabel = (TextView) findViewById(R.id.factTextView); final Button showFactButton = (Button) findViewById(R.id.showFactButton); final RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.relativeLayout); View.OnClickListener listener = new View.OnClickListener() { @Override public void onClick(View view) { String fact = mFactBook.getFact();

        factLabel.setText(fact);

        int color = mColorWheel.getColor();
        relativeLayout.setBackgroundColor(color);
        showFactButton.setTextColor(color);
    }
};
showFactButton.setOnClickListener(listener);

//Toast.makeText(this, "Yay!our activity was created!", Toast.LENGTH_LONG).show(); Log.d(TAG, "We are login from the onCreate()method!"); } }

COLORWHEEL.JAVA

import android.graphics.Color;

import java.util.Random;

/** * Created by Eleni on 30/4/2015. */ public class ColorWheel {

public String [] mColors = {

    "#39add1",//1
    "#3079ab",//2
    "#c25975",//3
    "#e15258",//4
    "#f9845b",//5
    "#838cc7",//6
    "#7d669e",//7
    "#53bbb4",//8
    "#51b46d",//9
    "#e0ab18",//10
    "#637a91",//11
    "#f092b0",//12
    "#b7c0c7",//13
    "#C8AB65",//14
    "#FFCF75",//15
    "#99CCFF",//16
    "#9FBF8C",//17
    "#99CC99",//18
    "#C296B6",//19
    "#13A1CB", //20
    "#787A40",//21
    "#B7695C",//22
    "#CDBB79",//23
    "#51A39D"//24

};

public int getColor(){ String color = ""; Random randomGenerator = new Random(); int randomNumber = randomGenerator.nextInt(mColors.length);

color = mColors[randomNumber];

int colorAsInt = Color.parseColor(color);

return colorAsInt;

} }