0

I want to create an Activity with 2 lists. Temporarily I've created 2 listViews with different rows declared in adequate *.xml files, and divided the screen 50/50, but it doesn't look nice. That's why I want to make one scrollview with rows from first listView, separator and then rows from second listView.

Can I use what I already have (xml files defining layout of rows)?

Do I need to make new class extending View or there is other way?

I have to add that each row has about 5 controls that need to be set, so it is not very simple row.

Pankaj Kumar
  • 81,967
  • 29
  • 167
  • 186
karex
  • 221
  • 1
  • 6
  • 14
  • Do you really need to scrolling views? Why dont you just add them both to the same scrollView? This is very easy to do programatically – Jameo Jun 17 '13 at 15:41
  • I want it to be separated - so the first line is a label, maybe with image, then first list, then separator, another label, maybe image and then the second list. How can I add separator to the list? The third type of entry for ListView? And you mean that after insertion of many items of different types i just make an if statement in getView that gets to know whether it is the first or the other type? – karex Jun 17 '13 at 16:04
  • 1
    Yes, basically. You will have 3(maybe more) types of rows. You have your first lists row, your second lists row, and then a separator (with image, or whatever). You will insert a separator, then loop through the first list. Insert second separator, loop through second list – Jameo Jun 17 '13 at 16:25
  • Thanks man! That would make everything much simpler. I am reading about such solution here http://stackoverflow.com/questions/3514548/creating-viewholders-for-listviews-with-different-item-layouts and want to ask you if you know what are those ViewHolders? Looks like I'll need them. – karex Jun 17 '13 at 16:37
  • all a view holder is is just an object that holds your views, for easy access and organization. – Jameo Jun 18 '13 at 18:14

2 Answers2

1

You could do what your saying, which would still use a listView. ListViews can be tricky because you have to match the number of rows with the number of items in your adapter. What I was saying is you could just use a scrollView to start. You wont see a performance increase unless your talking about several hundred rows.

Here is how to inflate a row, and add it to a scrollview programmatically

ScrollView scrollView = (ScrollView)findViewById(R.id.scrollView);
...
for(int i = 0; i < firstList.size(); i++){
   //here my row was a relative layout.  Could be LinearLayout, or anything 
   RelativeLayout row = (RelativeLayout)View.inflate(this, R.layout.list_row, null);
   tv = (TextView)row.findViewById(R.id.tv);
   tv.setText("Some text");
   ...initialize other views in row
   scrollView.addView(row);
}

then just repeat for your second list, and dont forget to insert your seperators

Jameo
  • 4,507
  • 8
  • 40
  • 66
1

You might need to learn custom adepter .

you can customize your list item's order . lets say you have 10 total item to show in on screen and you want to separate it in 5/5 .

here is basic logic according to above scenario

@Override
public View getView(int position, View convertView, ViewGroup parent) 
    {

     if (postion<5)
    {
    //Write your code here for first five items 
    }
    else{
    //Write your code here for rest five items 
    }

}
dharmendra
  • 7,835
  • 5
  • 38
  • 71