2016-08-18 113 views
0

我想用下面的教程的內容:無法解析FirebaseListAdapter(安卓)構造

Retrieving data in realtime with Firebase Events - Firecasts #2

大約14:00分大關,你會看到介紹如下代碼:

FirebaseListAdapter<String> adapter = new FirebaseListAdapter<String>(this, 
      String.class, android.R.layout.simple_list_item_1, messagesRef) { 

     protected void populateView(View v, String model, int position) { 
      TextView textView = (TextView) findViewById(android.R.id.text1); 
      textView.setText(model); 
     } 
    }; 

但是,我的Android Studio強調了紅色的構造函數參數,當我將鼠標懸停在帶下劃線的區域上時,彈出一條消息「無法解析構造函數」[我的構造函數w/params的詳細抽象描述]'。我希望我可以剪切和粘貼它所說的內容,但我找不到任何方法。

無論如何......在我的無限知識中,我檢查了底層(導入)類FirebaseListAdapter.java(如果視頻製作後對構造函數需求進行了某種更改),並且我可以看到沒有理由爲什麼我的構造函數(這不是真正的「我的」構造函數 - 它是視頻中的構造函數)不起作用。

感謝您的幫助!

PS - 我知道有人會要求更多的代碼,所以這裏是整個MainActivity:

package com.testing123.firecast2; 

import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.View; 
import android.widget.ArrayAdapter; 
import android.widget.ListView; 
import android.widget.TextView; 
import com.firebase.client.ChildEventListener; 
import com.firebase.client.DataSnapshot; 
import com.firebase.client.Firebase; 
import com.firebase.client.FirebaseError; 
import com.firebase.client.ValueEventListener; 
import com.firebase.ui.database.FirebaseListAdapter; 
import java.util.ArrayList; 
import java.util.Map; 

public class MainActivity extends AppCompatActivity { 

ArrayAdapter<String> adapter; 

static final String TAG = "FireBase2"; 

// Firebase 

Firebase mRootRef; 
Firebase messagesRef; 

// ArrayList<String> mMessages = new ArrayList<>(); 

// UI 

TextView mTextView; 
ListView mListView; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    mRootRef = new Firebase ("https://firecast002.firebaseio.com/"); 

    mTextView = (TextView) findViewById(R.id.textView); 
    mListView = (ListView) findViewById(R.id.listView); 

} 


@Override 
protected void onStart() { 
    super.onStart(); 
    messagesRef = mRootRef.child("messages"); 

    // adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mMessages); 
    FirebaseListAdapter<String> adapter = new FirebaseListAdapter<String>(this, 
      String.class, android.R.layout.simple_list_item_1, messagesRef) { 

     protected void populateView(View v, String model, int position) { 
      TextView textView = (TextView) findViewById(android.R.id.text1); 
      textView.setText(model); 
     } 
    }; 



    mListView.setAdapter(adapter); 

    /* messagesRef.addValueEventListener(new ValueEventListener() { 
     @Override 
     public void onDataChange(DataSnapshot dataSnapshot) { 

      // String message = dataSnapshot.getValue(String.class); 

      // mTextView.setText(message); 

      // that was how its done for single key value pair... but now we're doing multiple children under "message" 

      Map<String,String> map = dataSnapshot.getValue(Map.class); 
      String message1 = map.get("message1"); 
      String message2 = map.get("message2"); 

     } 

     @Override 
     public void onCancelled(FirebaseError firebaseError) { 
     } 
    }); */ 

    // that was how its done for valuevent listener... now we treat the children of "message" key as list items 
    // and use a childeventlistener instead 

    /* messagesRef.addChildEventListener(new ChildEventListener() { 
     @Override 
     // gets fired for every INITIAL child member. 
     // only gets sent a string, not a downstream dataset 
     public void onChildAdded(DataSnapshot dataSnapshot, String s) { 
      String message = dataSnapshot.getValue(String.class); 
      Log.i(TAG, "child added: " + message + " ... and by the way, String 's' is" + s); 
      mMessages.add(message); 
      adapter.notifyDataSetChanged(); 
     } 

     @Override 
     public void onChildChanged(DataSnapshot dataSnapshot, String s) { 
      String message = dataSnapshot.getValue(String.class); 
      Log.i(TAG, "child changed: " + message + " ... and by the way, String 's' is" + s); 
     } 

     @Override 
     public void onChildRemoved(DataSnapshot dataSnapshot) { 

      String message = dataSnapshot.getValue(String.class); 
      Log.i(TAG, "child removed: " + message); 
     } 

     @Override 
     public void onChildMoved(DataSnapshot dataSnapshot, String s) { 
     } 

     @Override 
     public void onCancelled(FirebaseError firebaseError) { 
     } 
    }); 
    */ 
    // that was the hard way, now we use FirebaseUI 





} 
} 
+0

一切似乎都合法。我訪問了[這個鏈接](https://firebaseui.com/docs/android/com/firebase/ui/FirebaseListAdapter.html)來查看它的可用構造函數,看起來好像你已經掌握了它。你有沒有嘗試用你的錯誤搜索,看看有人有嗎? – Vucko

+0

你是否在你的依賴gradle文件中加入了firebase ui編譯'com.firebaseui:firebase-ui:0:3.1' –

+0

你能分享一下你得到的錯誤嗎 –

回答

0

更新您的項目中添加最新版本的火力UI

「com.firebaseui的: firebase-ui:0.4.3'