0

RecycleView가 표시되는 대화 조각이 있습니다.이 문제는 RecycleView에 대한 모든 질문을 거의 볼 수 있지만 여전히 내 문제를 해결하지 못하기 때문에 미친 듯이 보입니다. 여기RecycleView Dialogue Fragment에 표시되지 않음

Fragment.xml 내 코드에서 봐 주시기 바랍니다

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 


<LinearLayout 
    android:id="@+id/titlebar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 

    <TextView 
     android:id="@+id/textView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Be the first to like this" 
     android:layout_marginLeft="@dimen/feed_item_margin" 
     android:layout_marginRight="@dimen/feed_item_margin" 
     android:layout_marginTop="@dimen/feed_item_margin"/> 
</LinearLayout> 

<View 
    android:layout_width="match_parent" 
    android:layout_height="0.5dp" 
    android:background="@color/dialog" 
    android:layout_marginTop="10dp" 
    android:paddingRight="@dimen/comment_item_status_pad_left_right" 
    android:paddingLeft="@dimen/comment_item_status_pad_left_right" 
    android:layout_below="@+id/titlebar"/> 

<android.support.v7.widget.RecyclerView 
    android:id="@+id/comment_recycler_view" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:animateLayoutChanges="false" 
    android:scrollbars="vertical" /> 

<LinearLayout 
    android:id="@+id/commentInsert" 
    android:layout_width="match_parent" 
    android:layout_height="60dp" 
    android:layout_alignParentBottom="true" 
    android:background="@android:color/white" 
    android:orientation="horizontal" > 

    <EditText 
     android:id="@+id/commentField" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:ems="10" 
     android:hint="Add a comment" 
     android:background="@null"/> 

    <Button 
     android:id="@+id/sendButton" 
     android:layout_width="77dp" 
     android:layout_height="wrap_content" 
     android:text="Send" /> 
</LinearLayout> 

Fragment.java는 recycleview의 t을 설정 O를 조각 여기

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    // Remove TITLE 
    getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); 

    View dialogView = inflater.inflate(R.layout.fragment_comment, container,false); 
    commentRecyclerView =(RecyclerView)dialogView.findViewById(R.id.comment_recycler_view); 
    commentRecyclerView.setNestedScrollingEnabled(false); 

    //bind the recycler view with the adapter 
    commentAdapter = new CommentAdapter(this.getActivity(),commentItems); 
    final LinearLayoutManager mLayoutManager = new LinearLayoutManager(this.getActivity()); 
    commentRecyclerView.setLayoutManager(mLayoutManager); 
    commentRecyclerView.setAdapter(commentAdapter); 

나는 서버에 대한 요청이

다음
private void fetchItem(int item_id){ 


    // making fresh volley request and getting json 
    JsonObjectRequest jsonReq = new JsonObjectRequest(Request.Method.GET, 
      URL_GET_ITEM + item_id, null, new Response.Listener<JSONObject>() { 

     @Override 
     public void onResponse(JSONObject response) { 
      VolleyLog.d(AppController.TAG, "VolleyResponse: " + response.toString()); 
      Log.d("responseGet",response.toString()); 
      parseJsonFeed(response); 
     } 
    }, new Response.ErrorListener() { 

     @Override 
     public void onErrorResponse(VolleyError error) { 
      VolleyLog.d(AppController.TAG, "Error: " + error.getMessage()); 

     } 
    }) { 
     //adding header to authenticate 
     @Override 
     public Map<String, String> getHeaders() throws AuthFailureError { 

      Map<String,String> headers = new HashMap<>(); 
      headers.put("Content-Type", "application/json"); 
      return headers; 
     } 
    }; 

    // Adding request to volley request queue 
    AppController.getInstance().addToRequestQueue(jsonReq); 

} 

내가 JSON 피드를 구문 분석 할

다음
private void parseJsonFeed(JSONObject response) { 
    try { 

     JSONArray itemArray = response.getJSONArray("item"); 
     //get all the item in Json 
     for (int i = 0; i < itemArray.length(); i++) { 
      JSONObject itemObj = (JSONObject) itemArray.get(i); 

      itemId = itemObj.getInt("item_id"); 
      itemUsername= itemObj.getString("item_username"); 
      itemBody = itemObj.getString("item_body"); 
      itemProfileImage = itemObj.getString("item_profile_image"); 
      itemCreatedAt = itemtObj.getString("item_created_at"); 

      //set all item to the Array list 
      setItemToCommentArrayList(itemId,itemUsername,itemProfileImage,itemBody,itemCreatedAt); 

     } 

     // notify data changes to list adapter 
     itemAdapter.notifyDataSetChanged(); 

    }catch (JSONException e){ 
     System.out.println("end of content"); 
    } 

} 

나는 Item.java에 모든 세부 사항을 추가 모델

여기
private void setItemToCommentArrayList(int itemId, String itemUsername, String itemrofileImage, String itemBody, String itemCreatedAt) { 
    CommentItem item = new CommentItem(); 
    item.setCommentId(itemId); 
    item.setUsername(itemUsername); 
    item.setCommentProfilePic(itemProfileImage); 
    item.setCommentBody(itemBody); 
    item.setCommentTimeStamp(itemCreatedAt); 


    //save it to the comment array list 
    items.add(item); 
} 

6,가 comment_item.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <ImageView 
     android:id="@+id/commentProfilePic" 
     android:layout_width="@dimen/comment_item_profile_pic" 
     android:layout_height="@dimen/comment_item_profile_pic" 
     android:layout_marginLeft="@dimen/feed_item_margin" 
     android:layout_marginRight="@dimen/feed_item_margin" 
     android:layout_marginTop="@dimen/feed_item_margin" 
     android:scaleType="fitCenter" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="@dimen/feed_item_margin" 
     android:layout_marginRight="@dimen/feed_item_margin" 
     android:layout_marginTop="@dimen/feed_item_margin" 
     android:orientation="vertical" 

     android:paddingLeft="@dimen/comment_item_profile_info_padd"> 

     <TextView 
      android:id="@+id/commentUsername" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:paddingLeft="@dimen/comment_item_status_pad_left_right" 
      android:paddingRight="@dimen/comment_item_status_pad_left_right" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/commentBody" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:paddingLeft="@dimen/comment_item_status_pad_left_right" 
      android:paddingRight="@dimen/comment_item_status_pad_left_right" /> 

     <TextView 
      android:id="@+id/commentTimestamp" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:paddingLeft="@dimen/comment_item_status_pad_left_right" 
      android:paddingRight="@dimen/comment_item_status_pad_left_right" 
      android:paddingTop="@dimen/comment_item_timestamp_pad_top" /> 
    </LinearLayout> 

</LinearLayout> 

마지막이다, 여기에 어댑터

입니다
public class CommentAdapter extends RecyclerView.Adapter<CommentAdapter.MyViewHolder>{ 
private Context mContext; 
private List<CommentItem> commentItems; 

class MyViewHolder extends RecyclerView.ViewHolder{ 
    TextView commentBody,commentUsername,commentTimeStamp; 
    ImageView commentProfilePic; 

    //find all the view here 
    MyViewHolder(final View view) { 
     super(view); 

     commentProfilePic = (ImageView)view.findViewById(R.id.commentProfilePic); 
     commentUsername = (TextView)view.findViewById(R.id.commentUsername); 
     commentBody = (TextView)view.findViewById(R.id.commentBody); 
     commentTimeStamp = (TextView)view.findViewById(R.id.commentTimestamp); 

    } 
} 

public CommentAdapter(Context mContext, List<CommentItem> commentItems) { 
    this.mContext = mContext; 
    this.commentItems = commentItems; 
} 


@Override 
public long getItemId(int position) { 
    return position; 
} 
//this one for make the adview inside this 
@Override 
public int getItemViewType(int position) { 
    return position; 
} 


//bind the comment item here 
@Override 
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 
    View commentItemView = LayoutInflater.from(parent.getContext()) 
      .inflate(R.layout.comment_item, parent, false); 
    return new MyViewHolder(commentItemView); 
} 

//do all the action here 
@Override 
public void onBindViewHolder(CommentAdapter.MyViewHolder holder, int position) { 

    final CommentItem commentItem = commentItems.get(position); 

    //commenter username 
    holder.commentUsername.setText(commentItem.getUsername()); 

    //commenter profile image 
    Glide 
      .with(mContext) 
      .load(commentItem.getCommentProfilePic()) 
      .fitCenter() 
      .into(holder.commentProfilePic); 


    //comment body 
    holder.commentBody.setText(commentItem.getCommentBody()); 

    //comment timestamp 
    holder.commentTimeStamp.setText(commentItem.getCommentTimeStamp()); 
} 

@Override 
public int getItemCount() { 
    return commentItems.size(); 
} 
} 

내가 거의 내 다른 RecycleView에 모든 것을 확인, 나는 어떤 다른 볼 didnt는 . 그리고 또한 모든 Stackoverflow 질문을 참조하십시오, 나는 아직도 일어날 것을 볼 수 없습니다. 그것은 단지 recycleview에 어떤 항목을 보여주지 못했어요. 전자 도움말

업데이트 Fragment.xml의 레이아웃을 RelativeLayout에서 LinearLayout으로 변경하면 여전히 작동하지 않습니다.

은 여전히 ​​아래 item.As를 표시하지뿐만 아니라 android:layout_weight="1"이 줄을 제거하십시오 layout_height match_parent로 변경

선형 레이아웃에

시도 변화가 부모로서, android:layout_height="500dp"뿐만 아니라, 또한 찾았하지

<android.support.v7.widget.RecyclerView 
    android:id="@+id/comment_recycler_view" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:animateLayoutChanges="false" 
    android:scrollbars="vertical" /> 

답변

0

대부분 문제는 android:layout_weight="1" 입니다. 상위 레이아웃의 RecyclerView 이외의 다른 곳에서는 가중치를 사용하지 않습니다.

android:layout_height="0dp" 
android:layout_weight="1" 

여기에서 높이는 0dp이며 RelativeLayout에서 가중치가 사용됩니다. 이것들은 작동하지 않을 것이다.

우선, 가중치는 RelativeLayouts에서 작동하지 않습니다. Recycler보기는 RelativeLayout의 하위입니다.미리 정의 된 크기가 경우에 따라서, 그 무게를 제거하고 부모와 같이있는 LinearLayout과 적절한 높이 배포하여 재활용보기로

<android.support.v7.widget.RecyclerView 
     android:id="@+id/comment_recycler_view" 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:animateLayoutChanges="false" 
     android:scrollbars="vertical" /> 

또는 를 사용하여 적절한 가중치를 일부 높이를 설정합니다. 그것은 그것을 고쳐야한다.

+0

이것은'comment_item.xml'의 선형 레이아웃에서 이것을 의미합니까 ?? – ken

+0

이 코드를 추가 할 수있는 위치를 알려주시겠습니까 ?? – ken

+1

Fragment.xml 파일을 업데이트해야합니다. – Neji

0

조합 android:layout_weight="1"android:layout_height="0dp"은 선형 레이아웃에서만 작동합니다. weight 특성을 사용하려면 리사이클러를 LinearLayout에 넣거나 사용자 정의 높이를 설정하십시오. 기본적으로 귀하의 리사이클러 높이는 "0dp"입니다.

+0

선생님, 레이아웃을 변경합니다. 리니어 레이아웃 ady로 표시하지만 여전히 아무것도 보이지 않는 경우 – ken

+0

relativeLayout을 변경하면 리사이클 러의 높이를 20dp로 변경하거나 표시되는 것이 있는지 확인하기 위해 모든 항목을 재정렬해야하기 때문에 그럴 것입니다. –

+0

Brother 아무것도 일어나지 않습니다. 'comment_item.xml'은 보이지 않습니다. – ken

0

layout_weight 속성을 width 또는 height로 설정하면 각각 0dp로 설정됩니다. 또한 하나의 요소에 가중치를주는 다른 요소들에 가중치를 할당하는 것은 전체 레이아웃을 다룰 좋은 연습이 아닙니다.