我正试图按顺序进入第三个活动.从主要活动到第二个活动工作正常,但是当我尝试从第二个活动转到第三个活动时,应用程序崩溃了.
这是我的第二个活动的代码:
package com.example.helloandroid;
import android.app.Activity;
//other imports here
public class Game extends Activity implements OnClickListener {
private static final String TAG = "Matrix";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.matrix);
View doneButton = findViewById(R.id.done_button);
doneButton.setOnClickListener(this);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.done_button:
Intent k = new Intent(this, GameTwo.class);
startActivity(k);
//finish();
break;
}
}
}
Run Code Online (Sandbox Code Playgroud)
以及第三项活动的代码:
package com.example.helloandroid;
import android.app.Activity;
//other imports here
public class GameTwo extends Activity {
private static final String TAG = …
Run Code Online (Sandbox Code Playgroud) 在应用程序的java部分创建EditText时,如何将其限制为与xml中的数字相同?例如:
new EditText(this);
Run Code Online (Sandbox Code Playgroud)
设置像
<EditText
android:id="@+id/h1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"/>
Run Code Online (Sandbox Code Playgroud) 目前我的代码将用户输入放入一维ArrayList中,但我想将它们放入二维ArrayList中并遇到一些麻烦.
这是我的代码:
public class Game extends Activity implements OnClickListener {
private static final String TAG = "Matrix";
static ArrayList<EditText> columnEditTexts;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.matrix);
View doneButton = findViewById(R.id.done_button);
doneButton.setOnClickListener(this);
columnEditTexts = new ArrayList<EditText>();
for(int i = 0; i < MatrixMultiply.h1; i++){
TableLayout table = (TableLayout)findViewById(R.id.myTableLayout);
TableRow row = new TableRow(this);
EditText column = new EditText(this);
for(int j = 0; j < MatrixMultiply.w1; j++){
table = (TableLayout)findViewById(R.id.myTableLayout);
column = new EditText(this);
column.setId(i);
row.addView(column);
columnEditTexts.add(column);
}
table.addView(row);
} …
Run Code Online (Sandbox Code Playgroud) 我试图使用if语句将变量限制在零以上,并且以下代码只是运行,好像if语句不存在:
private void startGame(int h1, int h2, int w1, int w2) {
this.h1 = h1;
this.w1 = w1;
this.h2 = h2;
this.w2 = w2;
Intent intent = new Intent(this, Game.class);
if((h1 > 0) || (w1 > 0) || (h2 > 0) || (w2 > 0)){
startActivity(intent);
}
else {
finish();
}
}
Run Code Online (Sandbox Code Playgroud)