私はアンドロイドが初めてなので、何かひどく間違っているかもしれません。ゲームの「クリーチャー」クラスのインスタンスに関する詳細を示す特定のアクティビティが必要です。名前、受けたダメージ、とか。
クリーチャー データを GUI オブジェクトに正しく表示するのに問題があります。最初の作成時 (クリーチャーの名前を名前フィールドにコピーする必要がある場所) と、ダメージ マークが追加されたとき (適切な画像を表示するために更新されない場所) の両方。
これが私が持っているものの私のミニ例です:
public class CreatureDetailActivity2 extends Activity
{
Creature creature;
public void addMark(View v)
{
// connected to the button via android:onClick="addMark" in the XML
creature.getTrack().addDamage(DamageType.Normal, 1);
refreshDisplay();
new AlertDialog.Builder(this).setTitle(creature.getName())
.setMessage(creature.getTrack().toString()).show();
}
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_creature_detail);
creature = new Creature("Example");
refreshDisplay();
}
public void refreshDisplay()
{
final View creatureDetailView = this.getLayoutInflater().inflate(
R.layout.activity_creature_detail, null);
final EditText nameField = (EditText) (creatureDetailView
.findViewById(R.id.textbox_creature_name));
nameField.setText(creature.getName());
final ImageView damageBox0 = (ImageView) (creatureDetailView.findViewById(R.id.damageBox0));
damageBox0.setImageResource(R.drawable.__n);
// in the full program this does the same for 0 through 9, but this is a sample
// also, in the full program, this is a dynamic lookup for the correct pic
// but again, this is just a sample version.
}
}
ここでの問題は、アプリがロードされて起動することですが、その後、どのウィジェットも適切に更新されません。ボタンをクリックすると、AlertDialog が表示され、AlertDialog のテキストが変更されますが、アクティビティのテキスト フィールドは変更されず、ImageView は最初の時点から変更されません。変更することになっているものに。
だから私はとても困惑しています。重要なことを省略している場合は、プロジェクトのセットアップについてさらに投稿できますが、何が問題なのかさえわからないため、質問に他に何を含めればよいかわかりません。