Java 是洗牌还是把头撞在墙上?

Java 是洗牌还是把头撞在墙上?,java,android,arrays,list,Java,Android,Arrays,List,我正在尝试将数字列表从1-15重新排列。然后取前5个号码,将索引1分配给第一个btn的文本,将第二个号码分配给第二个btn的文本,以此类推。。。。问题是我已经尝试了几乎所有我在Stackoverflow中读到的东西,但是没有任何帮助。请帮忙 public class MainActivity extends Activity implements OnClickListener, CountdownTimerFinishedListener{ /** Called when the

我正在尝试将数字列表从1-15重新排列。然后取前5个号码,将索引1分配给第一个btn的文本,将第二个号码分配给第二个btn的文本,以此类推。。。。问题是我已经尝试了几乎所有我在Stackoverflow中读到的东西,但是没有任何帮助。请帮忙

    public class MainActivity extends Activity implements  OnClickListener,  
CountdownTimerFinishedListener{
/** Called when the activity is first created. */
//SET UP SPINS

 private TextView spins;    
 private Button spin;
 private Button s_1;
 private Button s_2;
 private Button s_3;
 private Button s_4;
 private Button s_5;

  private static final Random rand = new Random();

int totalspins = 15;
int gamescore = 0;
int s1 = 0;
int s2 = 0;
int s3 = 0;
int s4 = 0;
int s5 = 0;
int[] b_list ={1,2,3,4,5,6,7,8,9,10,12,13,14,15};

     @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.play_layout);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);


    gamescore=(0);
    score = (TextView) findViewById(R.id.score);
    score.setText(String.valueOf("SCORE: "+ gamescore));
    totalspins = (15);
    spins = (TextView) findViewById(R.id.spins);
    spins.setText(String.valueOf("SPINS: "+ totalspins));
    spin = (Button) findViewById(R.id.spin);
    s_1 = (Button) findViewById(R.id.spin_1);
    s_2 = (Button) findViewById(R.id.spin_2);
    s_3 = (Button) findViewById(R.id.spin_3);
    s_4 = (Button) findViewById(R.id.spin_4);
    s_5 = (Button) findViewById(R.id.spin_5);
    b_1 = (Button) findViewById(R.id.btn_1);
    b_2 = (Button) findViewById(R.id.btn_2);
    b_3 = (Button) findViewById(R.id.btn_3);
    b_4 = (Button) findViewById(R.id.btn_4);
    b_5 = (Button) findViewById(R.id.btn_5);

    //int randIntb1 = rand.nextInt(15)+1;
     b_1.setText(String.valueOf(b_list[0]));//randIntb1
    //int randIntb2 = rand.nextInt(15)+1;
    b_2.setText(String.valueOf(b_list[1]));//randIntb2
    //int randIntb3 = rand.nextInt(15)+1;
    b_3.setText(String.valueOf(b_list[2]));//randIntb3
    //int randIntb4 = rand.nextInt(15)+1;
    b_4.setText(String.valueOf(b_list[3]));//randIntb4
    //int randIntb5 = rand.nextInt(15)+1;
    b_5.setText(String.valueOf(b_list[4]));//randIntb5

     spin.setOnClickListener(new OnClickListener() {
        private Object Button;
        public void onClick(View v) {
            //spin.setEnabled(false);
            int randInts1 = rand.nextInt(17)+1;
            s_1.setText(String.valueOf(randInts1));
            s1=(randInts1);
            int randInts2 = rand.nextInt(17)+15;
            s_2.setText(String.valueOf(randInts2));
            s2=(randInts2);
            int randInts3 = rand.nextInt(17)+30;
            s_3.setText(String.valueOf(randInts3));
            s3=(randInts3);
            int randInts4 = rand.nextInt(17)+45;
            s_4.setText(String.valueOf(randInts4));
            s4=(randInts4);
            int randInts5 = rand.nextInt(17)+60;
            s_5.setText(String.valueOf(randInts5));
            s5=(randInts5);


            totalspins = (totalspins - 1);
            spins.setText(String.valueOf("SPINS: "+ totalspins));
            if(totalspins <= 0){
                totalspins =(15);
            }
            }

    });






    b_1.setOnClickListener(new OnClickListener() {
        private Object Button;
        public void onClick(View v){
            if (b_1.getText() == (s_1.getText())){
                gamescore =(gamescore + s1);
                score.setText(String.valueOf("SCORE: "+ gamescore));
                b_1.setText(String.valueOf(""));
                s_1.setText(String.valueOf(""));
                }
            }
    });
    b_2.setOnClickListener(new OnClickListener() {
        private Object Button;
        public void onClick(View v){
            if (b_2.getText() == (s_1.getText())){
                gamescore =(gamescore + s1);
                score.setText(String.valueOf("SCORE: "+ gamescore));
                b_2.setText(String.valueOf(""));
                s_1.setText(String.valueOf(""));
                }
            }
    });
    b_3.setOnClickListener(new OnClickListener() {
        private Object Button;
        public void onClick(View v){
            if (b_3.getText() == (s_1.getText())){
                gamescore =(gamescore + s1);
                score.setText(String.valueOf("SCORE: "+ gamescore));
                b_3.setText(String.valueOf(""));
                s_1.setText(String.valueOf(""));
                }
            }
    });
}
public类MainActivity扩展活动实现OnClickListener,
倒计时FinishedListener{
/**在首次创建活动时调用*/
//设置旋转
私有文本视图旋转;
私人按钮旋转;
专用按钮s_1;
专用按钮s_2;
专用按钮s_3;
专用按钮s_4;
专用按钮s_5;
私有静态最终随机兰德=新随机();
int totalspins=15;
int gamescore=0;
int s1=0;
int s2=0;
int s3=0;
int s4=0;
int s5=0;
int[]b_list={1,2,3,4,5,6,7,8,9,10,12,13,14,15};
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(窗口。功能\u无\u标题);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_全屏,
WindowManager.LayoutParams.FLAG(全屏);
setContentView(R.layout.play_布局);
setRequestedOrientation(ActivityInfo.SCREEN\u ORIENTATION\u Picture);
游戏分数=(0);
分数=(TextView)findViewById(R.id.score);
score.setText(String.valueOf(“score:+gamescore”);
总自旋=(15);
spins=(TextView)findViewById(R.id.spins);
setText(String.valueOf(“spins:+totalspins”);
spin=(按钮)findViewById(R.id.spin);
s_1=(按钮)findViewById(R.id.spin_1);
s_2=(按钮)findViewById(R.id.spin_2);
s_3=(按钮)findViewById(R.id.spin_3);
s_4=(按钮)findViewById(R.id.spin_4);
s_5=(按钮)findViewById(R.id.spin_5);
b_1=(按钮)findViewById(R.id.btn_1);
b_2=(按钮)findViewById(R.id.btn_2);
b_3=(按钮)findViewById(R.id.btn_3);
b_4=(按钮)findViewById(R.id.btn_4);
b_5=(按钮)findViewById(R.id.btn_5);
//int randIntb1=rand.nextInt(15)+1;
b_1.setText(String.valueOf(b_list[0]);//randIntb1
//int randIntb2=rand.nextInt(15)+1;
b_2.setText(String.valueOf(b_list[1]);//randIntb2
//int randIntb3=rand.nextInt(15)+1;
b_3.setText(String.valueOf(b_list[2]);//randIntb3
//int randIntb4=rand.nextInt(15)+1;
b_4.setText(String.valueOf(b_list[3]);//randIntb4
//int randIntb5=rand.nextInt(15)+1;
b_5.setText(String.valueOf(b_list[4]);//randIntb5
spin.setOnClickListener(新的OnClickListener(){
私有对象按钮;
公共void onClick(视图v){
//spin.setEnabled(false);
int randInts1=rand.nextInt(17)+1;
s_1.setText(String.valueOf(randInts1));
s1=(randInts1);
int randInts2=rand.nextInt(17)+15;
s_2.setText(String.valueOf(randInts2));
s2=(randInts2);
int randInts3=rand.nextInt(17)+30;
s_3.setText(String.valueOf(randInts3));
s3=(randInts3);
int randInts4=rand.nextInt(17)+45;
s_4.setText(String.valueOf(randInts4));
s4=(随机数s4);
int randInts5=兰特nextInt(17)+60;
s_5.setText(字符串值(randInts5));
s5=(randInts5);
totalspins=(totalspins-1);
setText(String.valueOf(“spins:+totalspins”);

如果(totalspins洗牌列表非常简单:

ArrayList<Integer> numbers = new ArrayList<Integer>()
for(int i = 1; i <= 15; i++) {
    numbers.add(i);
}

Collections.shuffle(numbers);
但是,将这些按钮保留在某种数据结构中可能会更好:

ArrayList<Button> buttons = new ArrayList<Button>();
//Fill list to your heart's content

Collections.shuffle(numbers);
for(int i = 0; i < buttons.length() && i < numbers.length(); i++) {
    buttons.get(i).setText(numbers.get(i).toString());
}
ArrayList按钮=新建ArrayList();
//把清单填得满满的
收藏。洗牌(数字);
对于(int i=0;i

<>编辑我忘记java列表使用GET()而不是(C++)矢量(

洗牌列表)很简单:

ArrayList<Integer> numbers = new ArrayList<Integer>()
for(int i = 1; i <= 15; i++) {
    numbers.add(i);
}

Collections.shuffle(numbers);
但是,将这些按钮保留在某种数据结构中可能会更好:

ArrayList<Button> buttons = new ArrayList<Button>();
//Fill list to your heart's content

Collections.shuffle(numbers);
for(int i = 0; i < buttons.length() && i < numbers.length(); i++) {
    buttons.get(i).setText(numbers.get(i).toString());
}
ArrayList按钮=新建ArrayList();
//把清单填得满满的
收藏。洗牌(数字);
对于(int i=0;i


<>编辑我忘记java列表使用GET()而不是C++(例如,C++向量< /P>),你是否遇到了按钮逻辑?洗牌?你尝试了什么?请给我们展示你的代码。这样的精神是帮助人们解决他们自己的问题(并且学会做)…而不是为(简单)提供盆栽解决方案。问题。你肯定应该在这里发布你的一些尝试。我想你会发现,如果人们看到你在做“老大学尝试”,他们会更倾向于提供帮助首先。呃……我们应该如何帮助你?这还不是很清楚。如果你只是想随机排列一个数组,谷歌搜索:随机数组排列。这是两行代码。你在按钮逻辑方面有问题吗?洗牌?你尝试了什么?请给我们看你的代码。所以精神就是帮助人们解决他们自己的问题(并学会去做)…而不是为(简单的)问题提供一锅解决方案。你肯定应该在这里发布你的一些尝试。我想你会发现,如果人们看到你在做“老大学尝试”,他们会更倾向于提供帮助首先。呃……我们应该如何帮助你?这还不是很清楚。如果你只是想随机排列一个数组,那就用谷歌搜索:随机数组排列。这是两行代码。科林,我已经尝试了尽可能多的形式,因为我对java是新手。它警告我整数。我的记忆力已经不好了。警告过你整数?警告是什么?我没有编译这个,所以我可能会把事情搞砸。这是我第一次看到这个。谢谢。我会试试。我相信这会有用的。你是对的。at发出了警告。再次感谢。我检查了