首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FirebaseUI片段

FirebaseUI片段
EN

Stack Overflow用户
提问于 2017-04-10 18:16:31
回答 1查看 634关注 0票数 0

因此,我试图在数据库片段中使用FirebaseUi作为数据库listView,我试图搜索与我在这里没有发现的问题相同的人--这是我的代码。

我尝试从另一个类引用它,它不像ex那样工作,创建一个新类,调用它FirebaseDatabase,并导入整个ui,没有任何错误,但是当我试图在片段中调用时,我会得到一个错误

代码语言:javascript
复制
    public BlankFragment() {
        // Required empty public constructor

    }

    private ListView mlistView;
    public View view;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        mlistView = (ListView) view.findViewById(R.id.listView);
        DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReferenceFromUrl("https://kalby-3428f.firebaseio.com/");
        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) {

            }
        };
       return   inflater.inflate(R.layout.fragment_blank, container, false);

    }

and that's the XML Code`<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.kalby.kalby.BlankFragment">

    <!-- TODO: Update blank fragment layout -->
    <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
         />

</FrameLayout>

这就是错误

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-10 19:25:18

代码语言:javascript
复制
    FirebaseListAdapter<String> firebaseListAdapter = new FirebaseListAdapter<String>(
            this,
            String.class,
            android.R.layout.simple_list_item_1,
            databaseReference
    )

在这里,"this“需要一个活动,而您是在片段中使用它,所以这里的"this”是片段而不是活动。

尝试使用"getActivity()“而不是"this",代码应该如下所示:

代码语言:javascript
复制
FirebaseListAdapter<String> firebaseListAdapter = new FirebaseListAdapter<String>(
        getActivity(),
        String.class,
        android.R.layout.simple_list_item_1,
        databaseReference
)

试试看,根据你的屏幕截图,我认为这是可行的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43330188

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档