Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Build a Simple Android App (2014) Coding the Fun Facts Using an Array

maxmaltsev
maxmaltsev
3,419 Points

Extra Credit - Array Madness

Hi,

So i was trying to do an Extra Credit Task in Array Madness training at Android development section:

"Create a new project and add two TextViews to the screen. Create an array of numbers and see if you can display the numbers in order in the first TextView and then reversed in the second TextView."

What I'm I doing wrong? How make array numbers in order and reversed after?

   ```JAVA
   setContentView(R.layout.activity_array);

    TextView firstLabel = (TextView) findViewById(R.id.textView);//textview1
    TextView secondLabel = (TextView) findViewById(R.id.textView2);//textview2

    int myNumbers[] = {1,4,5,7,2,9,11,6,28,13}; // This is an array

    Arrays.sort(myNumbers); // Trying to sort it

    int firstTextView = myNumbers; // Wrong data type :(
    firstLabel.setText(firstTextView);

   ```
aakarshrestha
aakarshrestha
6,509 Points

You are missing index in the array you are using i.e. "firstLabel.setText(firstTextView[provide the index here]);"

   setContentView(R.layout.activity_array);

    TextView firstLabel = (TextView) findViewById(R.id.textView);//textview1
    TextView secondLabel = (TextView) findViewById(R.id.textView2);//textview2

    int myNumbers[] = {1,4,5,7,2,9,11,6,28,13}; // This is an array

    Arrays.sort(myNumbers); // Trying to sort it

    //Interating through the array list.
    for(int i =0; i < myNumber.length; i++){
             firstLabel.setText(myNumbers[i]); //you need to provide an index, which is "i" in this case, so the code knows from which position of the array it should start reading.
    }

Hope it clears your confusion.

Happy coding!