0

I am trying to show some views based on certain conditions in getView() in Android. This is my code:

@Override
public View getView(int position, View view, ViewGroup parent) {
if (view == null) {
        final LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if(Type.equals("note"))
{
view = inflater.inflate(R.layout.note, parent, false);
}
else
{
view = inflater.inflate(R.layout.event, parent, false);
    }
}

However it is not working since android recycles the last inflated layout and displays it.

Are there any workarounds?

Kalimah
  • 11,217
  • 11
  • 43
  • 80
  • What if inflate both always and then make only one visible? – slkorolev Oct 06 '11 at 20:43
  • When you scroll list in Android device, layout will be recycled and you will get a strange behavior. I actually inflated one layout and tried to make some views inside it invisible. However, on the device, when scroll up and down for couple of times all rows follow the same rule because of view recycling. – Kalimah Oct 06 '11 at 20:48

1 Answers1

4

If you want your ListView to have different layouts for rows you can find more info here: Android ListView with different layouts for each row

Community
  • 1
  • 1
ciscogambo
  • 1,160
  • 11
  • 18