Я подаю заявку в банк крови с базой данных пожарных. я хочу получить мои данные с помощью двух счетчиков для правильной группы крови и местоположения человека, который использует мое приложение. Я использовал много методов, чтобы дио эту вещь, но я терпел неудачу каждый раз. на этот раз вы хотите исправить это для общества.
, и я сделал индекс для этого в моей базе данных firestoew, мой код:
public class ListActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
public Dialog dialog;
Spinner bloodg,localbodyg;
Context context;
TextView sk;
private FirebaseFirestore db = FirebaseFirestore.getInstance ( );
private CollectionReference noteBokkRef = db.collection ("users");
RecyclerView recyclerView;
public NoteAdapter adapter;
public String name1,place1,number1,blood1,location1;
public String bld;
public String lclbdy;
public String group1;
public String munci;
Button load;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_list);
overridePendingTransition( R.anim.fui_slide_in_right, R.anim.fui_slide_out_left );
recyclerView=findViewById (R.id.recyclerview);
recyclerView.setVisibility (View.INVISIBLE);
load=findViewById (R.id.load);
bloodg=findViewById (R.id.bloodg);
localbodyg=findViewById (R.id.localbodyg);
final ArrayAdapter<CharSequence> adapter1=ArrayAdapter.createFromResource (this, R.array.blood_groups, R.layout.spinner_item);
adapter1.setDropDownViewResource (android.R.layout.simple_spinner_dropdown_item);
bloodg.setAdapter (adapter1);
bloodg.setOnItemSelectedListener (this);
ArrayAdapter<CharSequence>adapter2=ArrayAdapter.createFromResource (this, R.array.muncipality, R.layout.spinner_item);
adapter2.setDropDownViewResource (android.R.layout.simple_spinner_dropdown_item);
localbodyg.setAdapter (adapter2);
localbodyg.setOnItemSelectedListener (this);
load.setOnClickListener (new View.OnClickListener ( ) {
@Override
public void onClick(View v) {
recyclerView.setVisibility (View.VISIBLE);
Toast.makeText (ListActivity.this,bld +lclbdy,Toast.LENGTH_SHORT).show ();
}
});
setUpRecyclerView ( );
}
public void setUpRecyclerView() {
String blood = bloodg.getSelectedItem().toString();
String localbody = localbodyg.getSelectedItem().toString();
Query query=db.collection ("users")
.whereEqualTo ("bloodgroup",bloodg.getSelectedItem ().toString ())
.whereEqualTo ("muncipality",localbodyg.getSelectedItem ().toString ())
.orderBy ("name",Query.Direction.ASCENDING);
FirestoreRecyclerOptions<Note>options=new FirestoreRecyclerOptions.Builder<Note> ()
.setQuery (query,Note.class).build ();
FirebaseFirestoreSettings settings=new FirebaseFirestoreSettings .Builder ()
.setPersistenceEnabled (false)
.build ();
adapter=new NoteAdapter (options);
recyclerView.setHasFixedSize (true);
recyclerView.setLayoutManager (new LinearLayoutManager (this));
recyclerView.setAdapter (adapter);
adapter.setOnItemClickListener (new NoteAdapter.OnItemClickListener ( ) {
@Override
public void onItemClick(Note note, int position) {
String number=note.getNumber ();
String name=note.getName ();
String place=note.getPlace ();
String location=note.getMuncipality ();
String blood=note.getBloodgroup ();
name1=name;
place1=place;
location1=location;
blood1=blood;
number1=number;
startDialog();
}
});
}
@Override
protected void onStart() {
super.onStart ( );
adapter.startListening ();
}
@Override
protected void onStop() {
super.onStop ( );
adapter.stopListening ();
}
private void startDialog() {
dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.custompopup);
dialog.show();
TextView tv_message = (TextView) dialog .findViewById(R.id.txtclose);
TextView name=dialog.findViewById (R.id.name2);
name.setText (name1);
TextView place=dialog.findViewById (R.id.place);
place.setText (place1);
TextView localbody=dialog.findViewById (R.id.location);
localbody.setText (location1);
TextView blood=dialog.findViewById (R.id.blood);
blood.setText (blood1);
TextView number=dialog.findViewById (R.id.number);
number.setText (number1);
Button call = (Button)dialog.findViewById(R.id.call);
call.setOnClickListener (new View.OnClickListener ( ) {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + number1));
startActivity(intent);
}
});
Button share=dialog.findViewById (R.id.share);
share.setOnClickListener (new View.OnClickListener ( ) {
@Override
public void onClick(View v) {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT,name1+"\n"+blood1+"\n"+place1+"\n"+location1+"\n"+number1+"\n");
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "The title");
startActivity(Intent.createChooser(shareIntent, "Share..."));
}
});
Button chat=dialog.findViewById (R.id.whatsapp);
chat.setOnClickListener (new View.OnClickListener ( ) {
@Override
public void onClick(View v) {
Uri uri=Uri.parse ("smsto:"+number1);
Intent intent=new Intent (Intent.ACTION_SENDTO, uri);
intent.setPackage ("com.whatsapp");
intent.putExtra(Intent.EXTRA_TEXT,"Your score and Some extra text");
intent.putExtra(Intent.EXTRA_SUBJECT, "The title");
startActivity (intent);
}
});
tv_message.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater ().inflate (R.menu.menu1,menu);
MenuItem item=menu.findItem (R.id.search);
return super.onCreateOptionsMenu (menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected (item);
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if(parent.getId() == R.id.bloodg)
{
String group=parent.getItemAtPosition (position).toString ();
if (position!=0){
Toast.makeText (parent.getContext (),group,Toast.LENGTH_SHORT).show ();}
bld=group;
}
else if(parent.getId() == R.id.localbodyg)
{
String muncipality=parent.getItemAtPosition (position).toString ();
if (position!=0){
Toast.makeText (parent.getContext (),muncipality,Toast.LENGTH_SHORT).show ();}
lclbdy=muncipality; }
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
public void call(View view) {
}
}
Структура базы данных: