android之问卷

老师上课演示了一个循环答题系统,一时技痒也想试下。所以也写了一遍。

但是有点缺陷就是我忘记了老师上课时如何实现问题的数组存储的了。

所以我就用一个String数组实现了,最终也是实现了效果的,但是和老师的相比还是很有差距。

继续加油吧!

先附上截图吧。

下载地址:http://ddl.escience.cn/pan/download?path=%2Fandroid%E5%B0%8F%E9%A1%B9%E7%9B%AE%2Fwenjuan.apk&version=0

附上代码:

 <TextView
android:id="@+id/question"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:gravity="center"
android:textSize="30dp"
android:hint="你准备好答题了吗?" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
>
<Button
android:id="@+id/true_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/true_button"
android:layout_marginLeft="100dp"
android:textSize="20dp"
/>
<Button
android:id="@+id/false_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:text="@string/false_button"/>


</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<Button
android:id="@+id/last_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/last_button"
android:textSize="20dp"
android:layout_marginLeft="30dp"
/>
<Button
android:id="@+id/next_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/next_button"
android:layout_weight="1"
android:layout_marginRight="30dp"
android:textSize="20dp"
/>



</LinearLayout>




public class MainActivity extends AppCompatActivity {
private TextView question;
private Button true_button;
private Button false_button;
private Button last_button;
private Button next_button;
private String mquestion[]={"湖北是中国的吗?","武汉是湖北的吗?","华农是武汉的吗?"};
private int flag=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
question=(TextView)findViewById(R.id.question);
true_button=(Button)findViewById(R.id.true_button);
false_button=(Button)findViewById(R.id.false_button);
last_button=(Button)findViewById(R.id.last_button);
next_button=(Button)findViewById(R.id.next_button);
//按下是
true_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast toast=Toast.makeText(getApplicationContext(),"恭喜答对!",Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER,0,0);
toast.show();
}
});
false_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast toast=Toast.makeText(getApplicationContext(),"再想想!!",Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER,0,0);
toast.show();
}
});
//按下一题
next_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
question.setText(mquestion[flag]);
flag=(flag+1)%(mquestion.length);
}
});
//按下上一题
last_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
question.setText(mquestion[flag]);
flag=(flag+mquestion.length-1)%(mquestion.length);
}
});
}
}

 

posted @ 2017-03-16 16:09  爱编程的文科生  阅读(377)  评论(0编辑  收藏  举报