2016-05-23 10 views
0

我有像這樣的例子:如何通過單擊recyclerview1的listitem在recylerview1中添加recylerview2?

Recylerview2內Recylerview1

img 在這種情況下:

如果我點擊列表項的數字1,然後recylerview2下方會出現一個號碼1

所以我的問題是:

我該怎麼做?這是我的代碼。

我把這段代碼放在適配器內部的onBindViewHolder裏面。

fItemsHolder.mLinearReply.setVisibility(View.GONE); 
    if (item.getName2() != null) { 
     fItemsHolder.mHiddenComment.setText(item.getName2()+": "+item.getComment2()); 
     fItemsHolder.feedImageView.setVisibility(View.VISIBLE); 

     int jComment = Integer.parseInt(item.getJumlahComment().toString()); 
     if(jComment > 0){ 
      fItemsHolder.mHiddenComment.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View v) { 
        commentItems = new ArrayList<CommentModel>(); 
        adapter = new NoteCommentListAdapter(mContext, commentItems); 
        mRecyclerView = new RecyclerView(mContext); 
        getListViewComments(item.getUserid(), item.getId(),fItemsHolder,i, commentItems, adapter, mRecyclerView); 
        commentItems = new ArrayList<CommentModel>(); 
        adapter = new NoteCommentListAdapter(mContext, commentItems); 
        mRecyclerView.setAdapter(adapter); 

       } 
      }); 
     } 
    } else { 
     fItemsHolder.mHiddenComment.setVisibility(View.GONE); 
     fItemsHolder.mLinearHiddenComment.setVisibility(View.GONE); 
    } 

,這是我的AsyncTask:

private void getListViewComments(final String userid, String id_note,final feedItemsHolder feedItemsHolder, int i, final List<CommentModel> commentItems, final NoteCommentListAdapter adapter, final RecyclerView mRecyclerView) { 
    class ambilComment extends AsyncTask<String, Void, String> { 
     ProgressDialog loading; 
     com.android.personalRoom.asynctask.profileSaveDescription profileSaveDescription = new profileSaveDescription(); 
     String result = ""; 
     InputStream inputStream = null; 

     @Override 
     protected void onPreExecute() { 
      feedItemsHolder.mLoading.setVisibility(View.GONE); 
      feedItemsHolder.mHiddenComment.setVisibility(View.GONE); 
      feedItemsHolder.mLinearHiddenComment.setVisibility(View.GONE); 
      feedItemsHolder.mLoading.setVisibility(View.VISIBLE); 
      super.onPreExecute(); 
     } 

     @Override 
     protected String doInBackground(String... params) { 
      HashMap<String, String> data = new HashMap<String,String>(); 
      data.put("userid", params[0]); 
      data.put("id_note", params[1]); 
      String result = profileSaveDescription.sendPostRequest(URL_LIST_VIEW_COMMENT,data); 
      return result; 
     } 

     protected void onPostExecute(String s) { 
      JSONArray dataJsonArr = null; 
      if(s.equals(null)){ 
       Toast.makeText(mContext, "Internet Problem.", Toast.LENGTH_SHORT).show(); 
       Log.w("notakomen", "notakomen: "+s); 
      }else{ 
       Log.w("notakomen", "notakomen: "+s); 
       try{ 
        JSONObject json = new JSONObject(s); 
        String id_note = json.getString("id_note"); 

        dataJsonArr = json.getJSONArray("data"); 
        for (int i = 0; i < dataJsonArr.length(); i++) { 

         JSONObject c = dataJsonArr.getJSONObject(i); 

         String id_comment = c.getString("id_comment"); 
         String uid = c.getString("userid"); 
         String profile_name = c.getString("profile_name"); 
         String profile_photo = c.getString("profile_photo"); 
         String amount_of_like = c.getString("amount_of_like"); 
         String amount_of_dislike = c.getString("amount_of_dislike"); 
         String amount_of_comment = c.getString("amount_of_comment"); 
         String content_comment = c.getString("content_comment"); 
         String tgl_comment = c.getString("tgl_comment"); 
         String parent_id = c.getString("parent_id"); 

         Log.e(TAG, "id_comment: " + id_comment 
           + ", uid: " + uid 
           + ", profile_name: " + profile_name 
           + ", profile_photo: " + profile_photo 
           + ", amount_of_comment: " + amount_of_comment 
           + ", tgl_comment: " + tgl_comment); 

         CommentModel citem = new CommentModel(); 
         citem.setId_note(id_note); 
         citem.setId_comment(id_comment); 
         citem.setUserid(uid); 
         citem.setProfileName(profile_name); 
         String pPhoto = c.isNull("profile_photo") ? null : c.getString("profile_photo"); 
         citem.setProfile_photo(pPhoto); 
         citem.setJumlahLove(amount_of_like); 
         citem.setJumlahNix(amount_of_dislike); 
         citem.setJumlahComment(amount_of_comment); 
         citem.setContent_comment(content_comment); 
         citem.setTimeStamp(tgl_comment); 
         String prntID = c.isNull("parent_id") ? null : c.getString("parent_id"); 
         citem.setParent_id(prntID); 

         citem.setLevel(level); 
         commentItems.add(citem); 

         feedItemsHolder.mNameReply.setText(profile_name); 
        } 
        adapter.notifyDataSetChanged(); 

       }catch(JSONException e){ 
        e.printStackTrace(); 
        Log.w("getListNotesComment", "exception"); 
       } 
       feedItemsHolder.mLoading.setVisibility(View.GONE); 
       feedItemsHolder.mLinearReply.setVisibility(View.VISIBLE); 
      } 
      /* iH.mHiddenComment.setText("");*/ 
     } 
} 
    ambilComment ru = new ambilComment(); 
    ru.execute(userid, id_note); 
} 
+1

你有使用可擴展的ListView裏面回收者中考慮? –

+0

現在我的問題是,expandablelistview可以在CollapsingToolbarLayout內滾動嗎?因爲當我使用recylerview時,它可以在CollapsingToolbarLayout內滾動。就像這個http://imgur.com/R8kQvg1 @MalithLakshan – Lukmanpryg

回答

1

嘗試使用這個庫:android-advancedrecyclerview

入住這example有關如何使用此lib中使用可擴展recyclerview。

要使用它,通過在gradle.build文件中加入對它的依賴的lib添加到您的項目:

dependencies { 
    compile ('com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:[email protected]'){ 
     transitive=true 
    } 
} 
相關問題