无法解析FirebaseListAdapter(Android)的构造函数

时间:2016-08-18 10:54:20

标签: android firebase firebase-realtime-database firebaseui

我正在尝试按照以下教程:

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





}
}

2 个答案:

答案 0 :(得分:0)

更新项目以添加最新版本的firebase UI

&#39; com.firebaseui:火力的UI:0.4.3&#39;

答案 1 :(得分:-1)

我有同样的错误。经过多次尝试,我认为我找到了解决方法。

  1. 首先,将此库添加到您的依赖项中:

    implementation 'com.firebaseui:firebase-ui:0.6.2'

  2. 接下来,将此导入复制并粘贴到您的活动导入中:

    import com.firebase.ui.database.FirebaseListAdapter;