精華區beta java 關於我們 聯絡資訊
請各位大大幫我分析一下這個程式可以嗎?! 我主要是做九宮格 中間數字可以上下左右移動 然後下面是我的程式碼 往上的部分沒問題 但往下的部分有問題 我也找到錯誤 但是我不知道為什麼錯 arr[i+1][j]=1; 請大大們求解~~~~ 然後我滿想問的多TextView要怎麼設成陣列使用 我有找過listview!但是我的view有照順序排! 我有用過!他會變成直視顯示.... public class MainActivity extends ActionBarActivity { public TextView tv1; public TextView tv2; public TextView tv3; public TextView tv4; public TextView tv5; public TextView tv6; public TextView tv7; public TextView tv8; public TextView tv9; private Button up; private Button down; private Button left; private Button right; int i,j; int [][]arr= new int [3][3]; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); up = (Button)findViewById(R.id.button1); down = (Button)findViewById(R.id.button2); left = (Button)findViewById(R.id.button3); right = (Button)findViewById(R.id.button4); tv1 = (TextView)findViewById(R.id.textView1); tv2 = (TextView)findViewById(R.id.textView2); tv3 = (TextView)findViewById(R.id.textView3); tv4 = (TextView)findViewById(R.id.textView4); tv5 = (TextView)findViewById(R.id.textView5); tv6 = (TextView)findViewById(R.id.textView6); tv7 = (TextView)findViewById(R.id.textView7); tv8 = (TextView)findViewById(R.id.textView8); tv9 = (TextView)findViewById(R.id.textView9); up.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { for(i=0;i<3;i++){ for(j=0;j<3;j++){ if(arr[i][j]==1){ if(arr[1][0]==1){ tv1.setText("L"); tv4.setText("0"); } if(arr[1][1]==1){ tv2.setText("L"); tv5.setText("0"); } if(arr[1][2]==1){ tv3.setText("L"); tv6.setText("0"); } if(arr[2][0]==1){ tv4.setText("L"); tv7.setText("0"); } if(arr[2][1]==1){ tv5.setText("L"); tv8.setText("0"); } if(arr[2][2]==1){ tv6.setText("L"); tv9.setText("0"); } arr[i][j]=0; arr[i-1][j]=1; } } } } }); down.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { for(i=0;i<3;i++){ for(j=0;j<3;j++){ if(arr[i][j]==1){ arr[i][j]=0; arr[i+1][j]=1; if(arr[0][1]==1){ tv2.setText("0"); tv5.setText("L"); } } } } } }); -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.134.234.121 ※ 文章網址: http://www.ptt.cc/bbs/java/M.1398718543.A.C80.html
often897:補點註解? 04/29 07:39
pttnews:你不知道有專版嗎? 04/29 09:18