2016-08-18 93 views
0

我有我的火力点名单适配器如下与卡片视图使用火力地堡列表适配器

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_home); 
    mListview = (ListView) findViewById(R.id.listview); 

    mAuth = FirebaseAuth.getInstance(); 
    //the post list shit is happening here 

    DatabaseReference root = FirebaseDatabase.getInstance().getReference(); 
    FirebaseUser user = mAuth.getCurrentUser(); 
    DatabaseReference postRef = root.child("users").child(user.getUid().toString()).child("posts"); 

    ListAdapter adapter = new FirebaseListAdapter<PostList>(this,PostList.class,android.R.layout.simple_list_item_1,postRef) { 
     @Override 
     protected void populateView(View view, PostList postList, int i) { 
      TextView text = (TextView)view.findViewById(android.R.id.text1); 
      text.setText(postList.getBody()); 

     } 

    }; 
    mListview.setAdapter(adapter); 

我有一个列表视图正常的XML和与它的卡片视图另一个XML

我的问题是,我不能找到一种方法,涉及我cardview的xml文件到我的活动,所以我的列表只是不停地显示为正常列表, 在初始化火力名单适配器,我发现了一个R.layout_simple_list_item 林不知道这究竟是如何工作的,我用Google搜索,没有什么可以解释为什么我不能只说改为。另外,请让我知道,如果我这样做是错误的。

+1

如果您使用CardView,我建议您改用FirebaseRecyclerAdapter。 – Linxy

+0

你能指出我的任何好的教程,从火力位置回收适配器,而不是一些静态数组专门处理 – Mordred

+0

从这里安装FirebaseRecyclerAdapter:https://github.com/firebase/FirebaseUI-Android,然后有一个完整的教程藏汉:https://github.com/firebase/FirebaseUI-Android/blob/master/database/README.md – Linxy

回答

0

我已经得到了答案,只是为了防止任何人经历同样的问题,就像Linxy明确指出的那样,最好使用FirebaseRecyclerAdapter,它是ListAdapter的修改版本。

  1. ,你不能直接编辑0​​,而是创建自己的布局首先说明,你在你的布局有row.xml:如果你觉得你仍然想使用ListAdapter,然后

    然而文件,使用R.layout.row为您populateView()参数,而不是android.R.layout.row,后者不会找到任何东西,因为这些布局文件存储在您的SDK文件夹。

  2. 请考虑回收适配器,它并不难。