0

私はキッズ ゲームをやっています。それは IQ キッズ テストであり、10 個のアクティビティに質問があります。ユーザーが質問を開始するとランダムに 10 個中 1 個が呼び出され、ユーザーが [次の質問] を押すと 9 個のアクティビティのうち 1 個が呼び出されます。残りの 8 つのアクティビティのうちの 1 つを呼び出します。

どうやってやるの?

よろしくお願いします、

4

4 に答える 4

0

3 つのアクティビティに対して 1 つのデモを作成しました。最大 50 のアクティビティをカスタマイズできます。

activity_main.xml

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="main" />

<Button
    android:id="@+id/btn_next"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:text="Next" />

<Button
    android:id="@+id/btn_random"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView1"
    android:layout_below="@+id/textView1"
    android:layout_marginLeft="29dp"
    android:layout_marginTop="70dp"
    android:text="Random" />

one.xml

 <TextView
     android:id="@+id/btn_random"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignParentLeft="true"
     android:layout_alignParentTop="true"
     android:layout_marginLeft="74dp"
     android:layout_marginTop="26dp"
     android:text="One" />

two.xml

<TextView

     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignParentLeft="true"
     android:layout_alignParentTop="true"
     android:layout_marginLeft="74dp"
     android:layout_marginTop="26dp"
     android:text="Two" />
 <Button
     android:id="@+id/btn_random"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignParentBottom="true"
     android:layout_alignParentRight="true"
     android:text="Next" />

three.xml

     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignParentLeft="true"
     android:layout_alignParentTop="true"
     android:layout_marginLeft="74dp"
     android:layout_marginTop="26dp"
     android:text="Three" />

 <Button 
     android:id="@+id/btn_random"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Next" />

MainActivity.java

public class MainActivity extends Activity implements OnClickListener {
    public static List<Integer> numberList =new ArrayList<Integer>();
    private Button btn_Random,btn_Next;
    public static int countNext=0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // set resources
        btn_Random =(Button) findViewById(R.id.btn_random);
        btn_Next =(Button) findViewById(R.id.btn_next);
        btn_Random.setOnClickListener(this);


        btn_Next.setOnClickListener(this);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.btn_random:

            findRandom();

            break;
        case R.id.btn_next:
            countNext=0;

            System.out.println("first value of array:"+numberList.get(countNext));
            if(numberList.get(countNext)==1){
                countNext++;
                startActivity(new Intent(MainActivity.this,OneActivity.class));
            }else if (numberList.get(countNext) == 2) {
                countNext++;
                startActivity(new Intent(MainActivity.this,TwoActivity.class));
            }else if (numberList.get(countNext) ==3) {
                countNext++;
                startActivity(new Intent(MainActivity.this,ThreeActivity.class));           
            }




            break;
        default:
            break;
        }

    }

    private void findRandom() {
        numberList.clear();
        for(int i=0;i<3;i++){
            numberList.add(i+1);
        }

        long seed = System.nanoTime();
        Collections.shuffle(numberList, new Random(seed));
        Collections.shuffle(numberList, new Random(seed));


        for (int no : numberList) {
            System.out.println("random number:"+no);
        }

    }

}

OneActivity.java

package com.project.ques;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class OneActivity extends Activity implements OnClickListener{
    public static List<Integer> numberList =new ArrayList<Integer>();
    private Button btn_Random;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.one);
        // set resources
        btn_Random =(Button) findViewById(R.id.btn_random);

        btn_Random.setOnClickListener(this);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.btn_random:

            System.out.println("first value of array:"+MainActivity.numberList.get(MainActivity.countNext));
            if(MainActivity.numberList.get(MainActivity.countNext)==1){
                MainActivity.countNext++;
                startActivity(new Intent(OneActivity.this,OneActivity.class));
            }else if (MainActivity.numberList.get(MainActivity.countNext) == 2) {
                MainActivity.countNext++;
                startActivity(new Intent(OneActivity.this,TwoActivity.class));
            }else if (MainActivity.numberList.get(MainActivity.countNext) ==3) {
                MainActivity.countNext++;
                startActivity(new Intent(OneActivity.this,ThreeActivity.class));            
            }



            break;

        default:
            break;
        }

    }



}

TwoActivity.java

package com.project.ques;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class TwoActivity extends Activity implements OnClickListener{

    private Button btn_Random;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.two);
        // set resources
        btn_Random =(Button) findViewById(R.id.btn_random);

        btn_Random.setOnClickListener(this);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.btn_random:


            System.out.println("first value of array:"+MainActivity.numberList.get(MainActivity.countNext));
            if(MainActivity.numberList.get(MainActivity.countNext)==1){
                MainActivity.countNext++;
                startActivity(new Intent(TwoActivity.this,OneActivity.class));
            }else if (MainActivity.numberList.get(MainActivity.countNext) == 2) {
                MainActivity.countNext++;
                startActivity(new Intent(TwoActivity.this,TwoActivity.class));
            }else if (MainActivity.numberList.get(MainActivity.countNext) ==3) {
                MainActivity.countNext++;
                startActivity(new Intent(TwoActivity.this,ThreeActivity.class));            
            }



            break;

        default:
            break;
        }

    }



}

ThreeActivity.java

package com.project.ques;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class ThreeActivity extends Activity implements OnClickListener{

    private Button btn_Random;
    public static int countNext=1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.three);
        // set resources
        btn_Random =(Button) findViewById(R.id.btn_random);

        btn_Random.setOnClickListener(this);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.btn_random:


            System.out.println("first value of array:"+MainActivity.numberList.get(countNext));
            if(MainActivity.numberList.get(countNext)==1){
                MainActivity.countNext++;
                startActivity(new Intent(ThreeActivity.this,OneActivity.class));
            }else if (MainActivity.numberList.get(countNext) == 2) {
                MainActivity.countNext++;
                startActivity(new Intent(ThreeActivity.this,TwoActivity.class));
            }else if (MainActivity.numberList.get(countNext) ==3) {
                MainActivity.countNext++;
                startActivity(new Intent(ThreeActivity.this,ThreeActivity.class));          
            }

            countNext++;
            break;

        default:
            break;
        }

    }



}

AndroidManifest.xml

<uses-sdk
    android:minSdkVersion="10"
    android:targetSdkVersion="17" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.project.ques.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name="OneActivity"></activity>
    <activity android:name="TwoActivity"></activity>
    <activity android:name="ThreeActivity"></activity>
</application>

于 2013-05-17T11:38:36.473 に答える