FirebaseListAdapter没有触发populateView()

时间:2017-06-12 21:52:58

标签: android android-fragments firebase firebaseui

在找到一些人说FirebaseRecyclerAdapters在片段内部被破坏(并且在此之前尝试了大约4个小时才能使其工作)之后,我决定切换到FirebaseListAdapter,因为我发现在片段内工作的例子。但是,我遇到了问题。 populateView()方法似乎永远不会被触发,我没有错误。这是片段的代码:

public class PasteFromFirebasePopup extends DialogFragment implements AdapterView.OnClickListener {
Activity activity;

private FirebaseListAdapter mFirebaseAdapter;
private DatabaseReference mClipboardHistoryReference;
private ListView mListView;

public PasteFromFirebasePopup() {}

@Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                                   Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.clip_history_popup_list, container, false);

    mListView = (ListView) rootView.findViewById(R.id.clipboardHistoryListView);

    activity = getActivity();
    mClipboardHistoryReference = FirebaseDatabase.getInstance().getReference(Constants.FIREBASE_CHILD_CLIPBOARD_HISTORY);
    Log.d("clipboardRef", mClipboardHistoryReference.toString());

    mFirebaseAdapter = new FirebaseListAdapter<FirebaseString>
            (activity, FirebaseString.class, R.layout.clip_history_popup_item, mClipboardHistoryReference) {
            TextView mTextView;

        @Override protected void populateView(View v, FirebaseString model, int position) {

            mTextView = (TextView) v.findViewById(R.id.clipboardHistoryTextView);
            Log.d("model text", model.getText());
            mTextView.setText(model.getText());
        }
    };

    mListView.setAdapter(mFirebaseAdapter);

    return rootView;
}

@Override public void onClick(View v) {}

@Override public void onDestroy() {
    super.onDestroy();
    mFirebaseAdapter.cleanup();
}

}

无论我尝试什么,populateView()内的日志绝对不会触发。我已经三次检查了我的参考,并且确实有一些东西(目前只有一个项目,但据我所知,这不重要)。我错过了什么吗?这在DialogFragments内部不起作用吗?如果没有,是否有人建议popup可以成功保留FirebaseListAdapter/RecyclerAdapter

任何帮助都得到了适当的赞赏。

编辑:我的build.gradle (app),因为我认为这可能与它有关。

dependencies {
 compile fileTree(dir: 'libs', include: ['*.jar'])
 androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestCompile('com.android.support.test:runner:0.3') {
    exclude group: 'com.android.support', module: 'support-annotations'
}

compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.github.smart-fun:XmlToJson:1.2.2'

compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:gridlayout-v7:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:support-v4:25.3.1'

testCompile 'org.robolectric:robolectric:3.0'
testCompile 'org.robolectric:shadows-support-v4:3.0'
testCompile 'junit:junit:4.12'

compile 'com.google.firebase:firebase-database:11.0.0'
compile 'com.firebaseui:firebase-ui-database:1.2.0'
compile 'com.google.android.gms:play-services:11.0.0'

compile 'org.parceler:parceler-api:1.1.6'
annotationProcessor 'org.parceler:parceler:1.1.6'

compile 'com.jakewharton:butterknife:8.6.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
}

apply plugin: 'com.google.gms.google-services'

0 个答案:

没有答案