zoukankan      html  css  js  c++  java
  • 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);
    }
    });
    }
    }
  • 相关阅读:
    C# 控制反转
    控制反转和依赖注入
    C#中使用AOP
    jquery ajax
    python(7)- 小程序练习:循环语句for,while实现99乘法表
    007所谓性格与条件并不是成功的阻碍,懦弱才是
    006学习有可能速成吗
    005自学与有人带着哄着逼着学的不同在于自学是一种成熟的自律
    005单打独斗意味着需要更好地管理自己
    004真正的教育是自我教育,真正的学习是自学
  • 原文地址:https://www.cnblogs.com/fyz666/p/6560036.html
Copyright © 2011-2022 走看看