android 实现答题功能

news2024/11/24 1:46:54

一、效果

二、实现思路

1、界面实现

        实现起来其实不难,首先我们可以看到,界面是由答题进度、题目、选项ABCD组成,现在就是要考虑实现方式,答题进度可以使用Textview+progressbar实现,题目直接使用Textview,选项ABCD使用listview或者recyview,这里选择后者recyview。

2、题目切换逻辑实现

    ABCD单选多选可以用使用对象标记不同状态,题目替换可以使用Handler切换到集合下一个数据, ABCD选项列表也是重新赋值。

三、代码

1、题目布局

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">

    <data>

    </data>

    <LinearLayout
        android:layout_width="@dimen/dp_640"
        android:layout_height="@dimen/dp_400"
        android:background="@color/pageBgColor"
        android:orientation="vertical">

        <!--  返回模块 -->
        <include
            android:id="@+id/titleLyout"
            layout="@layout/chart_top_title_layout" />

        <!-- 内容 -->
        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="@dimen/dp_300"
            android:paddingTop="@dimen/dp_15">

            <TextView
                android:id="@+id/questionTitle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/dp_30"
                android:layout_marginRight="@dimen/dp_30"
                android:gravity="center|left"
                android:text=""
                android:textColor="@color/white"
                android:textSize="@dimen/sp_20"
                android:textStyle="bold" />

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/ryList"
                android:layout_width="@dimen/dp_385"
                android:layout_height="wrap_content"
                android:layout_below="@id/questionTitle"
                android:layout_marginLeft="@dimen/dp_30"
                android:layout_marginTop="@dimen/dp_10" />

            <!-- 再听一遍 -->
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_alignParentBottom="true"
                android:layout_marginLeft="@dimen/dp_60"
                android:layout_marginRight="@dimen/dp_30"
                android:gravity="center"
                android:orientation="vertical">

                <LinearLayout
                    android:id="@+id/repeat_tts"
                    android:layout_width="@dimen/dp_60"
                    android:layout_height="@dimen/dp_60"
                    android:background="@drawable/voice_bd_th"
                    android:gravity="center">

                    <ImageView
                        android:layout_width="@dimen/dp_30"
                        android:layout_height="@dimen/dp_25"
                        android:src="@drawable/voice_pic" />
                </LinearLayout>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="@dimen/dp_5"
                    android:text="再听一遍"
                    android:textColor="@color/white"
                    android:textSize="@dimen/sp_14" />
            </LinearLayout>

            <TextView
                android:id="@+id/tvBack"
                android:layout_width="@dimen/dp_100"
                android:layout_height="@dimen/dp_30"
                android:layout_alignParentRight="true"
                android:layout_alignParentBottom="true"
                android:layout_marginRight="@dimen/dp_240"
                android:layout_marginBottom="@dimen/dp_15"
                android:background="@drawable/start_screening_next_qs"
                android:gravity="center"
                android:visibility="gone"
                android:text="上一题"
                android:textColor="@color/white"
                android:textSize="@dimen/sp_14" />

            <TextView
                android:id="@+id/tvNext"
                android:layout_width="@dimen/dp_100"
                android:layout_height="@dimen/dp_30"
                android:layout_alignParentRight="true"
                android:layout_alignParentBottom="true"
                android:layout_marginRight="@dimen/dp_120"
                android:layout_marginBottom="@dimen/dp_15"
                android:background="@drawable/start_screening_next_qs"
                android:gravity="center"
                android:text="下一题"
                android:textColor="@color/white"
                android:textSize="@dimen/sp_14" />
        </RelativeLayout>

        <!-- 底部进度布局 -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="@dimen/dp_60"
            android:orientation="vertical">

            <TextView
                android:id="@+id/tvCount"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/dp_20"
                android:layout_marginTop="@dimen/dp_5"
                android:text="0/12"
                android:textColor="@color/white"
                android:textSize="@dimen/sp_14" />

            <ProgressBar
                android:id="@+id/progress"
                style="@style/screeningSeekBar"
                android:layout_width="match_parent"
                android:layout_height="@dimen/dp_5"
                android:layout_marginLeft="@dimen/dp_10"
                android:layout_marginTop="@dimen/dp_10"
                android:layout_marginRight="@dimen/dp_5"
                android:max="50"
                android:progress="10" />

        </LinearLayout>
    </LinearLayout>
</layout>

2、abcd答案列表布局

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">

    <data>

    </data>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/dp_10">
        <!-- screnning_question_item -->
        <TextView
            android:id="@+id/tvContent"
            android:layout_width="@dimen/dp_160"
            android:layout_height="@dimen/dp_40"
            android:background="@drawable/unselect_screnning_qs_item"
            android:gravity="center"
            android:text="-"
            android:textSize="@dimen/sp_14" />
    </RelativeLayout>
</layout>

3、主界面java代码

package csu.xiaoya.robotApp.ui.fragment_healthy_housekeeper.healthy_screen.screeningcn;

import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.GridLayoutManager;

import com.google.gson.Gson;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;
import java.util.OptionalInt;
import java.util.stream.IntStream;

import csu.xiaoya.robotApp.R;
import csu.xiaoya.robotApp.XiaoYaApp;
import csu.xiaoya.robotApp.base.BaseActivity;
import csu.xiaoya.robotApp.databinding.ScreeningContentLayoutBinding;
import csu.xiaoya.robotApp.glob.GlobalConstant;
import csu.xiaoya.robotApp.ui.activity.homepage.familydIm.FamilyDoctorActivity;
import csu.xiaoya.robotApp.ui.fragment_healthy_housekeeper.healthy_screen.HealthyScreeningActivity;
import csu.xiaoya.robotApp.ui.fragment_healthy_housekeeper.healthy_screen.screenbean.ReplySuccessBean;
import csu.xiaoya.robotApp.ui.fragment_healthy_housekeeper.healthy_screen.screenbean.ScreeningContentBean;
import csu.xiaoya.robotApp.ui.fragment_healthy_housekeeper.healthy_screen.screenbean.SubmitSreeningBean;
import csu.xiaoya.robotApp.ui.fragment_healthy_housekeeper.healthy_screen.screening_finish.ScreeningFinishPage;
import csu.xiaoya.robotApp.ui.pagemanage.beans.JumpBean;
import csu.xiaoya.robotApp.ui.pagemanage.constant.JumpPageCode;
import csu.xiaoya.robotApp.util.ActivityUtil;
import csu.xiaoya.robotApp.util.GlideUtil;
import csu.xiaoya.robotApp.util.HandlerUtils;
import csu.xiaoya.robotApp.util.dialog.LoginDialogUtil;
import csu.xiaoya.robotApp.util.log.Logger;

/**
 * 健康
 * 筛查内容
 */

public class ScreeningContentPage extends BaseActivity<ScreeningContentLayoutBinding, ScreeningContentViewmodle> implements HandlerUtils.OnReceiveMessageListener {
    // handler
    private HandlerUtils.HandlerHolder myHandler;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityUtil.getInstance().addActivity(ScreeningContentPage.this);
    }

    private int selectModuleId = 0;
    private int poolCodeType = 0;

    @Override
    protected void handleIntent(Intent intent) {
        super.handleIntent(intent);
        selectModuleId = Integer.parseInt(intent.getSerializableExtra("selectModuleId").toString());
        poolCodeType = Integer.parseInt(intent.getSerializableExtra("poolCodeType").toString());
        Logger.d("======健康筛查内容=====" + selectModuleId);
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.screening_content_layout;
    }

    @Override
    protected void initViewModel() {

    }

    @Override
    public void handlerMessage(Message msg) {

        // 刷新列表
        Logger.d("======没有更多消息======" + questionPosition);
    }

    @Override
    protected void bindViewModel() {
        mViewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(ScreeningContentViewmodle.class);
    }

    @Override
    protected void init() {

        // 标记为健康筛查答题模式
        GlobalConstant.asrModule = 1;

        myHandler = new HandlerUtils.HandlerHolder(this);

        initTitleLayout();

        mViewModel.getQuestionList(selectModuleId + "");

        // 初始化适配器
        initAdapter();
        initDataListner();
    }

    /**
     * 答案选择
     * 适配器
     */
    private ScreeningQuestionAdapater sqAdapter;
    private ScreeningContentBean sqAdapterBean;

    private void initAdapter() {

        sqAdapter = new ScreeningQuestionAdapater();
        mDataBinding.ryList.setAdapter(sqAdapter);
        mDataBinding.ryList.setLayoutManager(new GridLayoutManager(this, 2));

    }

    /**
     * 数据
     * 监听
     */
    private int questionPosition = 0;


    private void initDataListner() {

        // 切换下一题
        mDataBinding.tvNext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean isCheck = false;//答案是否选择

                if (questionPosition <= sqAdapterBean.getData().getQuestionList().size()) {

                    if (questionPosition == 0) {
                        questionPosition = 0;
                    }

                    for (int i = 0; i < sqAdapterBean.getData().getQuestionList().get(questionPosition).getAnswerList().size(); i++) {

                        if (sqAdapterBean.getData().getQuestionList().get(questionPosition).getAnswerList().get(i).getStatus().equals("1")) {
                            isCheck = true;
                            break;
                        }
                    }

                    if (sqAdapterBean.getData().getQuestionList().get(questionPosition).getQuestionType().equals("2")) {
                        isCheck = true;
                    }

                    // 已选种答案可以切换下一题
                    if (isCheck) {
                        // 选择效果切换
                        nextQuestion();
                    } else {
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(ScreeningContentPage.this, "至少选择一个答案", Toast.LENGTH_SHORT).show();
                            }
                        });
                    }

                }
            }
        });

        // 问答数据集合
        mViewModel.getScreeningContentBeanLivewDt().observe(this, new Observer<ScreeningContentBean>() {
            @Override
            public void onChanged(ScreeningContentBean screeningContentBean) {
                questionPosition = 0;
                sqAdapterBean = screeningContentBean;
                sqAdapter.adapaterAddData(screeningContentBean.getData().getQuestionList().get(0).getAnswerList());
                //
                if (XiaoYaApp.isAIUiFail()) {
                    Toast.makeText(ScreeningContentPage.this, "语音未授权", Toast.LENGTH_SHORT).show();
                } else {
                    if (sqAdapterBean.getData().getQuestionList().get(0).getQuestionType().equals("2")) {
                        XiaoYaApp.setOnlyPlayTTs(true);
                    }
                    // 语音播报
                    if (XiaoYaApp.getAiuiRecognizerService() != null) {
                        XiaoYaApp.getAiuiRecognizerService().playTts("" + screeningContentBean.getData().getQuestionList().get(0).getQuestionText());
                    }
                }

                // 数据显示
                mDataBinding.questionTitle.setText("" + screeningContentBean.getData().getQuestionList().get(0).getQuestionText());

                // 计数
                mDataBinding.tvCount.setText("0/" + screeningContentBean.getData().getQuestionList().size());
                mDataBinding.progress.setMax(screeningContentBean.getData().getQuestionList().size());
                mDataBinding.progress.setProgress(0);

                sqAdapter.notifyDataSetChanged();
//                Logger.LogD("健康筛查内容", "==获取题库==" + new Gson().toJson(screeningContentBean));
            }
        });

        // 答案列表选择监听
        sqAdapter.setOnItemClickListner(new ScreeningQuestionAdapater.OnItemClickListner() {
            @Override
            public void onItemClick(View view, int postion) {

                answerQt(postion);

            }

            @Override
            public void onItemLongClick(View view, int postion) {

            }
        });

        // 上一个
        mDataBinding.tvBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                backQuestion();
            }
        });

        // 重复播放tts
        mDataBinding.repeatTts.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (XiaoYaApp.isAIUiFail()) {
                    Toast.makeText(ScreeningContentPage.this, "语音未授权", Toast.LENGTH_SHORT).show();
                } else {
                    if (sqAdapterBean.getData().getQuestionList().get(questionPosition).getQuestionType().equals("2")) {
                        XiaoYaApp.setOnlyPlayTTs(true);
                    }
                    // 语音播报
                    if (XiaoYaApp.getAiuiRecognizerService() != null) {
                        XiaoYaApp.getAiuiRecognizerService().playTts("" + sqAdapterBean.getData().getQuestionList().get(questionPosition).getQuestionText());
                    }
                }

            }
        });

        // 提交完成
        mViewModel.getMtReplySuccess().observe(this, new Observer<ReplySuccessBean>() {
            @Override
            public void onChanged(ReplySuccessBean replySuccessBean) {

                if (replySuccessBean != null) {
                    Intent intent = new Intent(ScreeningContentPage.this, ScreeningFinishPage.class);
                    startActivity(intent);
                    finish();
                    LoginDialogUtil.getInstance().closeLoadingDialog();
                } else {
                    LoginDialogUtil.getInstance().closeLoadingDialog();
                    Toast.makeText(ScreeningContentPage.this, "提交失败", Toast.LENGTH_SHORT).show();
                }

            }
        });

    }

    /**
     * 回答问题
     */
    private void answerQt(int postion) {
        if (questionPosition <= sqAdapterBean.getData().getQuestionList().size()) {

            if (questionPosition >= 0) {
                mDataBinding.tvBack.setVisibility(View.VISIBLE);
            } else {
                mDataBinding.tvBack.setVisibility(View.GONE);
            }

            // 选择效果切换
            if (Integer.parseInt(sqAdapterBean.getData().getQuestionList().get(questionPosition).getQuestionType()) == 1) {//多选);
                if (sqAdapterBean.getData().getQuestionList().get(questionPosition).getAnswerList().get(postion).getStatus().equals("0")) {
                    sqAdapterBean.getData().getQuestionList().get(questionPosition).getAnswerList().get(postion).setStatus("1");
                } else {
                    sqAdapterBean.getData().getQuestionList().get(questionPosition).getAnswerList().get(postion).setStatus("0");
                }
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        sqAdapter.notifyDataSetChanged();
                    }
                });

            } else {
                // 单选移除已选
                for (int i = 0; i < sqAdapterBean.getData().getQuestionList().get(questionPosition).getAnswerList().size(); i++) {
                    sqAdapterBean.getData().getQuestionList().get(questionPosition).getAnswerList().get(i).setStatus("0");
                }
                // 重新选择
                if (sqAdapterBean.getData().getQuestionList().get(questionPosition).getAnswerList().get(postion).getStatus().equals("0")) {
                    sqAdapterBean.getData().getQuestionList().get(questionPosition).getAnswerList().get(postion).setStatus("1");
                } else {
                    sqAdapterBean.getData().getQuestionList().get(questionPosition).getAnswerList().get(postion).setStatus("0");
                }
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        sqAdapter.notifyDataSetChanged();
                    }
                });

                nextQuestion();
            }

        }
    }

    /**
     * 临时缓存
     */
    private SubmitSreeningBean submitSreeningBean = new SubmitSreeningBean();
    // 问题集合
    private List<SubmitSreeningBean.QuestionList> questionList = new ArrayList<>();

    private void saveScreeningDataList(ScreeningContentBean sqAdBean) {

        questionList.clear();

        submitSreeningBean.setPoolCode(poolCodeType);

        for (int x = 0; x < sqAdBean.getData().getQuestionList().size(); x++) {
            // 问题对象赋值
            SubmitSreeningBean.QuestionList qsBean = new SubmitSreeningBean.QuestionList();
            qsBean.setCreateBy(sqAdBean.getData().getQuestionList().get(x).getCreateBy());
            qsBean.setUpdateBy(sqAdBean.getData().getQuestionList().get(x).getUpdateBy());
            qsBean.setUpdateTime(sqAdBean.getData().getQuestionList().get(x).getUpdateTime());
            qsBean.setQuestionId(sqAdBean.getData().getQuestionList().get(x).getQuestionId());
            qsBean.setGroupId(sqAdBean.getData().getQuestionList().get(x).getGroupId());
            qsBean.setQuestionType(sqAdBean.getData().getQuestionList().get(x).getQuestionType());
            qsBean.setQuestionStemType(sqAdBean.getData().getQuestionList().get(x).getQuestionStemType());
            qsBean.setQuestionText(sqAdBean.getData().getQuestionList().get(x).getQuestionText());
            qsBean.setSort(sqAdBean.getData().getQuestionList().get(x).getSort());
            qsBean.setStatus(sqAdBean.getData().getQuestionList().get(x).getStatus());
            qsBean.setDelFlag(sqAdBean.getData().getQuestionList().get(x).getDelFlag());

            // c存答案
            List<SubmitSreeningBean.QuestionList.AnswerListDTO> answerListDTO = new ArrayList<>();

            for (int y = 0; y < sqAdBean.getData().getQuestionList().get(x).getAnswerList().size(); y++) {

                if (sqAdBean.getData().getQuestionList().get(x).getAnswerList().get(y).getStatus().equals("1")) {
                    // 答案对象赋值
                    SubmitSreeningBean.QuestionList.AnswerListDTO aswerBean = new SubmitSreeningBean.QuestionList.AnswerListDTO();
                    aswerBean.setCreateTime(sqAdBean.getData().getQuestionList().get(x).getAnswerList().get(y).getCreateTime());
                    aswerBean.setUpdateTime(sqAdBean.getData().getQuestionList().get(x).getAnswerList().get(y).getUpdateTime());
                    aswerBean.setAnswerId(sqAdBean.getData().getQuestionList().get(x).getAnswerList().get(y).getAnswerId());
                    aswerBean.setQuestionId(sqAdBean.getData().getQuestionList().get(x).getAnswerList().get(y).getQuestionId());
                    aswerBean.setAnswerType(sqAdBean.getData().getQuestionList().get(x).getAnswerList().get(y).getAnswerType());
                    aswerBean.setAnswerText(sqAdBean.getData().getQuestionList().get(x).getAnswerList().get(y).getAnswerText());
                    aswerBean.setAnswerScore(sqAdBean.getData().getQuestionList().get(x).getAnswerList().get(y).getAnswerScore());
                    aswerBean.setSort(sqAdBean.getData().getQuestionList().get(x).getAnswerList().get(y).getSort());
                    aswerBean.setStatus(sqAdBean.getData().getQuestionList().get(x).getAnswerList().get(y).getStatus());
                    aswerBean.setDelFlag(sqAdBean.getData().getQuestionList().get(x).getAnswerList().get(y).getDelFlag());

                    answerListDTO.add(aswerBean);
                }

            }

            // 有时题目为提示类型,是则不提交
            if (answerListDTO.size() > 0) {
                qsBean.setAnswerList(answerListDTO);
                // 单个问题数据保存
                questionList.add(qsBean);
            }

        }
        submitSreeningBean.setQuestionList(questionList);
        // 提交给服务端
        mViewModel.submitQuestionList(submitSreeningBean);

//        Logger.LogD("questionList", "======健康筛查00=====" + new Gson().toJson(submitSreeningBean));

    }

    /**
     * 上一题
     */
    private void backQuestion() {

        if (questionPosition > 0) {

            if (questionPosition > 1) {
                mDataBinding.tvBack.setVisibility(View.VISIBLE);
            } else {
                mDataBinding.tvBack.setVisibility(View.GONE);
            }

            // 统计显示当前进度
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    mDataBinding.tvCount.setText(questionPosition + "/" + sqAdapterBean.getData().getQuestionList().size());
                    mDataBinding.progress.setProgress(questionPosition);
                    sqAdapter.notifyDataSetChanged();
                }
            });


            myHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    questionPosition = questionPosition - 1;

                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            mDataBinding.questionTitle.setText("" + sqAdapterBean.getData().getQuestionList().get(questionPosition).getQuestionText());
                            sqAdapter.adapaterAddData(sqAdapterBean.getData().getQuestionList().get(questionPosition).getAnswerList());
                            sqAdapter.notifyDataSetChanged();
                        }
                    });

                }
            }, 200);
        }

    }

    /**
     * 切换
     * 下一题
     */
    private void nextQuestion() {

        // 统计显示当前进度
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                mDataBinding.tvCount.setText(questionPosition + 1 + "/" + sqAdapterBean.getData().getQuestionList().size());
                mDataBinding.progress.setProgress(questionPosition + 1);
            }
        });

        if (questionPosition < sqAdapterBean.getData().getQuestionList().size() - 1) {//切换题目

            myHandler.postDelayed(new Runnable() {
                @Override
                public void run() {

                    if (questionPosition + 1 >= sqAdapterBean.getData().getQuestionList().size()) {
                        return;
                    }

                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            mDataBinding.questionTitle.setText("" + sqAdapterBean.getData().getQuestionList().get(questionPosition + 1).getQuestionText());
                            sqAdapter.adapaterAddData(sqAdapterBean.getData().getQuestionList().get(questionPosition + 1).getAnswerList());
                            sqAdapter.notifyDataSetChanged();
                        }
                    });

                    questionPosition = questionPosition + 1;

                    voiceTTs();
                }
            }, 300);
        } else {
            LoginDialogUtil.getInstance().showLoadingDialog(this);
            saveScreeningDataList(sqAdapterBean);
        }
    }

    /**
     * 问答题目
     * 语音播报
     */
    private void voiceTTs() {

        myHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                // 语音播报
                if (XiaoYaApp.isAIUiFail()) {
                    Toast.makeText(ScreeningContentPage.this, "语音未授权", Toast.LENGTH_SHORT).show();
                } else {
                    if (sqAdapterBean.getData().getQuestionList().get(questionPosition).getQuestionType().equals("2")) {
                        XiaoYaApp.setOnlyPlayTTs(true);
                    }
                    // 语音播报
                    if (XiaoYaApp.getAiuiRecognizerService() != null) {
                        XiaoYaApp.getAiuiRecognizerService().playTts("" + sqAdapterBean.getData().getQuestionList().get(questionPosition).getQuestionText());
                    }
                }

            }
        }, 800);

    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void asrQuestioneAnswer(JumpBean jump) {

        for (int i = 0; i < sqAdapterBean.getData().getQuestionList().get(questionPosition).getAnswerList().size(); i++) {

            if (jump.getConn().contains(sqAdapterBean.getData().getQuestionList().get(questionPosition).getAnswerList().get(i).getAnswerText())) {
                Logger.d("==========" + jump.getConn() + "==" + questionPosition);
                answerQt(i);
            }

        }

    }

    @Override
    protected void onResume() {
        super.onResume();
        EventBus.getDefault().register(this);

    }

    @Override
    protected void onStop() {
        super.onStop();
        EventBus.getDefault().unregister(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        // 标记为页面跳转模式
        GlobalConstant.asrModule = 0;
    }

    /**
     * 初始化
     * 健康
     * 标题布局
     */
    private void initTitleLayout() {

        mDataBinding.titleLyout.tvTitle.setText("返回");

        mDataBinding.titleLyout.familyHead.setVisibility(View.GONE);
        mDataBinding.titleLyout.backArrow.setVisibility(View.VISIBLE);
        mDataBinding.titleLyout.bluth.setVisibility(View.INVISIBLE);

        GlideUtil.loadImageWithImage(mDataBinding.titleLyout.backArrow, R.drawable.back_arrow);
        //返回上一步
        mDataBinding.titleLyout.backArrowMd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }


}

4、abcd是列表

package csu.xiaoya.robotApp.ui.fragment_healthy_housekeeper.healthy_screen.screeningcn;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

import csu.xiaoya.robotApp.R;
import csu.xiaoya.robotApp.ui.fragment_healthy_housekeeper.healthy_screen.screenbean.ScreeningContentBean;

/**
 * 健康筛查a b c d选择
 * 选项适配器
 */

public class ScreeningQuestionAdapater extends RecyclerView.Adapter<ScreeningQuestionAdapater.ViewHodler> {

    private List<ScreeningContentBean.DataDTO.QuestionListDTO.AnswerListDTO> dataList;

    public ScreeningQuestionAdapater() {
        dataList = new ArrayList<>();
    }

    /**
     * 点击就监听
     */
    public interface OnItemClickListner {
        void onItemClick(View view, int postion);

        void onItemLongClick(View view, int postion);
    }

    private OnItemClickListner onItemClickListner;

    /**
     * 点击监听
     */
    public void setOnItemClickListner(OnItemClickListner listner) {
        this.onItemClickListner = listner;
    }

    public void adapaterAddData(List<ScreeningContentBean.DataDTO.QuestionListDTO.AnswerListDTO> dataList) {
        this.dataList.clear();
        this.dataList.addAll(dataList);
    }

    @Override
    public ViewHodler onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.question_item_layout, parent, false);
        ViewHodler hodler = new ViewHodler(view);
        return hodler;
    }

    @Override
    public void onBindViewHolder(final ViewHodler holder, final int position) {

        if (dataList.get(position).getStatus().equals("0")) {
            holder.textView.setBackgroundResource(R.drawable.unselect_screnning_qs_item);
        } else {
            holder.textView.setBackgroundResource(R.drawable.select_screnning_qs_item);
        }

        holder.textView.setText(dataList.get(position).getAnswerText());

        //设置点击响应
        if (onItemClickListner != null) {
            //点击
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    //获取当前屏幕上的位置,避免插入后position不对
                    int layoutPosition = holder.getLayoutPosition();
                    onItemClickListner.onItemClick(holder.itemView, layoutPosition);
                }
            });
            //长按
            holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View view) {
                    int layoutPosition = holder.getLayoutPosition();
                    onItemClickListner.onItemLongClick(holder.itemView, layoutPosition);
                    return false;
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return dataList != null ? dataList.size() : 0;
    }

    /**
     * 插入数据
     */
    public void addData(int pos) {
//        dataList.add(pos);
        dataList.add("Insert One");
//        notifyItemInserted(pos);
    }

    /**
     * 移除数据
     */
    public void deleData(int pos) {
        dataList.remove(pos);
        notifyItemRemoved(pos);
    }

    /**
     * viewHolder
     */
    public static class ViewHodler extends RecyclerView.ViewHolder {
        TextView textView;

        public ViewHodler(View itemView) {
            super(itemView);
            textView = (TextView) itemView.findViewById(R.id.tvContent);
        }
    }

}

5、handler工具

package csu.xiaoya.robotApp.util;

import android.os.Handler;
import android.os.Message;

import java.lang.ref.WeakReference;

import csu.xiaoya.robotApp.util.log.Logger;

public class HandlerUtils {

    private HandlerUtils() {
        throw new UnsupportedOperationException("u can't instantiate me...");
    }

    public static class HandlerHolder extends Handler {
        WeakReference<OnReceiveMessageListener> mListenerWeakReference;

        /**
         * 使用必读:推荐在Activity或者Activity内部持有类中实现该接口,不要使用匿名类,可能会被GC
         *
         * @param listener 收到消息回调接口
         */
        public HandlerHolder(OnReceiveMessageListener listener) {
            mListenerWeakReference = new WeakReference<>(listener);
        }

        @Override
        public void handleMessage(Message msg) {
            Logger.d("==没有更多消息=="+(mListenerWeakReference != null)+"===="+(mListenerWeakReference.get() != null));
            if (mListenerWeakReference != null && mListenerWeakReference.get() != null) {
                mListenerWeakReference.get().handlerMessage(msg);
            }
        }
    }

    /**
     * 收到消息回调接口
     */
    public interface OnReceiveMessageListener {
        void handlerMessage(Message msg);
    }

}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2246353.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

基于Java Springboot高校工作室管理系统

一、作品包含 源码数据库设计文档万字PPT全套环境和工具资源部署教程 二、项目技术 前端技术&#xff1a;Html、Css、Js、Vue、Element-ui 数据库&#xff1a;MySQL 后端技术&#xff1a;Java、Spring Boot、MyBatis 三、运行环境 开发工具&#xff1a;IDEA/eclipse 数据…

React(二)

文章目录 项目地址七、数据流7.1 子组件传递数据给父组件7.1.1 方式一:給父设置回调函数,传递给子7.1.2 方式二:直接将父的setState传递给子7.2 给props传递jsx7.2.1 方式一:直接传递组件给子类7.2.2 方式二:传递函数给子组件7.3 props类型验证7.4 props的多层传递7.5 cla…

浅谈丨功能安全测试,汽车的守护者

随着新能源汽车迅猛的发展&#xff0c;各类车型频频面世&#xff0c;同时辅助驾驶/自动驾驶等智驾功能也在不断迭代&#xff0c;使得整个汽车系统的复杂性越来越高&#xff0c;最终导致消费者不得不对如今的汽车质量和安全性提出质疑。 如何打破质疑&#xff1f; 那就不得不搬…

bridge-multicast-igmpsnooping

# 1.topo # 2.创建命名空间 ip netns add ns0 ip netns add ns1 ip netns add ns2 ip netns add ns3 # 3.创建veth设备 ip link add ns0-veth0 type veth peer name hn0-veth0 ip link add ns1-veth0 type veth peer name hn1-veth0 ip link add ns2-veth0 type veth pe…

密码学11

概论 计算机安全的最核心三个关键目标&#xff08;指标&#xff09;/为&#xff1a;保密性 Confidentiality、完整性 Integrity、可用性 Availability &#xff0c;三者称为 CIA三元组 数据保密性&#xff1a;确保隐私或是秘密信息不向非授权者泄漏&#xff0c;也不被非授权者使…

MIT 6.S081 | 操作系统 | Lab1: Xv6 and Unix utilities

Lab1: Xv6 and Unix utilities 文章目录 Lab1: Xv6 and Unix utilities实验任务1.启动XV6(easy)2.Sleep(easy)-练手的&#xff0c;就是熟悉一下怎么在xv6项目中加.c文件&#xff0c;生成可执行程序并进行测试的1.解析rm.c2.argc 如何被赋值3.Sleep代码4.makefile编辑5.通过make…

在SpringBoot项目中集成MongoDB

文章目录 1. 准备工作2. 在SpringBoot项目中集成MongoDB2.1 引入依赖2.2 编写配置文件2.3 实体类 3. 测试4. 文档操作4.1 插入操作4.1.1 单次插入4.1.2 批量插入 4.2 查询操作4.2.1 根据id查询4.2.2 根据特定条件查询4.2.3 正则查询4.2.4 查询所有文档4.2.5 排序后返回 4.3 删除…

美团-Leaf ID算法集成到SpringBoot项目

提前准备 下载源码 GitHub地址&#xff1a;https://github.com/Meituan-Dianping/Leaf 下载下来 然后 maven install 安装到本地仓库 再需要用到该ID算法的项目中引入 以下内容 <!-- 本地仓库中的Leaf --> <dependency><artifactId>leaf-boot-starte…

AI+若依框架项目

基础应用篇 1.若依搭建 技术选型 RuoYi-Vue版本&#xff0c;采用了前后端分离的单体架构设计&#xff1a; 软件环境&#xff1a;JDK、MySQL 、Redis 、Maven、Node 技术选型&#xff1a;Spring Boot、Spring Security、MyBatis、Jwt、V 官方推荐 课程版本 JDK > 1.8 …

RabbitMQ高可用延迟消息惰性队列

目录 生产者确认 消息持久化 消费者确认 TTL延迟队列 TTL延迟消息 惰性队列 生产者确认 生产者确认就是&#xff1a;发送消息的人&#xff0c;要确保消息发送给了消息队列&#xff0c;分别是确保到了交换机&#xff0c;确保到了消息队列这两步。 1、在发送消息服务的ap…

将django+vue项目发布部署到服务器

1.部署django后端服务 部署架构 1.1 下载依赖插件 pip3.8 freeze > requirements.txt1.2 安装依赖插件 pip3 install -r requirements.txt1.3 安装mysql数据库 apt install mysql-server初始化数据库 CREATE USER admin% IDENTIFIED WITH mysql_native_password BY 123…

论文阅读:SIMBA: single-cell embedding along with features

Chen, H., Ryu, J., Vinyard, M.E. et al. SIMBA: single-cell embedding along with features. Nat Methods 21, 1003–1013 (2024). 论文地址&#xff1a;https://doi.org/10.1038/s41592-023-01899-8 代码地址&#xff1a;https://github.com/pinellolab/simba. 摘要 大多…

商业物联网:拥抱生产力的未来

在现代商业格局中&#xff0c;数据占据至高无上的地位。物联网&#xff08;IoT&#xff09;站在这场数字革命的前沿&#xff0c;将以往模糊不清的不确定因素转变为可衡量、可付诸行动的深刻见解。物联网技术为日常物品配备传感器与连接功能&#xff0c;使其能够实时收集并传输数…

【FRP 内网穿透 从0到1 那些注意事项】

【摘要】 最近跟第三方团队调试问题&#xff0c;遇到一个比较烦的操作。就是&#xff0c;你必须要发个版到公网环境&#xff0c;他们才能链接到你的接口地址&#xff0c;才能进行调试。按理说&#xff0c;也没啥&#xff0c;就是费点时间。但是&#xff0c;在调试的时候&#…

最新Kali安装详细版教程(附安装包,傻瓜式安装教程)

本文主要详细介绍 kali 的安装过程&#xff0c;以及安装完成后的基本设置&#xff0c;比如安装增强工具&#xff0c;安装中文输入法以及更新升级等操作。 文章目录 实验环境准备工作步骤说明安装虚拟机安装 Kali安装增强工具安装中文输入法更新升级 实验环境 VMware &#x…

【山大909算法题】2014-T1

文章目录 1.原题2.算法思想3.关键代码4.完整代码5.运行结果 1.原题 为带表头的单链表类Chain编写一个成员函数Reverse&#xff0c;该函数对链表进行逆序操作&#xff08;将链表中的结点按与原序相反的顺序连接&#xff09;&#xff0c;要求逆序操作就地进行&#xff0c;不分配…

论文浅尝 | MindMap:知识图谱提示激发大型语言模型中的思维图(ACL2024)

笔记整理&#xff1a;和东顺&#xff0c;天津大学硕士&#xff0c;研究方向为软件缺陷分析 论文链接&#xff1a;https://aclanthology.org/2024.acl-long.558/ 发表会议&#xff1a;ACL 2024 1. 动机 虽然大语言模型&#xff08;LLMs&#xff09;已经在自然语言理解和生成任务…

Win11 22H2/23H2系统11月可选更新KB5046732发布!

系统之家11月22日报道&#xff0c;微软针对Win11 22H2/23H2版本推送了2024年11月最新可选更新补丁KB5046732&#xff0c;更新后&#xff0c;系统版本号升至22621.4541和22631.4541。本次更新后系统托盘能够显示缩短的日期和时间&#xff0c;文件资源管理器窗口很小时搜索框被切…

SpringSecurity创建一个简单的自定义表单的认证应用

1、SpringSecurity 自定义表单 在 Spring Security 中创建自定义表单认证应用是一个常见的需求&#xff0c;特别是在需要自定义登录页面、认证逻辑或添加额外的表单字段时。以下是一个详细的步骤指南&#xff0c;帮助你创建一个自定义表单认证应用。 2、基于 SpringSecurity 的…

Cloud Native 云原生后端的开发注意事项

在云原生后端开发里&#xff0c;数据管理和存储这块得好好弄。数据库选型得综合考虑&#xff0c;像关系型数据有复杂查询需求就选 MySQL、PostgreSQL&#xff0c;海量非结构化数据就可以考虑 MongoDB、Cassandra 这些。设计数据库得遵循规范化原则&#xff0c;像设计电商订单表…