我想選擇財(cái)務(wù)名稱,點(diǎn)擊財(cái)務(wù)名稱后,我想獲得相同財(cái)務(wù)的代碼。財(cái)務(wù)名稱列在列表視圖中。我的 Firebase 數(shù)據(jù)庫結(jié)構(gòu)如下:financeRef.addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(@NonNull DataSnapshot dataSnapshot) { for (DataSnapshot snapshot : dataSnapshot.getChildren()) { //Map<String, Object> data = (Map<String, Object>) snapshot.getValue(); String value = new Gson().toJson(snapshot.getValue()); progressBar.setVisibility(View.GONE); try { JSONObject object = new JSONObject(String.valueOf(value)); f = object.getString("Finance Name"); name = snapshot.getKey(); } catch (JSONException e) { e.printStackTrace(); } financeName.add(f); adapter.notifyDataSetChanged(); } listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intent = new Intent(FinanceNameListActivity.this, CodeAndNameActivity.class); String abc = (String) ((TextView) view).getText(); intent.putExtra("Name",abc); startActivity(intent); finish(); } }); } @Override public void onCancelled(@NonNull DatabaseError databaseError) { }});
1 回答

一只名叫tom的貓
TA貢獻(xiàn)1906條經(jīng)驗(yàn) 獲得超3個(gè)贊
從 firebase 獲取響應(yīng)并將其設(shè)置為模型調(diào)用或哈希映射或數(shù)組,然后實(shí)現(xiàn)列表視圖單擊事件或簡單單擊事件的接口,并獲取位置并從設(shè)置 firebase 響應(yīng)的位置獲取值。
添加回答
舉報(bào)
0/150
提交
取消