我正在制作一个拼字游戏应用程序,我想制作一个最高分系统。我开始制作一个数组,其中保存了球员的姓名和相应的分数。我想对分数数组进行排序,以便它们从最高到最低排列并输出分数(按降序排列)以及相应的名称。请指导我如何对分数进行排序并将其与相应的玩家姓名一起输出。任何帮助将非常感激。谢谢!
这是我到目前为止所拥有的:
public class MainTop extends Activity {
TextView show;
EditText name;
EditText score;
Button ok;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layouttop);
show = (TextView) findViewById(R.id.textView1);
name = (EditText) findViewById(R.id.editText1);
score = (EditText) findViewById(R.id.editText2);
ok = (Button) findViewById(R.id.button1);
ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String [] namearray = new String [4];
int [] scorearray = new int[4];
for (int i = 0; i < 4; i++){
String playername = name.getText().toString();
namearray[i] = playername;
String playerscorestr = score.getText().toString();
int playerscore = Integer.parseInt(playerscorestr);
scorearray[i] = playerscore;
show.setText(namearray[i] + scorearray[i]);
}