Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
227 views
in Technique[技术] by (71.8m points)

android - I want to do a task if a specific option of arraylist is clicked

I want to do something when a specific part of the array list is clicked. I added the list on bind view holder and after clicking it, it runs a specific void. But, after clicking one part of the list, and after clicking the after click list, I want to do a specific function if a specific thing was clicked on the first one. I tried if(i == 2) but it doesn't work because it takes the position of the list after clicking (the second one)

Here's My Code:


  public void onBindViewHolder(@NonNull HolderAdapterQuestionList holder, int i) {
            holder.tvName.setText(strings.get(i));
            holder.tvName.setTextSize(14f);
            if (string.equalsIgnoreCase("subject")) {
                holder.img.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.
                        subjects));
            }
            if (string.equalsIgnoreCase("class")) {
                holder.img.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.
                        subjects));
            }
            if (string.contains("topic")) {
                holder.img.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.topic));
            }

            holder.llSublist.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {


                   if(string.contains("class")){
                       subjectApi();

                   }
                   else{
                       if(i==0){
                           Toast.makeText(mContext, "Finally!", Toast.LENGTH_SHORT).show();
                       }
                       else{
                           Intent intent = new Intent(SubjectsActivity.this,PaymentActivity.class);
                           startActivity(intent);

                       }


                   }


                }
            });

and here's my list code:


 void classApi() {
        tvNoRecord.setVisibility(View.GONE);
        ArrayList<String> arrayList = new ArrayList<>();
        ArrayList<String> arrayListId = new ArrayList<>();

        tvHeader.setText("Choose Class");
        arrayList.add("5th Class");
        arrayList.add("6th Class");
        arrayList.add("7th Class");
        arrayList.add("8th Class");
        arrayList.add("9th Class");
        arrayList.add("10th Class");
        arrayList.add("11th Class");
        arrayList.add("12th Class");
        AdapterSubjectList adapterSubjectList = new AdapterSubjectList(arrayList, arrayListId, "class");
        rvVideos.setLayoutManager(new LinearLayoutManager(mContext));
        rvVideos.setAdapter(adapterSubjectList);
        ProjectUtils.pauseProgressDialog();



    }



In Simple, after you checked the code, the first list of classes come and the second list of subjects after clicking it. I want to do a specific function after clicking something on the subject list if a specific class was selected.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...