android中每个练习的活动

android中每个练习的活动,android,android-activity,Android,Android Activity,我正在为android中的孩子们创建一个数学应用程序。。在我的应用程序中,有询问问题的活动(Image,任何数字,如1、2、3等)和Image按钮中的三个选项([1]、[2]、[3]等等),每个按钮按下后也会发出声音。对于每个问题,我都创建了一个活动 这是为每个问题创建活动的好方法吗?我想随便问一个问题,我该怎么办,请帮帮我 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://

我正在为android中的孩子们创建一个数学应用程序。。在我的应用程序中,有询问问题的活动(
Image
,任何数字,如1、2、3等)和
Image按钮中的三个选项([1]、[2]、[3]等等),每个按钮按下后也会发出声音。对于每个问题,我都创建了一个活动

这是为每个问题创建活动的好方法吗?我想随便问一个问题,我该怎么办,请帮帮我

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:layout_centerHorizontal="true"
    tools:context="com.example.app.kids.kidsmaths.ExerciseSeven"
   android:background="@drawable/bgn">


    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/ivsz"
        android:src="@drawable/seven"
        android:layout_gravity="center"
        android:scaleType="fitCenter"
        android:layout_marginTop="49dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentEnd="true"
        android:layout_marginEnd="153dp" />

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/ib71"
        android:background="@drawable/six2"
        android:src="@drawable/answer_click_wrong"
        android:layout_below="@+id/ib73"
        android:layout_alignStart="@+id/ib73" />

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/ib72"
        android:src="@drawable/answer_click_wrong"
        android:background="@drawable/two2"
        android:layout_below="@+id/ivsz"
        android:layout_centerHorizontal="true" />

    <ImageButton

        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/ib73"
        android:background="@drawable/seven2"
        android:src="@drawable/answer_click_correct"
        android:layout_below="@+id/ib72"
        android:layout_alignStart="@+id/ib72" />

</RelativeLayout>

实际上这是一个非常糟糕的方法。。您只需要创建一个活动,并通过如下意图将变量传递给它:

Intent intent = new Intent(this, QuestionActivity.class);
// question is a custom object that implements Serializable
// if you don't wanna create custom class you can just pass your variables as Strings or so..
intent.putExtra("question", question);
startActivity(intent);
并在活动的onCreate中获得:

Question question = (Question) getIntent().getExtras().get("question");

然后将视图设置为具有问题的值实际上这是一种非常糟糕的方法。。您只需要创建一个活动,并通过如下意图将变量传递给它:

Intent intent = new Intent(this, QuestionActivity.class);
// question is a custom object that implements Serializable
// if you don't wanna create custom class you can just pass your variables as Strings or so..
intent.putExtra("question", question);
startActivity(intent);
并在活动的onCreate中获得:

Question question = (Question) getIntent().getExtras().get("question");

然后设置视图,使其具有问题的值。

活动是一个沉重的对象。您绝对不应该将活动用于问题,因为加载大量活动会使您的应用程序内存不足。 相反,您可以使用ViewPager显示问题。如何使用幻灯片的viewpager可在此处找到

您可以在这里找到最适合您需要的解决方案


活动是一个沉重的物体,你绝对不应该使用活动来提问,因为加载大量活动会使你的应用程序内存不足。 相反,您可以使用ViewPager显示问题。如何使用幻灯片的viewpager可在此处找到

您可以在这里找到最适合您需要的解决方案


所有问题“显示”是否完全相同?如果是,则只需执行一个活动并用新数据重新加载视图,您是否可以更具体地说明应用程序的要求?按钮是否重定向到问题或练习?最好使用viewpager并使用动态小部件。很容易所有的问题看起来都完全一样吗?如果是,则只需执行一个活动并用新数据重新加载视图,您是否可以更具体地说明应用程序的要求?按钮是否重定向到问题或练习?最好使用viewpager并使用动态小部件。这很容易