基本上我已经制作了一个应用程序,它是一个测验类型的应用程序。在每个活动1出现单个问题。由于我使用ViewPager
适配器并且以单选按钮的形式选择答案,因此我无法在数据库中存储所有问题的答案。请告诉我如何为这个应用程序建立一个数据库以及如何存储多个问题。
这是我的fragment.xml
。
我要为每个问题显示38个类似的片段。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.android.viewpager1.Layout_ Fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Question 1"
android:textSize="@dimen/activity_horizontal_margin"
android:textStyle="bold"
android:layout_marginLeft="@dimen/activity_horizontal_margin"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Face"
android:textSize="@dimen/activity_horizontal_margin"
android:textStyle="bold"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
/>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioGroup">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Small forehead"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:id="@+id/radioButton1"
android:onClick="onRadioButtonClicked"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Copper coloured with plenty of pimples"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:id="@+id/radioButton2"
android:onClick="onRadioButtonClicked"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Attractive good looking"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:id="@+id/radioButton3"
android:onClick="onRadioButtonClicked"/>
</RadioGroup>
</LinearLayout>
这是我的fragment.java
课程。
同样地,我有38个碎片
public class Fragment1 extends Fragment
{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (container == null) {
return null;
}
return (LinearLayout) inflater.inflate(R.layout.fragment1_layout, container, false);
}
}
这是我的mainactivity.java
public class MainActivity extends FragmentActivity
{
private PagerAdapter mPagerAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.viewpager_layout);
initialisePaging();
}
private void initialisePaging()
{
List<Fragment> fragments =new Vector<Fragment>();
fragments.add(Fragment.instantiate(this,Fragment1.class.getName()));
fragments.add(Fragment.instantiate(this, Fragment2.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment3.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment4.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment5.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment6.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment7.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment8.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment9.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment10.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment11.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment12.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment13.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment14.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment15.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment16.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment17.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment18.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment19.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment20.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment21.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment22.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment23.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment24.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment25.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment26.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment27.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment28.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment29.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment30.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment31.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment32.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment33.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment34.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment35.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment36.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment37.class.getName()));
fragments.add(Fragment.instantiate(this,Fragment38.class.getName()));
mPagerAdapter = new com.example.android.viewpager1.PagerAdapter(this.getSupportFragmentManager(),fragments);
ViewPager pager =(ViewPager)findViewById(R.id.viewpager);
pager.setAdapter(mPagerAdapter);
}
现在任何人都可以告诉我在mainactivity.java
中应该做出哪些更改,以使Sqlite数据库存储所有38个问题的单选按钮的值,并告诉我应该在数据库中创建哪些列和表。< / p>