2016-08-17 33 views
0

基本上我有像一门功课的提醒应用程序如何把火力地堡RecyclerView另一RecyclerView内

用户可以插入的对象列表,并在每个学科的家庭作业

列表

我知道它最糟糕的实践中,我不能把recyclerview内另一个

,但我需要在我的应用程序对象不能算作+其他事情

我插入它火力数据库successfuly这样

enter image description here

是subject_item.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="@drawable/simple_round" 
android:padding="10dp" 
android:layout_margin="10dp"> 
<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:padding="2dp" 
    android:orientation="horizontal"> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Subject: "/> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="2"/> 
</LinearLayout> 
<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:padding="2dp" 
    android:weightSum="6"> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="Teacher:"/> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="2"/> 
</LinearLayout> 
<android.support.v7.widget.RecyclerView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/recyclerview_illness_item_list"> 
</android.support.v7.widget.RecyclerView> 
</LinearLayout> 

,这是homework_item.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="@drawable/simple_round" 
android:padding="10dp" 
android:layout_margin="10dp"> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:padding="2dp" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="title:"/> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 
</LinearLayout> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:padding="2dp" 
    android:orientation="horizontal"> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="description:"/> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/> 
</LinearLayout> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:padding="2dp" 
    android:orientation="horizontal"> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="deadline:"/> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 
</LinearLayout> 

和只有一个recyclerview我那样做

adapter = new FirebaseRecyclerAdapter<Test, TestViewHolder>(Test.class, R.layout.test_main_body_item, TestViewHolder.class, reference.child("subjects/98794656")) { 
     @Override 
     protected void populateViewHolder(TestViewHolder viewHolder, Test model, int position) { 
      viewHolder.title.setText(model.getTitle()); 
      viewHolder.description.setText(model.getDescription()); 
     } 
    }; 

那么我该如何做一个回收者视图内幕另一个recyclerview?

感谢

回答

0

你想要做的是检测被点击了什么,然后导航到另一个活动以显示数据列表中也包含正确的呢?

但在此之前,您需要一个EXTRA_KEY包来告诉您的新活动,它需要从他的父母收到一些东西。例如:“嘿,我给你发一个软件包,提取它并在你的环境中明智地使用它。”

现在创建EXTRA BUNDLE很简单。只需在你的本地变量中写入。

你想浏览到活动中,把这个有:

public static final String EXTRA_NAME = "cheese_name"; 
public static final String EXTRA_POST_KEY = ""; ` 

Intent intent = getIntent(); 
final String cheeseName = intent.getStringExtra(EXTRA_NAME);` 

查看该帖子还对数据库的引用密匙:

  viewHolder.itemView.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View v) { 
        // Launch PostDetailActivity 
        Intent intent = new Intent(getActivity(), CheeseDetailActivity.class); 

    //How you are sending something to another activity 


intent.putExtra(CheeseDetailActivity.EXTRA_POST_KEY, postKey); 
        startActivity(intent); 
       } 
      }); 


    } 
}; 

你引用一个孩子("test")

adapter = new FirebaseRecyclerAdapter<Test, TestViewHolder>(Test.class, R.layout.test_main_body_item, TestViewHolder.class, reference.child("test")) { 
    @Override 
    protected void populateViewHolder(TestViewHolder viewHolder, Test model, int position) { 

    final DatabaseReference postRef = getRef(position); 


      // Set click listener for the whole post view 
      final String postKey = postRef.getKey(); 

     viewHolder.title.setText(model.getTitle()); 
     viewHolder.description.setText(model.getDescription()); 
    } 
}; 
+0

它不是这样,是的,我引用了一个不存在的错误节点。问题是我有2个列表,其中1个用于主题,另一个用于每个主题的家庭作品,我可以创建主题列表,当任何人被点击时,其作业将被列出,我目前正在使用下面的添加视图来解决它点击一个。 –

+0

好的。我将在桌面上回来 –