0

こんにちは、スタック オーバーフローです。

私は子供向けのAndroidアプリケーションに取り組んでいます:各アクティビティは質問です。問題ごとに、ヒントと答えの 2 つのボタンがあります。2 つの問題が発生します: 1/ アクティビティを変更する前にボタンをクリックする必要があります。2/ このアクティビティ (コードは以下) で、id "essai" のボタンをクリックすると、アクティビティが停止し、前のアクティビティに戻りました..これを修正する方法を知っている人はいますか? 前もって感謝します !

ここにJavaコードがあります

 package com.beryl.timewaster;

  import android.os.Bundle;
  import android.app.Activity;
  import android.content.Intent;
  import android.view.View;
  import android.view.View.OnClickListener;
   import android.widget.ImageButton;
  import android.widget.Toast;

   public class Activity1 extends Activity {

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_activity1);
}

public void indice1(View v)
{
    Toast.makeText(this, "expression", Toast.LENGTH_LONG).show();
}

public void indice2(View v)
{
    Toast.makeText(this, "aguéri", Toast.LENGTH_LONG).show();
}

public void essai(View v)
{
    Toast.makeText(this, "LOLILO", Toast.LENGTH_LONG).show();

    final ImageButton ib2 = (ImageButton) findViewById(R.id.flechegauche1);
  ib2.setOnClickListener(new OnClickListener() {

  @Override
  public void onClick(View v) {
    Intent intent = new Intent(Activity1.this, Accueil.class);
    startActivity(intent);
    }

    });
          }}

そしてここでxml

   <AbsoluteLayout
    android:id="@+id/absoluteLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true" >

    <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="xxx"
        ads:loadAdOnCreate="true"
        ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" >
    </com.google.ads.AdView>

   <TextView
   android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="42dp"
        android:layout_x="-1dp"
        android:layout_y="61dp"
        android:text="@string/dev2"
        android:textColor="@color/blanc"
        android:textSize="25sp"
        android:color="@color/blanc" />

  <Button
        android:id="@+id/Solution2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_x="0dp"
        android:layout_y="259dp"
        android:onClick="essai"
        android:text="@string/solution"
        android:textColor="@color/vertpomme"
        android:textSize="30sp" />

   <Button
     android:id="@+id/indice1de2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_x="1dp"
        android:layout_y="121dp"
        android:onClick="indice1"
        android:text="@string/indice1"
        android:textColor="@color/orange"
        android:textSize="30sp" />

   <Button
        android:id="@+id/indice2de2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_x="0dp"
        android:layout_y="190dp"
        android:onClick="indice2"
        android:text="@string/indice2"
        android:textColor="@color/rouge"
        android:textSize="30sp" />>

        <ImageButton
        android:id="@+id/flechedroite2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="196dp"
        android:layout_y="338dp"
        android:src="@drawable/flechedroite" />

    <ImageButton
        android:id="@+id/flechegauche2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="33dp"
        android:layout_y="339dp"
        android:src="@drawable/flechegauche" />

    </AbsoluteLayout>

  </RelativeLayout>
4

1 に答える 1

0

に変更final ImageButton ib2 = (ImageButton) findViewById(R.id.flechegauche1);final ImageButton ib2 = (ImageButton) findViewById(R.id.flechegauche2);ます。android:id="@+id/flechegauche1"xmlで宣言していません

于 2013-11-09T13:41:50.317 に答える