主頁 > 軟體設計 > 我需要在測驗應用程式android中隱藏一個單選按鈕

我需要在測驗應用程式android中隱藏一個單選按鈕

2022-01-09 04:06:03 軟體設計

我想就我的 android 代碼尋求一些幫助。我正在嘗試使用 SQLite 開發一個測驗應用程式。可能的答案數量不同,所以如果答案是 3 而不是 4,我需要從主螢屏隱藏單選按鈕(默認情況下,4 是單選按鈕的數量)。嘗試使用:

if (DataContract.QuestionTable.COLUMN_ANSWER4.isEmpty ()){ radioButton4.setVisibility (View.INVISIBLE); }

但似乎不起作用。我是 android 編程新手,這是我的第一個專案,所以每條評論都會很有幫助。謝謝你。

這是我的代碼的一部分:

測驗活動的xml

`<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout                   
 xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#C8ECF1"
android:backgroundTint="#C2ECF1"
android:backgroundTintMode="src_atop"
android:fadingEdge="horizontal"
tools:context=".QuestionsAct">

<TextView
    android:id="@ id/tvQuestionCount"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="5dp"
    android:layout_marginTop="5dp"
    android:text="question 1/x"
    android:textAlignment="center"
    android:textStyle="bold"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:id="@ id/tVTime"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="16dp"
    android:text="30:00"
    android:textSize="20sp"
    android:textStyle="bold"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<RadioGroup
    android:id="@ id/radioGroup"
    android:layout_width="356dp"
    android:layout_height="202dp"
    android:layout_marginBottom="40dp"
    app:layout_constraintBottom_toTopOf="@ id/butConfirmAns"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.29"
    app:layout_constraintStart_toStartOf="parent">

    <RadioButton
        android:id="@ id/radioButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="24dp"
        android:hint="answear1"
        android:textAlignment="viewStart"
        android:textStyle="bold" />

    <RadioButton
        android:id="@ id/radioButton2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="24dp"
        android:hint="answer2"
        android:textAlignment="viewStart"
        android:textStyle="bold" />

    <RadioButton
        android:id="@ id/radioButton3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="24dp"
        android:hint="answer3"
        android:textAlignment="viewStart"
        android:textStyle="bold" />

    <RadioButton
        android:id="@ id/radioButton4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="24dp"
        android:textAlignment="viewStart"
        android:textStyle="bold"

        />

</RadioGroup>

<TextView
    android:id="@ id/tVQuestion"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="5dp"
    android:text="Question bla bla "
    android:textSize="20sp"
    app:layout_constraintBottom_toTopOf="@ id/radioGroup"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@ id/tvImgQuest"
    app:layout_constraintVertical_bias="0.139" />

<Button
    android:id="@ id/butConfirmAns"
    android:layout_width="wrap_content"
    android:layout_height="35dp"
    android:layout_marginStart="15dp"
    android:layout_marginBottom="36dp"
    android:background="#FF9800"
    android:text="Submit"
    android:textColor="#009688"
    android:textSize="12sp"
    android:textStyle="bold"
    app:iconTint="#DA9E45"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toEndOf="@ id/butBack"
    app:strokeColor="#8BC34A" />

<ImageView
    android:id="@ id/tvImgQuest"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
    android:visibility="visible"

    app:layout_constraintBottom_toTopOf="@ id/radioGroup"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.498"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.176"
    app:srcCompat="@drawable/ic_launcher_background" />

<Button
    android:id="@ id/butBack"
    android:layout_width="61dp"
    android:layout_height="33dp"
    android:layout_marginStart="4dp"
    android:layout_marginBottom="36dp"
    android:textSize="12sp"
    app:icon="@android:drawable/ic_media_rew"
    app:iconTint="#2196F3"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent" />

<Button
    android:id="@ id/butForw"
    android:layout_width="61dp"
    android:layout_height="35dp"
    android:layout_marginStart="15dp"
    android:layout_marginBottom="36dp"
    android:textSize="12sp"
    android:textStyle="bold"
    app:icon="@android:drawable/ic_media_ff"
    app:iconTint="#2196F3"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toEndOf="@ id/butConfirmAns" />

<Button
    android:id="@ id/butFinish"
    android:layout_width="85dp"
    android:layout_height="35dp"
    android:layout_marginStart="30dp"
    android:layout_marginEnd="10dp"
    android:layout_marginBottom="36dp"
    android:text="Finish"
    android:textAlignment="center"
    android:textColor="#F44336"
    android:textSize="10sp"
    android:textStyle="bold"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="1.0"
    app:layout_constraintStart_toEndOf="@ id/butForw" />

<TextView
    android:id="@ id/tvScore"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="4dp"
    android:layout_marginTop="28dp"
    android:text="Score: 0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@ id/tvQuestionCount" />

   </androidx.constraintlayout.widget.ConstraintLayout>`

資料庫表

 `package com.anna.myquiz;
  import android.provider.BaseColumns;
  public final class DataContract {
  private  DataContract(){}
  public static class StudentTable implements BaseColumns {

    public static final String TABLE_NAME1 = "student_info";
    public static final String COLUMN_ID = "id";
    public static final String COLUMN_AM = "studentAm";
    public static final String COLUMN_NAME = "name";
    public static final String COLUMN_SEMESTER = "semester";
    public static final String COLUMN_SCORE = "score";
    public static final String COLUMN_DATE = "studentDate";
}
public static class QuestionTable implements BaseColumns {
    public static final String TABLE_NAME = "quiz_question";
    public static final String COLUMN_QUESTION = "question";
    public static final String COLUMN_IMAGE = "image";
    public static final String COLUMN_ANSWER1 = "answer1";
    public static final String COLUMN_ANSWER2 = "answer2";
    public static final String COLUMN_ANSWER3 = "answer3";
    public static final String COLUMN_ANSWER4 = "answer4";
    public static final String COLUMN_ANSWERNUM = "answerNum";

}
}`

資料庫 SQLiteHelper

`package com.anna.myquiz;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.view.View;

import com.anna.myquiz.DataContract.*;
import java.util.ArrayList;
import java.util.List;

public class DataDbHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "Quiz.db";
private static final int DATABASE_VERSION = 1;
private SQLiteDatabase db;

public DataDbHelper (Context context) {
    super (context, DATABASE_NAME, null, DATABASE_VERSION);
}


@Override
public void onCreate (SQLiteDatabase db) {

    this.db = db;
    final String SQL_CREATE_QUESTIONS_TABLE = "CREATE TABLE "  
            QuestionTable.TABLE_NAME   " ( "  
            QuestionTable._ID   " INTEGER PRIMARY KEY AUTOINCREMENT,"  
            QuestionTable.COLUMN_QUESTION   " TEXT,"  
            QuestionTable.COLUMN_IMAGE   " TEXT,"  
            QuestionTable.COLUMN_ANSWER1   " TEXT,"  
            QuestionTable.COLUMN_ANSWER2   " TEXT,"  
            QuestionTable.COLUMN_ANSWER3   " TEXT,"  
            QuestionTable.COLUMN_ANSWER4   " TEXT,"  
            QuestionTable.COLUMN_ANSWERNUM   " INTEGER "  
            ")";

    db.execSQL(SQL_CREATE_QUESTIONS_TABLE);
    fillQuestionsTable();

    final String SQL_CREATE_STUDENT_TABLE = "CREATE TABLE "  
            StudentTable.TABLE_NAME1   " ( "  
            StudentTable.COLUMN_ID   " INTEGER PRIMARY KEY AUTOINCREMENT,"  
            StudentTable.COLUMN_AM   " TEXT,"  
            StudentTable.COLUMN_NAME   " TEXT,"  
            StudentTable.COLUMN_SEMESTER   " TEXT,"  
            StudentTable.COLUMN_SCORE   " TEXT, "  
            StudentTable.COLUMN_DATE   " TEXT "  
           ")";
    db.execSQL(SQL_CREATE_STUDENT_TABLE);

}


@Override
public void onUpgrade (SQLiteDatabase db, int oldVersion, int   newVersion) {
    db.execSQL("DROP TABLE IF EXISTS "   QuestionTable.TABLE_NAME);
    db.execSQL("DROP TABLE IF EXISTS "   StudentTable.TABLE_NAME1);
    onCreate(db);

}
private void fillQuestionsTable() {
    Question q1 = new Question ("A is correct","arkas.jpj",  "Maria" ,"anna", "Nikos" , "Andy", 1);
    addQuestion (q1);
    Question q2 = new Question ("B is correct","arkas1.jpg", "kjbhkjhA" ,"Bkjgkgj", "Cjvjhgj" , null, 2);
    addQuestion (q2);
    Question q3 = new Question ("C is correct","arkas2.jpg", "cgxcvnx" ,"xcvnxvxv", "Cgnhxfgjxf" , null, 3);
    addQuestion (q3);
    Question q4 = new Question ("A is correct again","NULL", "fvjxfvA" ,"Bxfgxmg", "Cxgmxmx" , null, 1);
    addQuestion (q4);
    Question q5 = new Question ("D is correct","NULL", "Afghf" ,"fghxggggghB", "xfgxghxghC" , "fghxghxgh", 4);
    addQuestion (q5);

}
private void addQuestion(Question question){
    ContentValues cv = new ContentValues();
    cv.put(QuestionTable.COLUMN_QUESTION, question.getQuestion());
    cv.put(QuestionTable.COLUMN_IMAGE, String.valueOf (question.getImage()));
    cv.put(QuestionTable.COLUMN_ANSWER1, question.getAnswer1());
    cv.put(QuestionTable.COLUMN_ANSWER2, question.getAnswer2());
    cv.put(QuestionTable.COLUMN_ANSWER3, question.getAnswer3());

    cv.put(QuestionTable.COLUMN_ANSWER4, question.getAnswer4());
    cv.put(QuestionTable.COLUMN_ANSWERNUM, question.getAnswerNum());
    db.insert(QuestionTable.TABLE_NAME, null, cv);
}

// this method is use to add new student to our sqlite database.
public void addNewStudent(String studentAm, String studentName, String studentSemester, int studentScore, String studentDate){

    // on below line we are creating a variable for
    // our sqlite database and calling writable method
    // as we are writing data in our database.
    SQLiteDatabase db = this.getWritableDatabase();

    // on below line we are creating a
    // variable for content values.
    ContentValues values = new ContentValues();


    // on below line we are passing all values
    // along with its key and value pair.
    values.put(StudentTable.COLUMN_AM, studentAm);
    values.put(StudentTable.COLUMN_NAME, studentName);
    values.put(StudentTable.COLUMN_SEMESTER, studentSemester);
    values.put(StudentTable.COLUMN_SCORE, studentScore);
    values.put(StudentTable.COLUMN_DATE, studentDate);

    // after adding all values we are passing
    // content values to our table.
    db.insert(StudentTable.TABLE_NAME1, null, values);

    // at last we are closing our
    // database after adding database.
    db.close();
}

public  ArrayList<Student> readStudentInfo () {
    // on below line we are creating a
    // database for reading our database.
    SQLiteDatabase db = this.getReadableDatabase();

    // on below line we are creating a cursor with query to read data from database.
    Cursor cursorCourses = db.rawQuery("SELECT * FROM "   StudentTable.TABLE_NAME1, null);

    // on below line we are creating a new array list.
    ArrayList<Student> StudentArrayList = new ArrayList<>();

    // moving our cursor to first position.
    if (cursorCourses.moveToFirst()) {
        do {
            // on below line we are adding the data from cursor to our array list.
            StudentArrayList.add(new Student(cursorCourses.getString(1),
                    cursorCourses.getString(5),
                    cursorCourses.getString(4),
                    cursorCourses.getString(2),
                    cursorCourses.getString(3)));
        } while (cursorCourses.moveToNext());
        // moving our cursor to next.
    }
    // at last closing our cursor
    // and returning our array list.
    cursorCourses.close();
    return StudentArrayList;
}

public List<Question> getAllQuestions() {
    List<Question> questionList = new ArrayList<>();
    db = getReadableDatabase ();
    // Choose Random Questions
    Cursor c = db.rawQuery("SELECT * FROM quiz_question ORDER BY RANDOM() LIMIT 3 ",null );


    if (c.moveToFirst()){
        do {
            Question question = new Question();
            question.setQuestion(c.getString(c.getColumnIndexOrThrow(QuestionTable.COLUMN_QUESTION)));
            question.setImage (c.getString(c.getColumnIndexOrThrow(QuestionTable.COLUMN_IMAGE)));
            question.setAnswer1(c.getString(c.getColumnIndexOrThrow(QuestionTable.COLUMN_ANSWER1)));
            question.setAnswer2(c.getString(c.getColumnIndexOrThrow(QuestionTable.COLUMN_ANSWER2)));
            question.setAnswer3(c.getString(c.getColumnIndexOrThrow(QuestionTable.COLUMN_ANSWER3)));

            question.setAnswer4(c.getString(c.getColumnIndexOrThrow(QuestionTable.COLUMN_ANSWER4)));
            question.setAnswerNum (c.getInt(c.getColumnIndexOrThrow(QuestionTable.COLUMN_ANSWERNUM)));
            questionList.add (question);
        } while (c.moveToNext());
    }
    c.close ();
    return questionList;
}

public  void addScore(int StudentScore){
    ContentValues cv = new ContentValues();
    cv.put(DataContract.StudentTable.COLUMN_SCORE, StudentScore);
    db.update(DataContract.StudentTable.TABLE_NAME1, cv, DataContract.StudentTable.COLUMN_SCORE   "= ?", new String[] {"?"});
    db.close();
}`

問題

`package com.anna.myquiz;

 import android.graphics.drawable.Drawable;

public class Question {
private String question;
private String image;
private String answer1;
private String answer2;
private String answer3;
private String answer4;
private int answerNum;

public Question() {}

public Question (String question,String image, String answer1,   String answer2, String answer3, String answer4, int answerNum) {
    this.question = question;
    this.image = image;
    this.answer1 = answer1;
    this.answer2 = answer2;
    this.answer3 = answer3;
    this.answer4 = answer4;
    this.answerNum = answerNum;
}

public String getQuestion () {
    return question;
}

public void setQuestion (String question) {
    this.question = question;
}

public Object getImage () {
    return Drawable.createFromPath (image);
}

public void setImage (String image) {
    this.image = image;
}

public String getAnswer1 () {
    return answer1;
}

public void setAnswer1 (String answer1) {
    this.answer1 = answer1;
}

public String getAnswer2 () {
    return answer2;
}

public void setAnswer2 (String answer2) {
    this.answer2 = answer2;
}

public String getAnswer3 () {
    return answer3;
}

public void setAnswer3 (String answer3) {
    this.answer3 = answer3;
}

public String getAnswer4 () {
    return answer4;
}

public void setAnswer4 (String answer4) {
    this.answer4 = answer4;
}

public int getAnswerNum () {
    return answerNum;
}

public void setAnswerNum (int answerNum) {
    this.answerNum = answerNum;
}
}`

學生資訊

`package com.anna.myquiz;

public class Student {
private  String studentAm;
private String studentName;
private  String studentSemester;
private static int studentScore;
private String studentDate;
private int id;

public Student(){}

 public Student (String studentAm, String studentName, String      studentSemester, int studentScore, String studentDate, int id) {
    this.studentAm = studentAm;
    this.studentName = studentName;
    this.studentSemester = studentSemester;
    this.studentScore = studentScore;
    this.studentDate = studentDate;
    this.id = id;
}

public Student (String studentAm, String studentName, String   studentSemester, String studentScore, String studentDate) {
}

public String getStudentAm () {
    return studentAm;
}

public void setStudentAm (String studentAm) {
    this.studentAm = studentAm;
}

public String getStudentName () {
    return studentName;
}

public void setStudentName (String studentName) {
    this.studentName = studentName;
}

public String getStudentSemester () {
    return studentSemester;
}

public void setStudentSemester (String studentSemester)   {this.studentSemester = studentSemester; }

public static int getStudentScore () {
    return studentScore;
}

public void setStudentScore (int studentScore) {
    this.studentScore = studentScore;
}

public String getStudentDate () { return studentDate; }

public void setStudentDate (String studentDate) {   this.studentDate = studentDate; }

public int getId () {
    return id;
}

public void setId (int id) {
    this.id = id;
}
}`

測驗活動

 `package com.anna.myquiz;

  import androidx.appcompat.app.AppCompatActivity;


  import android.content.Intent;
  import android.content.res.ColorStateList;

  import android.database.sqlite.SQLiteDatabase;
  import android.graphics.drawable.Drawable;
   import android.os.CountDownTimer;
   import android.os.Bundle;
 import android.view.View;
 import android.widget.Button;
 import android.widget.ImageView;
 import android.widget.RadioButton;
 import android.widget.RadioGroup;
 import android.widget.TextView;
 import android.widget.Toast;

 import java.util.ArrayList;
 import java.util.Collections;
 import android.graphics.Color;
  import android.os.CountDownTimer;
  import java.util.Collections;
  import java.util.Locale;


public class QuestionsAct extends AppCompatActivity {

private TextView tvQuestion;
private TextView tvQuestionCount;
private TextView tvTime;
private TextView tvScore;
private RadioGroup radioGroup;
private RadioButton radioButton1;
private RadioButton radioButton2;
private RadioButton radioButton3;
private RadioButton radioButton4;
private Button butconfirmAns;
private Button butFinish;
private Button butForw;
private Button butBack;
private ImageView tvImgQuest;
private ColorStateList textColorDefaultRb;
private ColorStateList textColorDefaultCd;
private ArrayList<Question> questionList;
private ArrayList<Student> studentList;
private int questionCounter;
private int questionCountTotal;
private Question currentQuestion;
private int score;
private boolean answered;
private SQLiteDatabase db;
//-----------score variables---------------
public static final String EXTRA_SCORE = "extraScore";
//--------------time variables---------------------------
private static final long COUNTDOWN_IN_MILLIS = 3600000;
private CountDownTimer countDownTimer;
private long timeLeftInMillis;


@Override
protected void onCreate (Bundle savedInstanceState)
{
    super.onCreate (savedInstanceState);
    setContentView (R.layout.activity_questions);

    tvQuestion = findViewById (R.id.tVQuestion);
    tvQuestionCount = findViewById (R.id.tvQuestionCount);
    tvTime = findViewById (R.id.tVTime);
    tvScore = findViewById (R.id.tvScore);
    radioGroup = findViewById (R.id.radioGroup);
    radioButton1 = findViewById (R.id.radioButton1);
    radioButton2 = findViewById (R.id.radioButton2);
    radioButton3 = findViewById (R.id.radioButton3);

    radioButton4 = findViewById (R.id.radioButton4);
    butconfirmAns =  findViewById (R.id.butConfirmAns);
    butForw = findViewById (R.id.butForw);
    butBack = findViewById (R.id.butBack);
    tvImgQuest = findViewById (R.id.tvImgQuest);
    textColorDefaultRb = radioButton1.getTextColors ();
    textColorDefaultCd = tvTime.getTextColors();

    DataDbHelper dbHelper = new DataDbHelper (this);
    questionList = (ArrayList<Question>)       bHelper.getAllQuestions ();
    questionCountTotal = questionList.size ();
    Collections.shuffle (questionList);
    timeLeftInMillis = COUNTDOWN_IN_MILLIS;
    startCountDown();
    showNextQuestion ();

    radioGroup.clearCheck();

    butconfirmAns.setOnClickListener (new View.OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            if(!answered)
            {
                if (radioButton1.isChecked() ||   radioButton2.isChecked() || radioButton3.isChecked() || radioButton4.isChecked())
                {
                    checkAnswer();
                }
                else {
                    Toast.makeText (QuestionsAct.this, "Please select an answer", Toast.LENGTH_SHORT).show ();
                }
            }
            else {
                showNextQuestion ();
            }
        }
    });
}

private void showNextQuestion()
{
    radioButton1.setTextColor (textColorDefaultRb);
    radioButton2.setTextColor (textColorDefaultRb);
    radioButton3.setTextColor (textColorDefaultRb);
    radioButton4.setTextColor (textColorDefaultRb);
    radioGroup.clearCheck();
    Question question;

    if (questionCounter < questionCountTotal )
    {
        currentQuestion = questionList.get(questionCounter);

        tvQuestion.setText(currentQuestion.getQuestion ());
        tvImgQuest. setImageDrawable((Drawable)  currentQuestion.getImage());

        radioButton1.setText(currentQuestion.getAnswer1 ());
        radioButton2.setText(currentQuestion.getAnswer2 ());
        radioButton3.setText(currentQuestion.getAnswer3 ());
        //radioButton4.setText(currentQuestion.getAnswer4 ());
        if (DataContract.QuestionTable.COLUMN_ANSWER4.isEmpty ()){
            radioButton4.setVisibility (View.INVISIBLE);
        } else {
            radioButton4.setText(currentQuestion.getAnswer4 ());
         }
        questionCounter  ;
        tvQuestionCount.setText("Question: "   questionCounter   "/"   questionCountTotal);
        answered = false;
        butconfirmAns.setText("Submit");
    }
    else {
        finishQuiz();
    }

}

private void checkAnswer()
{
    answered = true;
    //countDownTimer.cancel();
    RadioButton rbSelected =  findViewById(radioGroup.getCheckedRadioButtonId());
    int answerNum = radioGroup.indexOfChild(rbSelected)   1;
    
    if (answerNum == currentQuestion.getAnswerNum()){
        score  ;
        tvScore.setText("Score: "   score);
    }
    // here must put the method to insert score in database
    checkEndOfQuiz();
}

private void checkEndOfQuiz()
{
    if (questionCounter < questionCountTotal)
    {
        butconfirmAns.setText("Next");
    }
    else {
        butconfirmAns.setText("Finish");
        //addScore(score);
    }
}


private void finishQuiz()
{
    Intent  ResultAct = new Intent(QuestionsAct.this,ResultAct.class);
    ResultAct.putExtra (EXTRA_SCORE , score);

    startActivity (ResultAct);
}


private void startCountDown()
{
    countDownTimer = new CountDownTimer(timeLeftInMillis, 1000)
    {
        @Override
        public void onTick(long millisUntilFinished)
        {
            timeLeftInMillis = millisUntilFinished;
            updateCountDownText();
        }

        @Override
        public void onFinish()
        {
            timeLeftInMillis = 0;
            updateCountDownText();
            //checkAnswer();
        }
    }.start ();
}
private void updateCountDownText() {
    int minutes = (int) (timeLeftInMillis / 1000) / 60;
    int seconds = (int) (timeLeftInMillis / 1000) % 60;

    String timeFormatted = String.format(Locale.getDefault(), "d:d", minutes, seconds);

    tvTime.setText(timeFormatted);

    if (timeLeftInMillis < 1000) {
        tvTime.setTextColor(Color.RED);
    } else {
        tvTime.setTextColor(textColorDefaultCd);
    }

}

@Override
protected void onDestroy() {
    super.onDestroy();
    if (countDownTimer != null) {
        countDownTimer.cancel();
    }
}
}`

uj5u.com熱心網友回復:

考慮到隨問題發布的代碼數量有限,這是一個帶有建議技術的演示。

這利用兩個表來符合規范化方法。問題表和答案表。每個答案(子項)都有一個與單個問題(父項)的鏈接/地圖/關系/關聯。為了防止參考完整性問題,使用了外鍵約束。

首先是問題答案QuestionWithAnswers的一些 POJO (即它的答案)

問題POJO

class QuestionPOJO {
    long questionId;
    String questionText;

    public QuestionPOJO(long questionId, String questionText) {
        this.questionId = questionId;
        this.questionText = questionText;
    }

    public long getQuestionId() {
        return questionId;
    }

    public void setQuestionId(long questionId) {
        this.questionId = questionId;
    }

    public String getQuestionText() {
        return questionText;
    }

    public void setQuestionText(String questionText) {
        this.questionText = questionText;
    }
}

回答POJO

class AnswerPOJO {
    long answerId;
    long questionMap;
    String answerText;
    boolean correct = false;

    public AnswerPOJO(long answerid, long questionMap, String answerText, boolean correct) {
        this.answerId = answerid;
        this.questionMap = questionMap;
        this.answerText = answerText;
        this.correct = correct;
    }

    public long getAnswerId() {
        return answerId;
    }

    public void setAnswerId(long answerId) {
        this.answerId = answerId;
    }

    public long getQuestionMap() {
        return questionMap;
    }

    public void setQuestionMap(long questionMap) {
        this.questionMap = questionMap;
    }

    public boolean isCorrect() {
        return correct;
    }

    public void setCorrect(boolean correct) {
        this.correct = correct;
    }

    public String getAnswerText() {
        return answerText;
    }

    public void setAnswerText(String answerText) {
        this.answerText = answerText;
    }
}

QuestionWithAnswerPOJO

class QuestionWithAnswersPOJO {
    QuestionPOJO question;
    ArrayList<AnswerPOJO> answers = new ArrayList<>();

    public QuestionWithAnswersPOJO(QuestionPOJO question, List<AnswerPOJO> answers) {
        this.question = question;
        this.answers.clear();
        this.answers.addAll(answers);
    }

    public QuestionPOJO getQuestion() {
        return question;
    }

    public void setQuestion(QuestionPOJO question) {
        this.question = question;
    }

    public ArrayList<AnswerPOJO> getAnswers() {
        return answers;
    }

    public void setAnswers(ArrayList<AnswerPOJO> answers) {
        this.answers = answers;
    }
}

現在是處理所有資料庫活動的 DatabaseHelper。包括添加和獲取問題和答案的方法,尤其是獲取屬于問題的答案。

class DatabaseHelper extends SQLiteOpenHelper {

    public static final String DATABASE_NAME = "questions.db";
    public static final int DATABASE_VERSION = 1;

    public static final String QUESTION_TABLE = "question";
    public static final String QUESTION_ID_COLUMN = BaseColumns._ID;
    public static final String QUESTION_TEXT_COLUMN = "question_text";
    public static final String ANSWER_TABLE = "answer";
    public static final String ANSWER_ID_COLUMN = BaseColumns._ID;
    public static final String ANSWER_TEXT_COLUMN = "answer_text";
    public static final String ANSWER_QUESTION_MAP_COLUMN = "question_map";
    public static final String ANSWER_CORRECT_COLUMN = "correct";

    private static volatile DatabaseHelper instance = null;
    private DatabaseHelper(Context context) {
        super(context,DATABASE_NAME,null,DATABASE_VERSION);
    }

    private static SQLiteDatabase db = null;

    public static DatabaseHelper getInstance(Context context, boolean forceOpen) {
        if (instance == null) {
            instance = new DatabaseHelper(context);
        }
        if (forceOpen) {
            db = instance.getWritableDatabase();
        }
        return instance;
    }
    @Override
    public void onCreate(SQLiteDatabase db) {

        db.execSQL("CREATE TABLE IF NOT EXISTS "   QUESTION_TABLE   "("  
                QUESTION_ID_COLUMN   " INTEGER PRIMARY KEY,"  
                QUESTION_TEXT_COLUMN   " TEXT"  
                ");");
        db.execSQL("CREATE TABLE IF NOT EXISTS "   ANSWER_TABLE   "("  
                ANSWER_ID_COLUMN   " INTEGER PRIMARY KEY,"  
                ANSWER_TEXT_COLUMN   " TEXT,"  
                ANSWER_QUESTION_MAP_COLUMN   " INTEGER REFERENCES "   QUESTION_TABLE   "("   QUESTION_ID_COLUMN   ") ON DELETE CASCADE ON UPDATE CASCADE,"  
                ANSWER_CORRECT_COLUMN   " INTEGER DEFAULT 0 /* false */"  
                ");");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int i, int i1) {

    }

    // Fully comprehensive Question insert
    public long insertQuestion(Long questionId, String questionText) {
        init_db_AsWriteableDatabase();
        long rv = -2;
        ContentValues cv = new ContentValues();
        if (questionId != null && questionId > 0) {
            cv.put(QUESTION_ID_COLUMN,questionId);
        }
        if (questionText != null && questionText.length() > 0) {
            cv.put(QUESTION_TEXT_COLUMN,questionText);
        }
        if (cv.size() > 0) {
            rv = db.insert(QUESTION_TABLE,null,cv);
        }
        return rv;
    }

    // Concise Question insert
    public long insertQuestion(String questionText) {
        return insertQuestion(null,questionText);
    }

    // Fully comprehensive Answer insert
    public long insertAnswer(Long answerId, long questionMap, String answerText, boolean correct) {
        init_db_AsWriteableDatabase();
        long rv = -2;
        ContentValues cv = new ContentValues();
        if (answerId != null && answerId > 0) {
            cv.put(ANSWER_ID_COLUMN,answerId);
        }
        if (answerText != null && answerText.length() > 0) {
            cv.put(ANSWER_CORRECT_COLUMN,correct);
            cv.put(ANSWER_TEXT_COLUMN,answerText);
            cv.put(ANSWER_QUESTION_MAP_COLUMN,questionMap);
            rv = db.insert(ANSWER_TABLE,null,cv);
        }
        return rv;
    }

    // long concise Answer insert
    public long insertAnswer(long questionMap, String answerText, boolean correct) {
        return insertAnswer(null,questionMap,answerText,correct);
    }
    public long insertAnswer(long questionMap, String answerText) {
        return insertAnswer(questionMap,answerText,false);
    }
    // short concise Answer insert
    private void init_db_AsWriteableDatabase() {
        if (db == null) {
            db = this.getWritableDatabase();
        }
    }


    @SuppressLint("Range")
    public QuestionPOJO getQuestionById(long questionId) {
        QuestionPOJO rv = null;
        init_db_AsWriteableDatabase();
        Cursor csr = db.query(QUESTION_TABLE,null,QUESTION_ID_COLUMN "=?",new String[]{String.valueOf(questionId)},null,null,null);
        if (csr.moveToNext()) {
            rv = new QuestionPOJO(csr.getLong(csr.getColumnIndex(QUESTION_ID_COLUMN)),csr.getString(csr.getColumnIndex(QUESTION_TEXT_COLUMN)));
        }
        csr.close();
        return rv;
    }

    @SuppressLint("Range")
    public List<AnswerPOJO> getAnswersForQuestion(long questionId, boolean onlyCorrect) {
        init_db_AsWriteableDatabase();
        ArrayList<AnswerPOJO> rv = new ArrayList<>();
        StringBuilder whereClause = new StringBuilder();
        whereClause.append(ANSWER_QUESTION_MAP_COLUMN   "=?");
        if (onlyCorrect) {
            whereClause.append(" AND ").append(ANSWER_CORRECT_COLUMN);
        }
        Cursor csr = db.query(ANSWER_TABLE,null,whereClause.toString(),new String[]{String.valueOf(questionId)},null,null,null);
        while (csr.moveToNext()) {
            rv.add(
                new AnswerPOJO(
                        csr.getLong(csr.getColumnIndex(ANSWER_ID_COLUMN)),
                        questionId,
                        csr.getString(csr.getColumnIndex(ANSWER_TEXT_COLUMN)),
                        csr.getInt(csr.getColumnIndex(ANSWER_CORRECT_COLUMN)) > 0
                )
            );
        }
        csr.close();
        return rv;
    }
}

最后將它們放在一起,活動具有 4 個單選按鈕的布局以及作為 TextView 的相關答案。

所以布局是: -

<?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:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!">
    </TextView>

    <RadioGroup
        android:id="@ id/question_radiogroup"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <RadioButton
            android:id="@ id/answer1_radioButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            tools:ignore="DuplicateSpeakableTextCheck"></RadioButton>
        <TextView
            android:id="@ id/answer1_textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
        </TextView>
        <RadioButton
            android:id="@ id/answer2_radioButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
        </RadioButton>
        <TextView
            android:id="@ id/answer2_textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
        </TextView>
        <RadioButton
            android:id="@ id/answer3_radioButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
        </RadioButton>
        <TextView
            android:id="@ id/answer3_textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
        </TextView>

        <RadioButton
            android:id="@ id/answer4_radioButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
        </RadioButton>
        <TextView
            android:id="@ id/answer4_textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
        </TextView>
    </RadioGroup>

</LinearLayout>
  • 簡單到足以顯示如何根據答案的數量隱藏按鈕(或根據按鈕/文本視圖的數量限制)

以及要展示的活動:-

public class MainActivity extends AppCompatActivity {
    DatabaseHelper dbHelper;
    RadioButton[] radiobuttons = new RadioButton[4];
    TextView[] answerTexts = new TextView[4];
    QuestionWithAnswersPOJO currentQuestionWithAnswers;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        /*
            prepare Radion Buttons and associated TextViews
         */
        radiobuttons[0] = this.findViewById(R.id.answer1_radioButton);
        radiobuttons[1] = this.findViewById(R.id.answer2_radioButton);
        radiobuttons[2] = this.findViewById(R.id.answer3_radioButton);
        radiobuttons[3] = this.findViewById(R.id.answer4_radioButton);
        answerTexts[0] = this.findViewById(R.id.answer1_textview);
        answerTexts[1] = this.findViewById(R.id.answer2_textview);
        answerTexts[2] = this.findViewById(R.id.answer3_textview);
        answerTexts[3] = this.findViewById(R.id.answer4_textview);

        /*
            Prepare to use Database
         */
        dbHelper = DatabaseHelper.getInstance(this,true);
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        /* Clear any existing data for consistent results */
        db.delete(DatabaseHelper.ANSWER_TABLE,null,null);
        db.delete(DatabaseHelper.QUESTION_TABLE,null,null);
        /* Add some demo data  1 question with 5 answers (comment out to reduce number of answers)*/
        long q1id = dbHelper.insertQuestion("What is 1   1");
        dbHelper.insertAnswer(q1id,"It is 1");
        dbHelper.insertAnswer(q1id,"it is 2", true);
        dbHelper.insertAnswer(q1id,"It is 3");
        dbHelper.insertAnswer(q1id,"It is 4");
        dbHelper.insertAnswer(q1id,"It is something Else"); // will be ignored because only 4 radio buttons

        /* Get the question with the answers, however many ot has */
        currentQuestionWithAnswers = new QuestionWithAnswersPOJO(dbHelper.getQuestionById(q1id),dbHelper.getAnswersForQuestion(q1id,false));
        /* setup (refresh) the radio buttons and textviews */
        getAndSetRadioButtons(currentQuestionWithAnswers);
    }

    /*
        Does as it says
     */
    private void getAndSetRadioButtons(QuestionWithAnswersPOJO qwa) {
        // Clear All

        for (int i=0;i < radiobuttons.length; i  ) {
            radiobuttons[i].setVisibility(View.GONE);
            answerTexts[i].setText("");
            answerTexts[i].setVisibility(View.GONE);
        }
        /* show only the least of answers/radio buttons */
        int numberToShow = radiobuttons.length;
        if (qwa.answers.size() < radiobuttons.length) {
            numberToShow = qwa.answers.size();
        }
        int i = 0;
        for(AnswerPOJO a: qwa.answers) {
            if (i < numberToShow) {
                radiobuttons[i].setVisibility(View.VISIBLE);
                answerTexts[i].setVisibility(View.VISIBLE);
                answerTexts[i  ].setText(a.answerText);
            } else {
                /* nothing more to do so early break out of the loop */
                break;
            }
        }
    }
}

結果

結果 1 - 運行 5 個答案(請參閱第 5 個答案的評論)

我需要在測驗應用程式android中隱藏一個單選按鈕

結果 2 - 所有欄 1 答案注釋掉,所以問題只有 1 個答案

使用的代碼:-

    long q1id = dbHelper.insertQuestion("What is 1   1");
    dbHelper.insertAnswer(q1id,"It is 1");
    //dbHelper.insertAnswer(q1id,"it is 2", true);
    //dbHelper.insertAnswer(q1id,"It is 3");
    //dbHelper.insertAnswer(q1id,"It is 4");
    //dbHelper.insertAnswer(q1id,"It is something Else"); // will be ignored because only 4 radio buttons

顯示幕 :-

我需要在測驗應用程式android中隱藏一個單選按鈕

結果 3 - 僅插入第一個和第 5 個答案

我需要在測驗應用程式android中隱藏一個單選按鈕

等等。


發布代碼后的附加資訊。

現在添加了作為代碼的附加答案。

你說:-

嘗試使用: if (DataContract.QuestionTable.COLUMN_ANSWER4.isEmpty ()){ radioButton4.setVisibility (View.INVISIBLE); } 但似乎不起作用。

如果DataContract.QuestionTable.COLUMN_ANSWER4為空,則將面臨更嚴重的問題,因為它是列名

對于正在檢查的問題,您應該檢查從 DB 檢索并放入currentQuestion的列的內容

我相信使用(舊代碼注釋掉): -

        radioButton1.setText(currentQuestion.getAnswer1 ());
        radioButton2.setText(currentQuestion.getAnswer2 ());
        radioButton3.setText(currentQuestion.getAnswer3 ());
        radioButton4.setText(currentQuestion.getAnswer4 ());
        if(currentQuestion.getAnswer4() == null || currentQuestion.getAnswer4().isEmpty()) {
            radioButton4.setVisibility(View.INVISIBLE);
        } else {
            radioButton4.setVisibility(View.VISIBLE); // just in case it is INVISIBLE
            radioButton4.setText(currentQuestion.getAnswer4());
        }
        /*
        if (DataContract.QuestionTable.COLUMN_ANSWER4.isEmpty ()){
            radioButton4.setVisibility (View.INVISIBLE);
        } else {
            radioButton4.setText(currentQuestion.getAnswer4 ());
        }
         */

將解決這個問題。例如在第三季度:-

我需要在測驗應用程式android中隱藏一個單選按鈕

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/405915.html

標籤:

上一篇:如何從AndroidStudio或GitlabPipeline自動上傳AppCenter?

下一篇:我認為AndroidStudioGit的作業方式很奇怪?

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 面試突擊第一季,第二季,第三季

    第一季必考 https://www.bilibili.com/video/BV1FE411y79Y?from=search&seid=15921726601957489746 第二季分布式 https://www.bilibili.com/video/BV13f4y127ee/?spm_id_fro ......

    uj5u.com 2020-09-10 05:35:24 more
  • 第三單元作業總結

    1.前言 這應該是本學期最后一次寫作業總結了吧。總體來說,對作業的節奏也差不多掌握了,作業做起來的效率也更高了。雖然和之前的作業一樣,作業中都要用到新的知識,但是相比之前,更加懂得了如何利用工具以及資料。雖然之間卡過殼,但總體而言,這幾次作業還算完成的比較好。 2.作業程序總結 相比前兩個單元,此單 ......

    uj5u.com 2020-09-10 05:35:41 more
  • 北航OO(2020)第四單元博客作業暨課程總結博客

    北航OO(2020)第四單元博客作業暨課程總結博客 本單元作業的架構設計 在本單元中,由于UML圖具有比較清晰的樹形結構,因此我對其中需要進行查詢操作的元素進行了包裝,在樹的父節點中存盤所有孩子的參考。考慮到性能問題,我采用了快取機制,一次查詢后盡可能快取已經遍歷過的資訊,以減少遍歷次數。 本單元我 ......

    uj5u.com 2020-09-10 05:35:48 more
  • BUAA_OO_第四單元

    一、UML決議器設計 ? 先看下題目:第四單元實作一個基于JDK 8帶有效性檢查的UML(Unified Modeling Language)類圖,順序圖,狀態圖分析器 MyUmlInteraction,實際上我們要建立一個有向圖模型,UML中的物件(元素)可能與同級元素連接,也可與低級元素相連形成 ......

    uj5u.com 2020-09-10 05:35:54 more
  • 6.1邏輯運算子

    邏輯運算子 1. && 短路與 運算式1 && 運算式2 01.運算式1為true并且運算式2也為true 整體回傳為true 02.運算式1為false,將不會執行運算式2 整體回傳為false 03.只要有一個運算式為false 整體回傳為false 2. || 短路或 運算式1 || 運算式2 ......

    uj5u.com 2020-09-10 05:35:56 more
  • BUAAOO 第四單元 & 課程總結

    1. 第四單元:StarUml檔案決議 本單元采用了圖模型決議UML。 UML檔案可以抽象為圖、子圖、邊的邏輯結構。 在實作中,圖的節點包括類、介面、屬性,子圖包括狀態圖、順序圖等。 采用了三次遍歷UML元素的方法建圖,第一遍遍歷建點,第二、三次遍歷設定屬性、連邊,實作圖物件的初始化。這里借鑒了一些 ......

    uj5u.com 2020-09-10 05:36:06 more
  • 談談我對C# 多型的理解

    面向物件三要素:封裝、繼承、多型。 封裝和繼承,這兩個比較好理解,但要理解多型的話,可就稍微有點難度了。今天,我們就來講講多型的理解。 我們應該經常會看到面試題目:請談談對多型的理解。 其實呢,多型非常簡單,就一句話:呼叫同一種方法產生了不同的結果。 具體實作方式有三種。 一、多載 多載很簡單。 p ......

    uj5u.com 2020-09-10 05:36:09 more
  • Python 資料驅動工具:DDT

    背景 python 的unittest 沒有自帶資料驅動功能。 所以如果使用unittest,同時又想使用資料驅動,那么就可以使用DDT來完成。 DDT是 “Data-Driven Tests”的縮寫。 資料:http://ddt.readthedocs.io/en/latest/ 使用方法 dd. ......

    uj5u.com 2020-09-10 05:36:13 more
  • Python里面的xlrd模塊詳解

    那我就一下面積個問題對xlrd模塊進行學習一下: 1.什么是xlrd模塊? 2.為什么使用xlrd模塊? 3.怎樣使用xlrd模塊? 1.什么是xlrd模塊? ?python操作excel主要用到xlrd和xlwt這兩個庫,即xlrd是讀excel,xlwt是寫excel的庫。 今天就先來說一下xl ......

    uj5u.com 2020-09-10 05:36:28 more
  • 當我們創建HashMap時,底層到底做了什么?

    jdk1.7中的底層實作程序(底層基于陣列+鏈表) 在我們new HashMap()時,底層創建了默認長度為16的一維陣列Entry[ ] table。當我們呼叫map.put(key1,value1)方法向HashMap里添加資料的時候: 首先,呼叫key1所在類的hashCode()計算key1 ......

    uj5u.com 2020-09-10 05:36:38 more
最新发布
  • 【中介者設計模式詳解】C/Java/JS/Go/Python/TS不同語言實作

    * 中介者模式是一種行為型設計模式,它可以用來減少類之間的直接依賴關系,
    * 將物件之間的通信封裝到一個中介者物件中,從而使得各個物件之間的關系更加松散。
    * 在中介者模式中,物件之間不再直接相互互動,而是通過中介者來中轉訊息。 ......

    uj5u.com 2023-04-20 08:20:47 more
  • 露天煤礦現場調研和交流案例分享

    他們集團的資訊化公司及研究院在一個礦區正在做智能礦山的統一平臺的 試點,專案投資大概1億,包括了礦山的各方面的內容,顯示得我們這次交流有點多余。他們2年前開始做智能礦山的規劃,有很多煤礦行業專家的加持,他們的描述是非常完美,但是去年底應該上線的平臺,現在還沒有看到影子。他們確實有很多場景需求,但是被... ......

    uj5u.com 2023-04-20 08:20:25 more
  • 《社區人員管理》實戰案例設計&個人案例分享

    設計是一個讓人夢想成真程序,開始編碼、測驗、除錯之前進行需求分析和架構設計,才能保證關鍵方面都做正確 ......

    uj5u.com 2023-04-20 08:20:17 more
  • 軟體架構生態化-多角色交付的探索實踐

    作為一個技術架構師,不僅僅要緊跟行業技術趨勢,還要結合研發團隊現狀及痛點,探索新的交付方案。在日常中,你是否遇到如下問題 “ 業務需求排期長研發是瓶頸;非研發角色感受不到研發技改提效的變化;引入ISV 團隊又擔心質量和安全,培訓周期長“等等,基于此我們探索了一種新的技術體系及交付方案來解決如上問題。 ......

    uj5u.com 2023-04-20 08:20:10 more
  • 【中介者設計模式詳解】C/Java/JS/Go/Python/TS不同語言實作

    * 中介者模式是一種行為型設計模式,它可以用來減少類之間的直接依賴關系,
    * 將物件之間的通信封裝到一個中介者物件中,從而使得各個物件之間的關系更加松散。
    * 在中介者模式中,物件之間不再直接相互互動,而是通過中介者來中轉訊息。 ......

    uj5u.com 2023-04-20 08:19:44 more
  • 露天煤礦現場調研和交流案例分享

    他們集團的資訊化公司及研究院在一個礦區正在做智能礦山的統一平臺的 試點,專案投資大概1億,包括了礦山的各方面的內容,顯示得我們這次交流有點多余。他們2年前開始做智能礦山的規劃,有很多煤礦行業專家的加持,他們的描述是非常完美,但是去年底應該上線的平臺,現在還沒有看到影子。他們確實有很多場景需求,但是被... ......

    uj5u.com 2023-04-20 08:19:07 more
  • 《社區人員管理》實戰案例設計&個人案例分享

    設計是一個讓人夢想成真程序,開始編碼、測驗、除錯之前進行需求分析和架構設計,才能保證關鍵方面都做正確 ......

    uj5u.com 2023-04-20 08:18:57 more
  • 軟體架構生態化-多角色交付的探索實踐

    作為一個技術架構師,不僅僅要緊跟行業技術趨勢,還要結合研發團隊現狀及痛點,探索新的交付方案。在日常中,你是否遇到如下問題 “ 業務需求排期長研發是瓶頸;非研發角色感受不到研發技改提效的變化;引入ISV 團隊又擔心質量和安全,培訓周期長“等等,基于此我們探索了一種新的技術體系及交付方案來解決如上問題。 ......

    uj5u.com 2023-04-20 08:18:49 more
  • 05單件模式

    #經典的單件模式 public class Singleton { private static Singleton uniqueInstance; //一個靜態變數持有Singleton類的唯一實體。 // 其他有用的實體變數寫在這里 //構造器宣告為私有,只有Singleton可以實體化這個類! ......

    uj5u.com 2023-04-19 08:42:51 more
  • 【架構與設計】常見微服務分層架構的區別和落地實踐

    軟體工程的方方面面都遵循一個最基本的道理:沒有銀彈,架構分層模型更是如此,每一種都有各自優缺點,所以請根據不同的業務場景,并遵循簡單、可演進這兩個重要的架構原則選擇合適的架構分層模型即可。 ......

    uj5u.com 2023-04-19 08:42:41 more