[英]Why does transfering data from one Activity to another doesnt work inside a query in firebasefirestore
我正在嘗試傳遞用戶選擇的過濾芯片的值,以便僅檢索他在該特定標准中想要的所需商店。
現在我創建了所有內容,並且從我的 FilterActivity 完成后獲得的數據正在傳遞到我的 HomeActivity 中。 但是這個數據在我的查詢中沒有被“讀取”或“接受”,因為它沒有產生正確的 output。 當我在查詢中使用 static 值時,它會起作用。 現在我需要它是一個變化的值,具體取決於使用選擇的內容。
這是在我的 HomeActivity 中打開過濾器活動的:
filterBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(HomeActivity.this,FilterActivity.class);
startActivityForResult(intent,101);
}
});
這是我的 FilterActivity 和幾個例子:
private Chip rate2,rate3,rate4;
private ArrayList<String> selectedChipData;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_filter);
rate2 = findViewById(R.id.chip_Rate_2);
selectedChipData = new ArrayList<>();
CompoundButton.OnCheckedChangeListener checkedChangeListener = new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
if(isChecked){
selectedChipData.add(compoundButton.getText().toString().trim());
}else{
selectedChipData.remove(compoundButton.getText().toString().trim());
}
}
};
rate2.setOnCheckedChangeListener(checkedChangeListener);
}
這是用戶在想要應用過濾器選項之一時單擊的按鈕:
filter_reset = findViewById(R.id.filter_reset);
filter_reset.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent resultIntent = new Intent();
resultIntent.putExtra("data",selectedChipData.toString().trim());
setResult(101,resultIntent);
finish();
}
});
現在在我的 HomeActivity 中,我創建了 onActivityResult:
String Data;
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==101){
Data = data.getStringExtra("data");
Log.d("TAG", data.getStringExtra("data"));
Query q = firebaseFirestore.collection("Shops").whereEqualTo("location",Data);
}
}
Query q = firebaseFirestore.collection("Shops").whereEqualTo("location",Data);
// this is my query and how i am trying to pass the matched users selected chip to the location of the Shops table.
我在查詢中遺漏了什么或做錯了什么以及如何解決它? 有人可以建議嗎?
您是否有任何機會忘記將意圖告訴 go 返回主頁
filter_reset = findViewById(R.id.filter_reset);
filter_reset.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent resultIntent = new Intent(FilterActivity.this, MainActivity.class);
// Changed the above Intent Paras
resultIntent.putExtra("data",selectedChipData.toString().trim());
setResult(101,resultIntent);
finish();
}
});
我發現了問題,它與我的數據庫不匹配,因為該值是一個數組並且結果中有 []。 如果我將 [] 放在我的數據庫中,它就可以正常工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.