安卓小项目,课程设计,课设,刷题app

一、需求分析:

如今考驾照已经成为了很多人的刚需,对于科目1与科目4来说,大量的刷题必不可少。
根据市场需求,我们开发了一个可以在手机刷题的app方便人们随时随地地刷题。

二、部分代码

public class Main3Activity extends AppCompatActivity {
private Sql sql;
int jub = 1;
String ans=null;
String anal=null;
String type=null;
int id;
String topic;
String a;
String b;
String c;
String d;
String img;
boolean boo=true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
Intent getI = getIntent();
final Bundle data = getI.getExtras();
type= data.getString("data");
replace(jub);
Button btnUp = findViewById(R.id.btnUp);  //上一题按钮
btnUp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (jub>=2){
jub--;
replace(jub);
}
}
});
Button btnDown = findViewById(R.id.btnDown);  //下一题按钮
btnDown.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
jub++;
replace(jub);
RadioGroup radioGroup2 = findViewById(R.id.radioGroup2);
radioGroup2.check(-1);
}
});
Button btnCol = findViewById(R.id.btnCol);
if(!type.equals("col")){
btnCol.setText("加入错题");
}else {
btnCol.setText("删除");
//btnCol.setText(type);
}
btnCol.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(!type.equals("col")){
SQLiteDatabase db = sql.getWritableDatabase();
Cursor cursor = db.query(true, "col",null,"id = "+id,null,null,null,null,null);
if (cursor.getCount()==1){
Toast toast=Toast.makeText(getApplicationContext(), "已经加入", Toast.LENGTH_SHORT);
toast.show();
}else {
int num;
Cursor cur = db.rawQuery("select * from col", null);
num=cur.getCount();
if(cur.moveToFirst()){
int frist=cur.getInt(cur.getColumnIndex("id"));
if (frist!=1){
num=num+frist;
}else {
num++;
}
}
if (num==0)num++;
ContentValues contentValues = new ContentValues();
contentValues.put("id",num);
contentValues.put("type",type);
contentValues.put("topic",topic);
contentValues.put("a",a);
contentValues.put("b",b);
contentValues.put("c",c);
contentValues.put("d",d);
contentValues.put("answer",ans);
contentValues.put("analyse",anal);
contentValues.put("img",img);
db.insert("col",null,contentValues);
Toast toast=Toast.makeText(getApplicationContext(), "加入成功", Toast.LENGTH_SHORT);
toast.show();
}
}else {
SQLiteDatabase db = sql.getWritableDatabase();
Cursor cursor = db.query(true, type,null,"id = "+id,null,null,null,null,null);
if (cursor.getCount()==1){
db.delete("col","id=?",new String[]{String.valueOf(id)});
Toast toast=Toast.makeText(getApplicationContext(), "删除成功", Toast.LENGTH_SHORT);
toast.show();
}else {
Toast toast=Toast.makeText(getApplicationContext(), "已经删除", Toast.LENGTH_SHORT);
toast.show();
}
}
}
});

三、相关截图

源码请+q:2538966470

本文地址:https://blog.csdn.net/weixin_45702159/article/details/107877828

(0)
上一篇 2022年3月21日
下一篇 2022年3月21日

相关推荐