2016-05-20 16 views
-1

中添加動態textView我想添加下面的代碼來動態地添加textview,但我沒有在我的活動中看到任何textview。我不能添加一個列表視圖,因爲我已經在使用recycleview。任何人有任何錯誤?無法在android

   { 

        LayoutInflater layoutInflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
        LinearLayout review_layout = (LinearLayout) rootMovieView.findViewById(R.id.review_comment); 

        for (ReviewsResult comment : review.getReviewsResults()) { 

         View view = layoutInflater.inflate(R.layout.layout_movie_comments, review_layout, false); 

         TextView tvCommentBy = (TextView) view.findViewById(R.id.tv_comment_by); 

         TextView tvCommentContent = (TextView) view.findViewById(R.id.tv_comment_content); 

         tvCommentContent.setText(comment.getContent()); 
         tvCommentBy.setText(comment.getAuthor()); 

         review_layout.addView(view); 
        } 
       } 
+0

您是否在活動中正確調用了setContentView – Konstantin

回答

0

您也可以嘗試這樣的事情

View myLay; // view that contains you textView 
LinearLayout rootlay; //root view in which you want to add 

    myLay = LayoutInflater.from(this).inflate(R.layout.layout_movie_comments, 
        null); 

    TextView tvCommentBy = (TextView) view.findViewById(R.id.tv_comment_by); 

    TextView tvCommentContent = (TextView) myLay.findViewById(R.id.tv_comment_content); 

     tvCommentContent.setText(comment.getContent()); 
     tvCommentBy.setText(comment.getAuthor()); 

     rootlay.addView(myLay); 

希望這有助於:)

0

做以下兩個變化,並檢查天氣是工作或沒有,因爲沒有別的似乎錯碼。

LayoutInflater inflater = getActivity().getLayoutInflater(); 

    View view = layoutInflater.inflate(R.layout.layout_movie_comments, null); 
+0

對不起,隊友,它不會添加視圖。 –

0

rootMoviewView不是它是在在rootView產生不recylceView TextView的一個rootView。這方式recylceView的rootView。