我正在使用Android应用程序,我想尝试从上一个活动中获取用户输入并将其解析为value字段。这样用户可以获取与搜索查询有关的所有数据。
这是我的实际代码
private RecyclerView mRecyclerView;
private RecyclerView.Adapter mAdapater;
private RecyclerView.LayoutManager mLayoutManager;
private FirebaseFirestore db;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_packages_list);
final ArrayList<Packages> packagesList = new ArrayList<>();
mRecyclerView = findViewById(R.id.packsRecycler);
mRecyclerView.setHasFixedSize(true);
mLayoutManager = new LinearLayoutManager(this);
mAdapater = new PackagesAdapter(packagesList);
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setAdapter(mAdapater);
Bundle extras = getIntent().getExtras();
String startL = extras.getString("startLocation"); //I want to parse this userInput to the value at whereEqualTo()//
String endL = extras.getString("endLocation");// And is it possible to parse this to another field: called searchCityDrop, value://
db = FirebaseFirestore.getInstance();
db.collection("PackageDetails").whereEqualTo(field:"searchCityPick", value:startL).get()
.addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
if (!queryDocumentSnapshots.isEmpty()){
List<DocumentSnapshot> list = queryDocumentSnapshots.getDocuments();
for (DocumentSnapshot d : list){
Packages p = d.toObject(Packages.class);
packagesList.add(p);
}
mAdapater.notifyDataSetChanged();
}
else {
Toast.makeText(PackagesListActivity.this, "Results not found! According to your destination.", Toast.LENGTH_LONG).show();
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(PackagesListActivity.this, "Something went wong. Please try again.", Toast.LENGTH_SHORT).show();
}
});
}
如何将用户输入解析为该数据快照值字段?
答案 0 :(得分:0)
我不知道解析的含义,但在我看来,您已经从上一个活动中获得了价值。也许尝试getIntent().getStringExtra("startLocation")
并在开始此意图之前检查是否确实在意图附加中放了任何东西。