如果/其他条件,则具有壁炉值


public class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.SearchViewHolder> 
{
    Context context;
    ArrayList<String> studentNameList;
    ArrayList<String> studentMatrikList;
    ArrayList<String> studentPhoneList;
    ArrayList<String> studentAddressList;
    ArrayList<String> studentStatusList;
    ArrayList<String> studentMailList;
    ArrayList<String> studentConList;
    ArrayList<String> studentIdList;
    class SearchViewHolder extends RecyclerView.ViewHolder{
       TextView studentName, studentMatrik, studentPhone, studentAddress, studentStatus, studentMail, studentCon, studentId, Check;
       CheckBox checkBox;
       Button buttonMap;
       DatabaseReference databaseReference;
       public SearchViewHolder(View itemView) {
          super(itemView);
          studentName = (TextView) itemView.findViewById(R.id.studentName);
          studentMatrik = (TextView) itemView.findViewById(R.id.studentMatrik);
          studentPhone = (TextView) itemView.findViewById(R.id.studentPhone);
          studentAddress = (TextView) itemView.findViewById(R.id.studentAddress);
          studentStatus = (TextView) itemView.findViewById(R.id.studentStatus);
          studentMail = (TextView) itemView.findViewById(R.id.studentMail);
          studentCon = (TextView) itemView.findViewById(R.id.studentCon);
          studentId = (TextView) itemView.findViewById(R.id.studentId);
          checkBox = (CheckBox) itemView.findViewById(R.id.checkBox);
          String name = studentName.getText().toString();
          if(name.equals("a")){
            checkBox.setChecked(true);
          }else{
            checkBox.setChecked(false);
          }
          buttonMap = (Button) itemView.findViewById(R.id.buttonMap);
          buttonMap.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, MapsViewActivity.class);
                intent.putExtra("Latitude",studentMail.getText().toString());
                intent.putExtra("Longitude",studentCon.getText().toString());
                intent.putExtra("Address",studentAddress.getText().toString());
                context.startActivity(intent);
            }
        });
        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
                if (isChecked) {
                    String id = studentId.getText().toString();
                    databaseReference = FirebaseDatabase.getInstance().getReference("student");
                    String name = "Check";
                    databaseReference.child(id).child("stat").setValue(name);
                    notifyDataSetChanged();
                } else {
                    String id = studentId.getText().toString();
                    databaseReference = FirebaseDatabase.getInstance().getReference("student");
                    String name = "Not Check";
                    databaseReference.child(id).child("stat").setValue(name);
                    notifyDataSetChanged();
                }
            }
        });
    }

我从Firebase检索所有数据到RecyClerview TextView ItemView。当我尝试适配器中的if/else条件时,它会与XML中的文本视图Android:文本进行比较,而不是firebase数据值。为什么会发生这种情况?

studentName = (TextView) itemView.findViewById(R.id.studentName);
        String name = studentName.getText().toString();
        if(name.equals("a")){
            checkBox.setChecked(true);
        }else{
            checkBox.setChecked(false);
        }

它与textview android:xml中的文本相比,而不是firebase值...

<TextView
    android:id="@+id/studentName"
    android:layout_width="205dp"
    android:layout_height="wrap_content"
    android:text="Name goes here"
    android:textColor="#212121"
    android:textSize="15sp" />

您必须先在firebase收到的文本视图上设置值。其他明智的选择将继续以XML中的默认值获得值。

相关内容

  • 没有找到相关文章

最新更新