我是Firebase的新手,通过观看一些教程和阅读文档,我使应用程序在列表视图中显示节点的值。但我想做的是在listview中同时显示键和值。我该怎么做呢?
我做了什么:
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?
请张贴适配器代码让我帮助。否则,使用此链接检索数据并在listview中显示。