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
ABRAHAM CHAVEZ REYES
361 Pointsneed help! Array Madness Extra Credit?
this is the way I did it. but when i press the button i get the whole array of numbers at the same time. i wold like to know if someone make just one number at a time not the whole array of numbers at the same click of button.
package com.example.hp.testlol;
import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.ImageButton; import android.widget.TextView;
import java.util.Arrays;
public class Mtest extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mtest);
final TextView firs=(TextView)findViewById(R.id.TV);
final TextView second=(TextView)findViewById(R.id.TV2);
ImageButton img1= (ImageButton)findViewById(R.id.img1);
View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View view) {
int[] numbersArray = { 5,7,3,0,1,2,8,9,4,6 };
Arrays.sort(numbersArray);
for (int a = 0; a < numbersArray.length; a++) {
firs.append(String.valueOf(numbersArray[a]));
}
for (int b = numbersArray.length - 1; b > -1; b--) {
second.append(String.valueOf(numbersArray[b]));
}
}
};
img1.setOnClickListener(listener);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.mtest, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}