Я создал список, в который я хочу поместить все извлеченные данные в соответствии с результатом предыдущих значений активности. Например, у меня есть Spinner и Edittext, а затем кнопка поиска.
Результат будет соответствовать значению счетчика и редактировать текстовое значение. Но это не придет. Пожалуйста помоги. Ниже моего класса Test с его файлом макета (здесь представлен спиннер и текст редактирования) и действием SearchResults и Useradapter (класс модели)
Test. java
public class Test extends AppCompatActivity {
Spinner sp;
EditText e1;
Button logout, searchuser;
FirebaseAuth firebaseAuth;
FirebaseUser firebaseUser;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_home);
logout = (Button)findViewById(R.id.logout);
searchuser = (Button)findViewById(R.id.searchbutt1);
sp = (Spinner)findViewById(R.id.selectblood) ;
e1 = (EditText)findViewById(R.id.searchpin);
firebaseAuth = FirebaseAuth.getInstance();
firebaseUser = firebaseAuth.getCurrentUser();
final String[] bloodgroups = new String[]{"A+","A-", "B+", "B-","O+", "O-", "AB+", "AB-"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, bloodgroups);
sp.setAdapter(adapter);
searchuser.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String bloods = sp.getSelectedItem().toString();
String pin1 = e1.getText().toString();
Intent intent = new Intent(Test.this, Searchresults.class);
intent.putExtra("bloods", bloods);
intent.putExtra("pin1", pin1);
startActivity(intent);
}
});
logout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AlertDialog.Builder alert = new AlertDialog.Builder(Test.this);
alert.setMessage("Are you Sure?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
FirebaseAuth.getInstance().signOut();
Intent i = new Intent(getApplicationContext(), SignupPage.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(i);
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog dialogg = alert.create();
dialogg.show();
}
});
}
}
Файл макета (Fragmenthome. xml)
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/button">
<ImageView
android:id="@+id/imageView3"
android:layout_width="match_parent"
android:layout_height="400dp"
android:src="@drawable/bloodimage"
app:layout_constraintBottom_toTopOf="@+id/cardView2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.32999998" />
<androidx.cardview.widget.CardView
android:id="@+id/cardView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
app:cardCornerRadius="15dp"
app:cardElevation="4dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.7">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="20dp">
<Spinner
android:id="@+id/selectblood"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/searchpin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Pincode"
android:inputType="number"/>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
<Button
android:id="@+id/searchbutt1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginEnd="40dp"
android:background="@drawable/buttonpressed"
android:text="Search"
android:textColor="#ffffff"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/cardView2"
app:layout_constraintVertical_bias="0.32" />
<Button
android:id="@+id/logout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginEnd="40dp"
android:background="@drawable/buttonpressed"
android:text="Logout"
android:textColor="#ffffff"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/searchbutt1" />
Результаты поиска Действия
public class Searchresults extends AppCompatActivity {
String pinfin;
String bloodfin;
ArrayList<String> donorList;
ListView listView;
ArrayAdapter<String> arrayAdapter;
public static ArrayList<UserAdapter> donorInfo;
DatabaseReference myRef;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_searchresults);
Bundle extras = getIntent().getExtras();
bloodfin = extras.getString("bloods");
pinfin = extras.getString("pin1");
donorList = new ArrayList<>();
donorInfo = new ArrayList<>();
listView = (ListView) findViewById(R.id.list_donor);
arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item,
donorList);
listView.setAdapter(arrayAdapter);
myRef = FirebaseDatabase.getInstance().getReference("Users");
myRef.child(bloodfin).child(pinfin).addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
UserAdapter donor = dataSnapshot.getValue(UserAdapter.class);
donorInfo.add(donor);
assert donor != null;
String donorInfo = donor.namefin + " \n" + donor.gender + " \n" + donor.phonefin + " \n" + donor.addfin + " \n" + donor.bloodfin ;
donorList.add(donorInfo);
arrayAdapter.notifyDataSetChanged();
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(Searchresults.this, databaseError.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
}
Класс UserAdapter
public class UserAdapter {
public String email, namefin, addfin, statefin, phonefin, pinfin, bloodfin, gender;
public UserAdapter(String email, String namefin, String addfin, String statefin, String pinfin, String phonefin, String bloodfin, String gender) {
this.email = email;
this.namefin = namefin;
this.addfin = addfin;
this.statefin = statefin;
this.phonefin = phonefin;
this.pinfin = pinfin;
this.bloodfin = bloodfin;
this.gender = gender;
}
public String getEmail() {
return email;
}
public String getNamefin() {
return namefin;
}
public String getAddfin() {
return addfin;
}
public String getStatefin() {
return statefin;
}
public String getPhonefin() {
return phonefin;
}
public String getPinfin() {
return pinfin;
}
public String getBloodfin() {
return bloodfin;
}
public String getGender() {
return gender;
}
public void setEmail(String email) {
this.email = email;
}
public void setNamefin(String namefin) {
this.namefin = namefin;
}
public void setAddfin(String addfin) {
this.addfin = addfin;
}
public void setStatefin(String statefin) {
this.statefin = statefin;
}
public void setPhonefin(String phonefin) {
this.phonefin = phonefin;
}
public void setPinfin(String pinfin) {
this.pinfin = pinfin;
}
public void setBloodfin(String bloodfin) {
this.bloodfin = bloodfin;
}
public void setGender(String gender) {
this.gender = gender;
}
}