2016-08-17 43 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

好的。我將在桌面上回來 –