日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > Android >内容正文

Android

android 多个按钮响应,处理Android Recyclerview中的多个按钮单击并将响应存储在Array或ArrayList中...

發(fā)布時(shí)間:2023/12/10 Android 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android 多个按钮响应,处理Android Recyclerview中的多个按钮单击并将响应存储在Array或ArrayList中... 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

我正在設(shè)計(jì)在線測(cè)驗(yàn)App。我設(shè)計(jì)了PlayQuiz.java文件如下:

public class PlayQuiz extends AppCompatActivity {

private RecyclerView recyclerView;

DataBaseHelper database;

private List quizList;

private QuizAdapter adapter;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_play_quiz);

Toolbar toolbar = findViewById(R.id.toolbar);

setSupportActionBar(toolbar);

recyclerView=(RecyclerView)findViewById(R.id.recycler_view_quiz_display);

database= new DataBaseHelper(PlayQuiz.this);

quizList= database.fillObjQuesList();

adapter=new QuizAdapter(quizList,getApplicationContext());

RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());

recyclerView.setLayoutManager(mLayoutManager);

recyclerView.setItemAnimator(new DefaultItemAnimator());

recyclerView.setAdapter(adapter);

});

}

}

現(xiàn)在,這是我的QuizAdapter.java文件

public class QuizAdapter extends RecyclerView.Adapter{

private List questionList;

private Context context;

public QuizAdapter(List questionList, Context context) {

this.questionList = questionList;

this.context = context;

}

@NonNull

@Override

public CustomViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

View itemView= LayoutInflater.from(parent.getContext()).inflate(R.layout.quiz_display_format,parent,false);

return new CustomViewHolder(itemView);

}

@Override

public void onBindViewHolder(@NonNull final CustomViewHolder holder, final int position) {

DmQuiz questionsList=questionList.get(position);

holder.tvquestion.getLayoutParams().width= LinearLayout.LayoutParams.WRAP_CONTENT;

holder.tvquestion.setText(questionsList.getQuestion());

holder.optA.setText(questionsList.getOpta());

holder.optB.setText(questionsList.getOptb());

holder.optC.setText(questionsList.getOptc());

holder.optD.setText(questionsList.getOptd());

holder.optA.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

holder.optA.setBackgroundColor(context.getResources().getColor(R.color.colorButton));

holder.optA.setBackgroundResource(R.drawable.button_border); holder.optB.setBackgroundResource(R.drawable.button_border_unselected); holder.optC.setBackgroundResource(R.drawable.button_border_unselected); holder.optD.setBackgroundResource(R.drawable.button_border_unselected);

}

});

holder.optB.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

holder.optA.setBackgroundResource(R.drawable.button_border_unselected);

holder.optB.setBackgroundResource(R.drawable.button_border);

holder.optC.setBackgroundResource(R.drawable.button_border_unselected);

holder.optD.setBackgroundResource(R.drawable.button_border_unselected);

}

});

holder.optC.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

holder.optA.setBackgroundResource(R.drawable.button_border_unselected);

holder.optB.setBackgroundResource(R.drawable.button_border_unselected);

holder.optC.setBackgroundResource(R.drawable.button_border);

holder.optD.setBackgroundResource(R.drawable.button_border_unselected);

}

});

holder.optD.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

holder.optA.setBackgroundResource(R.drawable.button_border_unselected);

holder.optB.setBackgroundResource(R.drawable.button_border_unselected);

holder.optC.setBackgroundResource(R.drawable.button_border_unselected);

holder.optD.setBackgroundResource(R.drawable.button_border);

}

});

holder.tvClear.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

holder.optA.setBackgroundResource(R.drawable.button_border_unselected);

holder.optB.setBackgroundResource(R.drawable.button_border_unselected);

holder.optC.setBackgroundResource(R.drawable.button_border_unselected);

holder.optD.setBackgroundResource(R.drawable.button_border_unselected);

}

});

}

@Override

public int getItemCount() {

return questionList.size();

}

public class CustomViewHolder extends RecyclerView.ViewHolder{

TextView tvquestion, tvClear;

Button optA,optB,optC,optD;

public CustomViewHolder(View itemView) {

super(itemView);

tvquestion=(TextView)itemView.findViewById(R.id.tvQuestion);

optA=(Button)itemView.findViewById(R.id.button1);

optB=(Button)itemView.findViewById(R.id.button2);

optC=(Button)itemView.findViewById(R.id.button3);

optD=(Button)itemView.findViewById(R.id.button4);

tvClear=(TextView)itemView.findViewById(R.id.tvClear);

}

}

public QuizAdapter(List questionList)

{

this.questionList=questionList;

}

public void setSearchOperation(List newList){

questionList= new ArrayList<>();

questionList.addAll(newList);

notifyDataSetChanged();

}

}

Recyclerview中的數(shù)據(jù)正在從SQLite數(shù)據(jù)庫(kù)中顯示。

現(xiàn)在我想處理/存儲(chǔ)多個(gè)按鈕上的點(diǎn)擊并將其發(fā)送到遠(yuǎn)程MySql服務(wù)器。我很困惑,如何存儲(chǔ)不同問題的回復(fù)?我應(yīng)該使用ArrayList或其他東西,請(qǐng)幫助......

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)

總結(jié)

以上是生活随笔為你收集整理的android 多个按钮响应,处理Android Recyclerview中的多个按钮单击并将响应存储在Array或ArrayList中...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。