我是Firebase的新手,通过观看一些教程和阅读文档,我让应用程序在列表视图中显示节点的值。但我想要做的是在列表视图中显示键和值。 我怎么能这样做?
我做了什么:
public class MainActivity extends AppCompatActivity {
private ListView mListView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mListView = (ListView) findViewById(R.id.listView);
final String med = "Meth";
final DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReferenceFromUrl("https://fir-test-d6253.firebaseio.com/"+med);
final FirebaseListAdapter<String> firebaseListAdapter = new FirebaseListAdapter<String>(
this,
String.class,
android.R.layout.simple_list_item_1,
databaseReference
) {
@Override
protected void populateView(View v, String model, int position) {
TextView textView = (TextView) v.findViewById(android.R.id.text1);
textView.setText(model);
}
};
mListView.setAdapter(firebaseListAdapter);
}
}`
数据库:
- fir-test-d6253addclose
- Meth
- Store1: "1"
- Store2: "10"
- Morphine
- Store1: "5"
- Store2: "10"
- Store3: "10"
现在的输出是:
- 1
- 10
我想要的是什么:
- Store1 1
- Store2 10
还是有其他方法而不是使用firebaseui吗?