Search code examples
androidandroid-layoutandroid-viewandroid-scrollview

Android - adding views to layout


I have a linear layout for which i will add views to make it a list like view, (reason for not using an android list view is, i am using this layout inside scroll view of my sliding menu and came to know list view cant be directly used in the scroll view). I don't know whether i heard it wrong or not, but all i want is scroll view and inside it, a scrollable list of options for the user to choose from as shown below:

enter image description here

my scroll view looks something like this:

<scrollview>
  <main layout>
       <some layout>
       <some layout>
       <some layout>
       <some layout> ////i wanted a list view here. as listview cant be used directly inside 
                          scrollview, i add views in the code to make it a list 
                         like view which has image view and checkedtextview to make it look like a
                         list view

  <main layout>
<scrollview>

now, the problem is after adding one view, i should also add the divider to separate two consecutive views. here is my complete scrollable layout.xml code http://pastebin.com/YZPj9w4C

here is my layout (list_item_category) which i add as a single view http://pastebin.com/htCTKmdT to the above scrollable layout.xml

here is my code which i use to inflate a view onto the layout:

for (int i = 0; i < 9; i++) {
            panelView = inflater.inflate(R.layout.dialog_list_item_category,
                    null, false);
            panelView.setId(i);

            final CheckedTextView chk = (CheckedTextView) panelView
                    .findViewById(R.id.categories_checkbox);

            chk.setText(some text);

            ImageView img = (ImageView) panelView
                    .findViewById(R.id.categories_icon);

            img.setImageResource(some icon);
}

To summarise, i need a divider line after inflating each view onto the layout.

any idea how to do that?


Solution

  • TextView with specified height, width and color will work. Try to add this,

    <TextView
    android:layout_width="fill_parent"
    android:layout_height="5dp"
    android:background="#colorCode"    
    />
    

    TextView basically is it. You can add extra attributes if you want, but the key point is height of textview and listview_divider should be equal and also background color of textview and listview divider too. In ListView for divider height and color you can use

    android:divider="#colorCode"
    android:dividerHeight="sameAsTextViewHeight"