我有一个Firebase数据库设置,当在应用程序中按下按钮时,它会使用我的数据库中的值填充列表视图。我没有问题,但我在调试中注意到列表视图没有标题。我想我可以添加一个包含所有标题的新String[]
列表,但我仍然坚持如何添加到每个项目。这是我点击按钮的代码:
public void viewJobsOnClick(View view) {
final TextView tv = (TextView) findViewById(R.id.tvday);
final RelativeLayout Rlitem = (RelativeLayout)findViewById(R.id.joblistitemslayout);
final RelativeLayout Rllist = (RelativeLayout)findViewById(R.id.joblistviewlayout);
//My adapter that is populating my listview
final ArrayAdapter<String> jlistAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, JoblistArray);
lv.setAdapter(jlistAdapter);
if (joblistRootRef.child("Monday").toString().contains(DAY_OF_THE_WEEK)) {
//Firebase child listener that sends the data to my adapter
joblistRootRef.child("Monday").addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
String jlist = dataSnapshot.getValue(String.class);
Rlitem.setVisibility(View.GONE);
Rllist.setVisibility(View.VISIBLE);
JoblistArray.add(jlist);
}
答案 0 :(得分:0)
你只保存string.class obj我认为你应该学习如何将java obj(POJO)保存到firebase中,女巫包含你的listview名称和listview detail 步骤1创建一个java类的POJO 并保存到firebase中,如果你想知道什么是pojo here is video you can watch
第2次在您的应用here is link to video中使用firebaseListadupter ,您将了解firebase listadupter的工作方式
简单代码:firebaseListAdupter如何工作
public class Main {
/**
* Main method. Starts the threads and lets them roll.
* @param args
*/
public static void main(String[] args) {
// start threads
DebugMessenger.out("Starting Main");
GUIThread guiThread = new GUIThread();
guiThread. setGUINumber(GUIThread.LAUNCH_IMAGE_PREVIEWER);
//Create and Start the Thread now using Thread API
Thread threadObj = new Thread(guiThread).start();
if(Config.DEBUG_OUTPUT_ENABLED) {
memBarThread = new GUIThread();
memBarThread.start(GUIThread.MEMORY_USAGE_WINDOW);
}
DebugMessenger.out("Main complete");
}
}