0

Currently my listview is working fine to return one view but I want it to check when the currentVerse.getVerseNumber()==1 and return two different views (rows) if the condition is true. I cannot figure it out, Any help will be highly appreciated.

    public View getView(int position, View convertView, ViewGroup parent) {
        VersesModel currentVerse = verses.get(position);
        if (convertView == null) {
            convertView = getActivity().getLayoutInflater().inflate(
                    R.layout.verses_custom_list, parent, false);
            viewHolder = new ViewHolder();
            font = Typeface.createFromAsset(convertView.getContext().getAssets(), "my_font.ttf");
            viewHolder.textView = (TextView) convertView.findViewById(R.id.textView_Verse);
            viewHolder.nView = (TextView) convertView.findViewById(R.id.textView_verseNumber);
            viewHolder.textView.setTypeface(font);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.textView.setText(currentVerse.getVerseText().toString());
        viewHolder.nView.setText(currentVerse.getVerseNumber() + "");
        convertView.setTag(viewHolder);
        return convertView;
    }
Aalem
  • 115
  • 1
  • 9
  • http://stackoverflow.com/questions/19723277 –  Apr 05 '15 at 14:29
  • decide view type according to your value, see this http://stackoverflow.com/questions/4777272/android-listview-with-different-layout-for-each-row – Harin Apr 06 '15 at 10:06

1 Answers1

0

Its simple according to me ....

Create a layout with both views in the same layout which you want to show...

And suppose for condition true you want to show LinearLayout-A and for false u want to show LinearLayout-B then its simple use View.Visibility

if(true)
{
    LinearLayout-B.setVisibility(View.GONE);
    LinearLayout-A.setVisibility(View.VISIBLE);
}
else
{
    LinearLayout-A.setVisibility(View.GONE);
    LinearLayout-B.setVisibility(View.VISIBLE);
}

btw im using both because rememember listview paints everytime the view is created after its hidden so to make it easy and robust otherwise it wud just mess up alot...

Hope it helps u ...

Thanks

Ahmad
  • 437
  • 1
  • 4
  • 12