Description: In this post I'm gonna show you how we can have multiple row layout in Android's Material Design RecyclerView using getItemViewType.
GitHub Project HERE
So lets get started :-)
Step 1: Create Recycler Adapter by overriding getItemViewType method and giving the type for different layout as shown below.
compile 'com.android.support:cardview-v7:23.0.0' compile 'com.android.support:recyclerview-v7:23.0.0'
GitHub Project HERE
So lets get started :-)
Step 1: Create Recycler Adapter by overriding getItemViewType method and giving the type for different layout as shown below.
@Override public int getItemViewType(int position) { MultipleRowModel multipleRowModel = multipleRowModelList.get(position); if (multipleRowModel != null) return multipleRowMod.type; return super.getItemViewType(position); }
Step 2: Create a viewHolder as per viewType . We can create different row layout using viewType .
Note: viewType in onCreateviewholder is retured from getItemViewType in Step 1.
Note: viewType in onCreateviewholder is retured from getItemViewType in Step 1.
@Override public MultipleRowViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = null; if (viewType == AppConstant.FIRST_ROW) view = inflater.inflate(R.layout.view_row_first, parent, false); else if (viewType == AppConstant.OTHER_ROW) view = inflater.inflate(R.layout.view_row_other, parent, false); return new MultipleRowViewHolder(view, viewType); }
Step 3: Lets integrated all this in one RecyclerView adapter.
public class MultipleRowAdapter extends RecyclerView.Adapter<MultipleRowViewHolder> { private LayoutInflater inflater = null; private List<MultipleRowModel> multipleRowModelList; public MultipleRowAdapter(Context context, List<MultipleRowModel> multipleRowModelList){ this.multipleRowModelList = multipleRowModelList; inflater = LayoutInflater.from(context); } @Override public MultipleRowViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = null; if (viewType == AppConstant.FIRST_ROW) view = inflater.inflate(R.layout.view_row_first, parent, false); else if (viewType == AppConstant.OTHER_ROW) view = inflater.inflate(R.layout.view_row_other, parent, false); return new MultipleRowViewHolder(view, viewType); } @Override public void onBindViewHolder(MultipleRowViewHolder holder, int position) { holder.multipleContent.setText(multipleRowModelList.get(position).modelContent); } @Override public int getItemCount() { return (multipleRowModelList!= null && multipleRowModelList.size() > 0 ) ? multipleRowModelList.size() : 0; } @Override public int getItemViewType(int position) { MultipleRowModel multipleRowModel = multipleRowModelList.get(position); if (multipleRowModel != null) return multipleRowModel.type; return super.getItemViewType(position); } }
Step 4: Finally our MainActivity looks something like this.
public class MainActivity extends AppCompatActivity { private RecyclerView multipleRowRecyclerView; private MultipleRowAdapter multipleRowAdapter; private List<MultipleRowModel> multipleRowModelList = new ArrayList<>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); multipleRowRecyclerView = (RecyclerView)findViewById(R.id.multipleRowRecyclerView); multipleRowRecyclerView.setHasFixedSize(true); LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, OrientationHelper.VERTICAL, false); multipleRowRecyclerView.setLayoutManager(linearLayoutManager); multipleRowRecyclerView.setItemAnimator(new DefaultItemAnimator()); fillAdapter(); multipleRowAdapter = new MultipleRowAdapter(MainActivity.this, multipleRowModelList); multipleRowRecyclerView.setAdapter(multipleRowAdapter); } private void fillAdapter() { int type; String content; for (int i = 0; i < 10; i++) { if (i == 0 || i == 5 || i == 9) { type = AppConstant.FIRST_ROW; content = "Type 1: This is Multiple row layout"; } else { type = AppConstant.OTHER_ROW; content = "Type 2"; } multipleRowModelList.add(new MultipleRowModel(type , content)); } } }
It's interesting that many of the bloggers to helped clarify a few things for me as well as giving.Most of ideas can be nice content.The people to give them a good shake to get your point and across the command.
ReplyDeletesoftware testing course in chennai
Great Article. Thank you for sharing! Really an awesome post for every one.
DeleteProject Centers in Chennai
JavaScript Training in Chennai
Final Year Project Domains for IT
JavaScript Training in Chennai
Hello, I appreciate your valuable tutorials. Is it suitable for all devices? You know each device is different from others.. thanks all~ Michael Jason from CatLight-Notifier for developers
ReplyDelete
ReplyDeleteThis is an awesome post. Really very informative and creative contents. This concept is a good way to enhance knowledge. I like it and help me to development very well. Thank you for this brief explanation and very nice information. Well, got good knowledge.
WordPress development company in Chennai
Aivivu - đại lý vé máy bay, tham khảo
ReplyDeletevé máy bay đi Mỹ bao nhiêu tiền
vé máy bay tết 2021 Vietnam Airline
ve may bay di Phap gia re
thời gian bay từ Hà Nội sang Anh
vé máy bay giá rẻ khứ hồi
vé máy bay giá rẻ đi San Francisco
vé máy bay từ Hà nội đi Los Angeles
mua combo vinpearl phú quốc
combo du lịch đà nẵng hội an
Excellent post. I want to thank you for this informative read, I really appreciate sharing this great post. Keep up your work… mobile app development company
ReplyDeleteĐặt mua vé máy bay liên hệ Aivivu
ReplyDeleteVé máy bay đi Mỹ
giá vé từ mỹ về việt nam
giá vé máy bay từ anh về việt nam
chuyến bay từ pháp về việt nam
rastgele görüntülü konuşma - kredi hesaplama - instagram video indir - instagram takipçi satın al - instagram takipçi satın al - tiktok takipçi satın al - instagram takipçi satın al - instagram beğeni satın al - instagram takipçi satın al - instagram takipçi satın al - instagram takipçi satın al - instagram takipçi satın al - binance güvenilir mi - binance güvenilir mi - binance güvenilir mi - binance güvenilir mi - instagram beğeni satın al - instagram beğeni satın al - polen filtresi - google haritalara yer ekleme - btcturk güvenilir mi - binance hesap açma - kuşadası kiralık villa - tiktok izlenme satın al - instagram takipçi satın al - sms onay - paribu sahibi - binance sahibi - btcturk sahibi - paribu ne zaman kuruldu - binance ne zaman kuruldu - btcturk ne zaman kuruldu - youtube izlenme satın al - torrent oyun - google haritalara yer ekleme - altyapısız internet - bedava internet - no deposit bonus forex - erkek spor ayakkabı - webturkey.net - karfiltre.com - tiktok jeton hilesi - tiktok beğeni satın al - microsoft word indir - misli indir
ReplyDeleteaşk kitapları
ReplyDeleteyoutube abone satın al
cami avizesi
cami avizeleri
avize cami
no deposit bonus forex 2021
takipçi satın al
takipçi satın al
takipçi satın al
takipcialdim.com/tiktok-takipci-satin-al/
instagram beğeni satın al
instagram beğeni satın al
btcturk
tiktok izlenme satın al
sms onay
youtube izlenme satın al
no deposit bonus forex 2021
tiktok jeton hilesi
tiktok beğeni satın al
binance
takipçi satın al
uc satın al
sms onay
sms onay
tiktok takipçi satın al
tiktok beğeni satın al
twitter takipçi satın al
trend topic satın al
youtube abone satın al
instagram beğeni satın al
tiktok beğeni satın al
twitter takipçi satın al
trend topic satın al
youtube abone satın al
takipcialdim.com/instagram-begeni-satin-al/
perde modelleri
instagram takipçi satın al
instagram takipçi satın al
takipçi satın al
instagram takipçi satın al
betboo
marsbahis
sultanbet
beğeni satın al
ReplyDeleteinstagram takipçi satın al
ucuz takipçi
takipçi satın al
https://takipcikenti.com
https://ucsatinal.org
instagram takipçi satın al
https://perdemodelleri.org
https://yazanadam.com
instagram takipçi satın al
balon perdeler
petek üstü perde
mutfak tül modelleri
kısa perde modelleri
fon perde modelleri
tül perde modelleri
https://atakanmedya.com
https://fatihmedya.com
https://smmpaketleri.com
https://takipcialdim.com
https://yazanadam.com
yasaklı sitelere giriş
aşk kitapları
yabancı şarkılar
sigorta sorgula
https://cozumlec.com
word indir ücretsiz
tiktok jeton hilesi
rastgele görüntülü sohbet
erkek spor ayakkabı
fitness moves
gym workouts
https://marsbahiscasino.org
http://4mcafee.com
http://paydayloansonlineare.com
www.escortsmate.com
ReplyDeleteescortsmate.com
https://www.escortsmate.com
marsbahis
ReplyDeletebetboo
sultanbet
marsbahis
betboo
sultanbet
I think you can try out the different version of it, you can also check out whatsapp lite apk download original apk it will provide you complete apk file with unlock features.
ReplyDeleteJust wanted to congratulate you for such an amazing contents,So happy to read your post!
ReplyDeletedachshund puppies for sale
dachshund puppy for sale
dachshunds puppies for sale
dachshund puppies sale
dachshund for sale
dachshund puppies for sale near me
dachshunds for sale
mini dachshund puppy for sale
mini dachshund puppies for sale
I'm happy I came acorss this blog,you are really a content builder,I will be coming back to read more post from you{.
ReplyDeleteThanks
toy poodle for sale
poodles for sale
poodle for sale
teacup poodles for sale
teacup poodle for sale
toy poodle for sale near me
poodle for sale near me
mini poodle for sale
poodle puppy for sale
Please guys let give this blog FIVE STAR Rating
ReplyDeletedapple dachshund puppies for sale
miniature long haired dachshund puppies for sale
miniature long haired dachshund for sale
dachshund puppies for sale under $500
long haired dachshund puppies for sale
teacup chihuahua for sale
chihuahua puppies for sale
chihuahua for sale
https://Greenlandpuppies.com
https://oneshoppharmacy.com
A very nice guide. Thank you for sharing such detailed article.
ReplyDeleteAre you planning to develop an On-Demand fuel delivery app? get the full details about the on-demand fuel delivery app development cost, features & benefits. Contact us now!