In my listView I have 3 row types, TXT, IMG, SMS. Each one has different row layout and works fine like this:
... extends BaseAdapter ...
public View getView(int position, View convertView, ViewGroup parent) {
TextViewHolder textViewHolder = null;
ImageHolder imageHolder = null;
SmsHolder smsHolder = null;
//PlaceHolder placeHolder = null;
ConversionModel conversion = getItem(position);
int type = conversion.type;
if (convertView == null) {
if(type == ConversionModel.TXT) {
textViewHolder = new TextViewHolder();
convertView = mInflater.inflate(R.layout.convers_txt, null);
textViewHolder.textView = (TextView)convertView.findViewById(R.id.row_txt);
convertView.setTag(textViewHolder);
}
if(type == ConversionModel.IMG) {
imageHolder = new ImageHolder();
convertView = mInflater.inflate(R.layout.convers_img, null);
imageHolder.img = (ImageHolder)convertView.findViewById(R.id.row_txt);
convertView.setTag(textViewHolder);
}
....
}
...
}
My purpose is this:
-alllist-----------
----txt------------
----img------------
-----(multipledata) //placeholder must has dynamic rows in it
--------button-----
--------button-----
---sms-------------
.....
My placeHolder must has dynamic rows in it because I don't know the numbers of data that comes from server. I tried to do it nested listview but it only shows first data in the list.
Also I put a LinearLayout to placeHolder and added items like this(pseudo):
for data in datas {
Button btn = new Button(ctx)
...
placeHolder.layout.addView(btn);
}
But whenever I scroll the listView, getView method is messing and it's rendering same buttons almost 10-20 times, when it should be 2-3.
How can I achieve this? I looked at app sources like Telegram but couldn't found similar approaches.
Solution:
String arr[] = conversion.message.split(Pattern.quote("$$"));
LinearLayout layHolder = new LinearLayout(ctx);
for (int i = 0; i < arr.length; i++) {
Button test_btn = new Button(ctx);
//PlaceModel pm = new PlaceModel(arr[i]);
layHolder.addView(test_btn);
}
placeHolder.linearLay.removeAllViews(); //<- THIS
placeHolder.linearLay.addView(layHolder);