0

I know how to create a custom listview in android. But like in iPhone application development we can set multiple different uicellview styles for each row. Is it possible in android if yes how can we achive this. Your help will be appreciated

Muhammad Aamir Ali
  • 20,419
  • 10
  • 66
  • 57
  • 1
    http://stackoverflow.com/questions/17370525/listview-adapter-with-arbitrary-number-of-row-types-dont-know-the-number-of-di/17370772#17370772. check this. – Raghunandan Jul 06 '13 at 13:57

2 Answers2

1

use the position of the item in your getView method.

Pseudo:

public View getView(int position, View recycledView, ViewGroup group) {
   View view;
   if(position == 1){
        view = View.inflate(context, R.layout.view1, null);
   } else {
        view = View.inflate(context, R.layout.view2, null);
   }

  // populate the view

return view;
}

Reference: http://developer.android.com/reference/android/widget/Adapter.html#getView(int, android.view.View, android.view.ViewGroup)

http://developer.android.com/reference/android/view/View.html#inflate(android.content.Context, int, android.view.ViewGroup)

Blundell
  • 75,855
  • 30
  • 208
  • 233
0

You can achieve this by inflating multiple xml layout files and return them based on condition .

For example inside your getview() method of adapter

you can do like this

for condition 1 

inflate layout 1 and return view

for condition 2 

inflate layout 2 and return view.
kaushal trivedi
  • 3,405
  • 3
  • 29
  • 47