2012-01-26 11 views
5

मेरे पास एक गतिविधि है जो टिप्पणियां प्रदर्शित करती है। टिप्पणियों में स्वयं का एक लेआउट होता है, इसलिए मैं केवल सूची दृश्य का उपयोग नहीं कर सकता।रैखिक स्तर पर प्रोग्राम जोड़ें

मैं लूप के साथ टिप्पणियां जोड़ रहा हूं, और प्रोग्राम पूरे लूप (लॉगकैट के माध्यम से चेक किया गया) के माध्यम से जाता है, लेकिन केवल लाइनरलेआउट में पहली दृश्य (टिप्पणी) जोड़ता है।

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.comment_layout); 
    String[] comments = {"kommentaar 1", "kommentaar 2", "kommentaar 3"}; 
    mTitle = (TextView) findViewById(R.id.comments_title); 
    mTextArea = (EditText) findViewById(R.id.comment_editor); 
    mAddButton = (Button) findViewById(R.id.add_comment); 
    mCommentArea = (LinearLayout) findViewById(R.id.comments_area); 

    mTitle.setText(getIntent().getStringExtra("name")); 
    fillComments(comments); 
} 

private void fillComments(String[] comments) { 
    View comment; 
    TextView commentator; 
    TextView commentDate; 
    TextView commentText; 
    LayoutInflater inflater = getLayoutInflater(); 

    for (String s : comments) { 
     Log.d("Comment adder", "Adding comment " + s); 
     comment = inflater.inflate(R.layout.comment_row_layout, null); 
     commentator = (TextView) comment.findViewById(R.id.commentator); 
     commentDate = (TextView) comment.findViewById(R.id.comment_date); 
     commentText = (TextView) comment.findViewById(R.id.comment_text); 
     commentator.setText("Test commentator"); 
     commentDate.setText("12-12-2012"); 
     commentText.setText(s); 
     mCommentArea.addView(comment); 
    } 
} 
+0

का आनंद लें यदि यह भी होता है कि 'R.id.comments_area' अभिविन्यास लंबवत + चौड़ाई fill_parent है? और लॉग ("टिप्पणी योजक") कई बार प्रदर्शित होता है? – louiscoquio

+0

क्या आप हमें लेआउट दिखा सकते हैं: comment_row_layout.xml .. मुझे लगता है कि आपके पास क्षैतिज अभिविन्यास है ... –

उत्तर

6

मुझे लगता है कि mCommentArea = (LinearLayout) findViewById(R.id.comments_area); इस लेआउट उन्मुखीकरण क्षैतिज है तो यह समस्या है होता है। कृपया क्षैतिज उन्मुखताएं तो कृपया इसे लंबवत में बदलें और

+0

आपने बस मुझे इस पर एक टन बचाया, चीयर्स! – ryanwils

2

कैसे आप LinearLayout परिभाषित किया है:

मेरे कोड (वास्तविकता में fillComments पैरामीटर से String [] कुछ और हो जाएगा)? यह सिर्फ एक प्रदर्शन मुद्दा हो सकता है। LinearLayout के आकार और अभिविन्यास की जांच करें।

+0

आप सही हैं, मैं अपने LinearLayout पर 'android: orientation =" लंबवत "पंक्ति जोड़ना भूल गया था। – j0ntech