ビューとレイアウトについて学ぶための正しい方向を指摘された後、私はかなり見栄えが良いと思った電卓を作れました。エレガントではない非常に基本的なコードをいくつか追加しましたが、シンプルなアプリケーションを作ることで私の偉業を濡らしたいと思っていました。これまでのところ、プロセスは停止しており、再試行するとしか書かれていません。私はそれが私のコードであり、これを実現する私のUIではないと100%肯定的です。私は1つのボタンで基本的なボタンカウンターを作ることができましたが、今は15個のボタンがあります。ここでプロセスが停止しました。 Android calculator trouples
はhellocats呼ば電卓のコードです(私は基本的なチュートリアル以下だったとの追加に保管)
package com.hellocats;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
public class hellokatz extends Activity {
/** Called when the activity is first created. */
int numbermover = 0;
int[] numbers ={0,0};
String sign = "+";
int answer;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button button0 = (Button)findViewById(R.id.button0);
final Button button1 = (Button)findViewById(R.id.button1);
final Button button2 = (Button)findViewById(R.id.button2);
final Button button3 = (Button)findViewById(R.id.button3);
final Button button4 = (Button)findViewById(R.id.button4);
final Button button5 = (Button)findViewById(R.id.button5);
final Button button6 = (Button)findViewById(R.id.button6);
final Button button7 = (Button)findViewById(R.id.button7);
final Button button8 = (Button)findViewById(R.id.button8);
final Button button9 = (Button)findViewById(R.id.button9);
final Button addbutton = (Button)findViewById(R.id.buttonadd);
final Button subbutton = (Button)findViewById(R.id.buttonsub);
final Button mulbutton = (Button)findViewById(R.id.buttonmul);
final Button divbutton = (Button)findViewById(R.id.buttondiv);
final Button equalsbutton = (Button)findViewById(R.id.buttonequals);
final EditText num1 = (EditText)findViewById(R.id.num1);
final EditText mysign = (EditText)findViewById(R.id.sign);
final EditText num2 = (EditText)findViewById(R.id.num2);
final EditText answer = (EditText)findViewById(R.id.answer);
num1.setText(numbers[0]);
num2.setText(numbers[1]);
mysign.setText(sign);
button0.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
numbers[numbermover] = 0;
}
});
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
numbers[numbermover] = 1;
}
});
button2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
numbers[numbermover] = 2;
}
});
button3.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
numbers[numbermover] = 3;
}
});
button4.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
numbers[numbermover] = 4;
}
});
button5.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
numbers[numbermover] = 5;
}
});
button6.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
numbers[numbermover] = 6;
}
});
button7.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
numbers[numbermover] = 7;
}
});
button8.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
numbers[numbermover] = 8;
}
});
button9.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
numbers[numbermover] = 9;
}
});
}
}
ここでレイアウトファイルmain.xmlは私がやったこと
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<TableRow android:id="@+id/tableRow1" android:layout_height="wrap_content" android:layout_width="match_parent">
<Button android:text=" 1 " android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text=" 2 " android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text=" 3 " android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text=" 4 " android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text=" 5 " android:id="@+id/button5" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text=" 6 " android:id="@+id/button6" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text=" 7 " android:id="@+id/button7" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</TableRow>
<TableRow android:id="@+id/tableRow2" android:layout_height="wrap_content" android:layout_width="match_parent">
<Button android:text=" 8 " android:id="@+id/button8" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text=" 9 " android:id="@+id/button9" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text=" 0 " android:id="@+id/button0" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</TableRow>
<TableRow android:id="@+id/tableRow3" android:layout_height="wrap_content" android:layout_width="match_parent">
<Button android:text=" + " android:id="@+id/buttonadd" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text=" - " android:id="@+id/buttonsub" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text=" X " android:id="@+id/buttonmul" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text="/ " android:id="@+id/buttondiv" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text=" = " android:id="@+id/buttonequals" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</TableRow>
<TableRow android:id="@+id/tableRow4" android:layout_height="wrap_content" android:layout_width="match_parent">
<EditText android:text=" " android:id="@+id/num1" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
<EditText android:text=" " android:id="@+id/sign" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
<EditText android:text=" " android:id="@+id/num2" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
<EditText android:text=" = " android:id="@+id/equals" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
<EditText android:text=" " android:id="@+id/answer" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
</TableRow>
</LinearLayout>
です私のJavaファイルで間違ってやり直して、それを修正してそれから学ぶことができますか?
ありがとうございます:私はあなたのウェブサイトにはとても慣れていて、これまでのところ私の人生の中でmain.xmlファイルを投稿する方法を理解できません。私はCTRL + KとCTRL + Vを試してみましたが、これまで何もしていませんでした。
チェック(これらの行は、彼らはプロセスが停止した理由についての情報を与え、スタックトレースです) – bigstones
も、コードをフォーマットするためにあなたがそれを選択する必要があります(すべての行がコードブロックならば)、エディタの上部にある '{}'ボタンをクリックします。 – bigstones
DDMS/Logcatログを投稿できますか?なぜ、 'TableLayout'を使わずに' LinearLayout'で直接 'TableRow'を使うのですか? – GrAnd