android 实现答题功能

一、效果

二、实现思路

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><LinearLayoutandroid:layout_width="@dimen/dp_640"android:layout_height="@dimen/dp_400"android:background="@color/pageBgColor"android:orientation="vertical"><!--  返回模块 --><includeandroid:id="@+id/titleLyout"layout="@layout/chart_top_title_layout" /><!-- 内容 --><RelativeLayoutandroid:layout_width="wrap_content"android:layout_height="@dimen/dp_300"android:paddingTop="@dimen/dp_15"><TextViewandroid: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.RecyclerViewandroid: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" /><!-- 再听一遍 --><LinearLayoutandroid: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"><LinearLayoutandroid: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"><ImageViewandroid:layout_width="@dimen/dp_30"android:layout_height="@dimen/dp_25"android:src="@drawable/voice_pic" /></LinearLayout><TextViewandroid: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><TextViewandroid: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" /><TextViewandroid: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><!-- 底部进度布局 --><LinearLayoutandroid:layout_width="match_parent"android:layout_height="@dimen/dp_60"android:orientation="vertical"><TextViewandroid: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" /><ProgressBarandroid: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><RelativeLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="@dimen/dp_10"><!-- screnning_question_item --><TextViewandroid: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 {// handlerprivate HandlerUtils.HandlerHolder myHandler;@Overrideprotected void onCreate(@Nullable Bundle savedInstanceState) {super.onCreate(savedInstanceState);ActivityUtil.getInstance().addActivity(ScreeningContentPage.this);}private int selectModuleId = 0;private int poolCodeType = 0;@Overrideprotected void handleIntent(Intent intent) {super.handleIntent(intent);selectModuleId = Integer.parseInt(intent.getSerializableExtra("selectModuleId").toString());poolCodeType = Integer.parseInt(intent.getSerializableExtra("poolCodeType").toString());Logger.d("======健康筛查内容=====" + selectModuleId);}@Overrideprotected int getLayoutResId() {return R.layout.screening_content_layout;}@Overrideprotected void initViewModel() {}@Overridepublic void handlerMessage(Message msg) {// 刷新列表Logger.d("======没有更多消息======" + questionPosition);}@Overrideprotected void bindViewModel() {mViewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(ScreeningContentViewmodle.class);}@Overrideprotected 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() {@Overridepublic 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() {@Overridepublic void run() {Toast.makeText(ScreeningContentPage.this, "至少选择一个答案", Toast.LENGTH_SHORT).show();}});}}}});// 问答数据集合mViewModel.getScreeningContentBeanLivewDt().observe(this, new Observer<ScreeningContentBean>() {@Overridepublic 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() {@Overridepublic void onItemClick(View view, int postion) {answerQt(postion);}@Overridepublic void onItemLongClick(View view, int postion) {}});// 上一个mDataBinding.tvBack.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {backQuestion();}});// 重复播放ttsmDataBinding.repeatTts.setOnClickListener(new View.OnClickListener() {@Overridepublic 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>() {@Overridepublic 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() {@Overridepublic 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() {@Overridepublic 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() {@Overridepublic void run() {mDataBinding.tvCount.setText(questionPosition + "/" + sqAdapterBean.getData().getQuestionList().size());mDataBinding.progress.setProgress(questionPosition);sqAdapter.notifyDataSetChanged();}});myHandler.postDelayed(new Runnable() {@Overridepublic void run() {questionPosition = questionPosition - 1;runOnUiThread(new Runnable() {@Overridepublic 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() {@Overridepublic 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() {@Overridepublic void run() {if (questionPosition + 1 >= sqAdapterBean.getData().getQuestionList().size()) {return;}runOnUiThread(new Runnable() {@Overridepublic 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() {@Overridepublic 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);}}}@Overrideprotected void onResume() {super.onResume();EventBus.getDefault().register(this);}@Overrideprotected void onStop() {super.onStop();EventBus.getDefault().unregister(this);}@Overrideprotected 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() {@Overridepublic 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);}@Overridepublic 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;}@Overridepublic 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() {@Overridepublic void onClick(View view) {//获取当前屏幕上的位置,避免插入后position不对int layoutPosition = holder.getLayoutPosition();onItemClickListner.onItemClick(holder.itemView, layoutPosition);}});//长按holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {@Overridepublic boolean onLongClick(View view) {int layoutPosition = holder.getLayoutPosition();onItemClickListner.onItemLongClick(holder.itemView, layoutPosition);return false;}});}}@Overridepublic 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);}@Overridepublic 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.mzph.cn/news/886982.shtml

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

相关文章

正排索引和倒排索引

一、简介 正排索引&#xff1a;一个未经处理的数据库中&#xff0c;一般是以文档ID作为索引&#xff0c;以文档内容作为记录。 倒排索引&#xff1a;Inverted index&#xff0c;指的是将单词或记录作为索引&#xff0c;将文档ID作为记录&#xff0c;这样便可以方便地通过单词或…

Django一分钟:django中收集关联对象关联数据的方法

场景&#xff1a;我有一个模型&#xff0c;被其它多个模型关联&#xff0c;我配置了CASCADE级联删除&#xff0c;我想要告知用户删除该实例之后&#xff0c;哪些关联数据将会被一同删除。 假设我们当前有这样一组模型&#xff1a; class Warehouse(models.Model):""…

卷积神经网络各层介绍

目录 1 卷积层 2 BN层 3 激活层 3.1 ReLU&#xff08;Rectified Linear Unit&#xff09; 3.2 sigmoid 3.3 tanh&#xff08;双曲正切&#xff09; 3.4 Softmax 4 池化层 5 全连接层 6 模型例子 1 卷积层 卷积是使用一个卷积核&#xff08;滤波器&#xff09;对矩阵进…

【工控】线扫相机小结 第四篇

背景 这一片主要是对第三篇继续补充。话说上一篇讲到了两种模式的切换&#xff0c;上一篇还遗留了一个Bug&#xff0c;在这一篇里进行订正&#xff01; 代码回顾 /// <summary>/// 其实就是打开触发/// </summary>void SetLineSacanWorkMode(){-----首先设置为帧…

AI 大模型重塑软件开发的未来

✅作者简介&#xff1a;2022年博客新星 第八。热爱国学的Java后端开发者&#xff0c;修心和技术同步精进。 &#x1f34e;个人主页&#xff1a;Java Fans的博客 &#x1f34a;个人信条&#xff1a;不迁怒&#xff0c;不贰过。小知识&#xff0c;大智慧。 &#x1f49e;当前专栏…

【软考】系统架构设计师-计算机系统基础(4):计算机网络

计算机网络功能&#xff1a;数据通信、资源共享、管理集中化、分布式处理、负载均衡 5G高峰速率&#xff1a;10Gbit/s 广域网&#xff08;因特网&#xff09;/城域网/局域网&#xff08;以太网&#xff09; 总线型&#xff1a;利用率低&#xff0c;易冲突&#xff0c;干扰大…

Ultiverse 和web3新玩法?AI和GameFi的结合是怎样

Gamef 和 AI 是我们这个周期十分看好两大赛道之一&#xff0c;(Gamef 拥有极强的破圈效应&#xff0c;引领 Web2 用户进军 Web3 最佳利器。AI是这个周期最热门赛道&#xff0c;无论 Web2的 OpenAl&#xff0c;还是 Web3&#xff0c;都成为话题热议焦点。那么结合 GamefiA1双叙事…

Matlab多输入单输出之倾斜手写数字识别

本文主要介绍使用matlab构建多输入单输出的网络架构&#xff0c;来实现倾斜的手写数字识别&#xff0c;使用concatenationLayer来拼接特征&#xff0c;实现网络输入多个特征。 1.加载训练数据 加载数据&#xff1a;手写数字的图像、真实数字标签和数字顺时针旋转的角度。 lo…

R | 统一栅格数据的坐标系、分辨率和行列号

各位同学&#xff0c;在做相关性等分析时&#xff0c;经常会遇到各栅格数据间的行列号不统一等问题&#xff0c;下面的代码能直接解决这类麻烦。以某个栅格数据的坐标系、分辨率和行列号为准&#xff0c;统一文件夹内所有栅格并输出到新的文件夹。 代码只需要更改输入输出和ti…

UE5 第一人称射击项目学习(完结)

这个项目几乎完结了。 也算我上手的第一个纯蓝图小项目。 现在只剩下缝缝补补了。 之前把子弹设计为蓝图&#xff0c;这里要引入C的面向对象思想&#xff0c;建立成员函数。 首先双击打开子弹的蓝图 这边就可以构造成员函数 写一个print your name 在这里生成成员函数后&am…

三相正弦交流电的相序:揭秘正相序与反相序的奥秘

在电力系统中&#xff0c;三相正弦交流电的应用无处不在&#xff0c;从家庭用电到大型工业设备&#xff0c;都离不开它的稳定供电。然而&#xff0c;在三相交流电中&#xff0c;有一个概念常常让初学者感到困惑&#xff0c;那就是“相序”。今天&#xff0c;我们就来深入探讨一…

力扣面试题 - 24 插入

题目&#xff1a; 给定两个整型数字 N 与 M&#xff0c;以及表示比特位置的 i 与 j&#xff08;i < j&#xff0c;且从 0 位开始计算&#xff09;。 编写一种方法&#xff0c;使 M 对应的二进制数字插入 N 对应的二进制数字的第 i ~ j 位区域&#xff0c;不足之处用 0 补齐…

华为云容器监控平台

首先搜索CCE,点击云容器引擎CCE 有不同的测试&#xff0c;生产&#xff0c;正式环境 工作负载--直接查询服务名看监控 数据库都是走的一个 Redis的查看

Spring Cloud Stream实现数据流处理

1.什么是Spring Cloud Stream&#xff1f; 我看很多回答都是“为了屏蔽消息队列的差异&#xff0c;使我们在使用消息队列的时候能够用统一的一套API&#xff0c;无需关心具体的消息队列实现”。 这样理解是有些不全面的&#xff0c;Spring Cloud Stream的核心是Stream&#xf…

Notepad++--在开头快速添加行号

原文网址&#xff1a;Notepad--在开头快速添加行号_IT利刃出鞘的博客-CSDN博客 简介 本文介绍Notepad怎样在开头快速添加行号。 需求 原文件 想要的效果 方法 1.添加点号 Alt鼠标左键&#xff0c;从首行选中首列下拉&#xff0c;选中需要添加序号的所有行的首列&#xff…

【ROS2】多传感器融合、实现精准定位:robot_localization

1、简述 robot_localization在SLAM建图、导航中常用于将多个传感器融合(IMU、里程计、深度相机、GPS等),以提高定位精度,为机器人提供了在三维空间中的非线性状态估计 robot_localization包含两个状态估计节点: ekf_localization_node:扩展卡尔曼滤波(EKF),缺点是非…

【智谱开放平台-注册_登录安全分析报告】

前言 由于网站注册入口容易被机器执行自动化程序攻击&#xff0c;存在如下风险&#xff1a; 暴力破解密码&#xff0c;造成用户信息泄露&#xff0c;不符合国家等级保护的要求。短信盗刷带来的拒绝服务风险 &#xff0c;造成用户无法登陆、注册&#xff0c;大量收到垃圾短信的…

永夜星河主题特效2(星河背景 + 闪烁文字+点击星星 + 文字弹出特效)

目录 图片展示 星河背景 闪烁文字点击星星 文字弹出特效 特效介绍&#xff1a; 使用方式&#xff1a; 图片展示 星河背景 闪烁文字点击星星 文字弹出特效 <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8">&l…

SAP Ariba Contracts_Author the Main Agreement

SAP Ariba Contracts_Author the Main Agreement Workspace Documents 从SAP Ariba 项目模板中继承的文档将自动出现在控件的“文档”选项卡中项目&#xff0c;Workspace Documents 管理所有合同相关文件的地方&#xff0c;如主要协议&#xff0c;附录&#xff0c;合同条款等…

C++练习题(5)

//函数打印素数 #include <iostream> using namespace std; int is_prime(int n){ for(int j2;j<n;j){ if(n%j0) return 0; } return 1; } int main(){ int i0; for(int i100;i<200;i){ if(is_prime(i)1) pr…