Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.leaderinfo;
- import android.content.Context;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.BaseAdapter;
- import android.widget.ImageView;
- import android.widget.TextView;
- public class CustomAdapter extends BaseAdapter {
- int[] imgs;
- String[] leaderNames;
- Context context;
- private LayoutInflater inflater;
- CustomAdapter(Context context, String[] leaderNames,int[] imgs)
- {
- this.context=context;
- this.leaderNames=leaderNames;
- this.imgs=imgs;
- }
- @Override
- public int getCount() {
- return leaderNames.length;
- }
- @Override
- public Object getItem(int i) {
- return null;
- }
- @Override
- public long getItemId(int i) {
- return 0;
- }
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- if(convertView ==null)
- {
- inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- convertView = inflater.inflate(R.layout.sample_view,parent,false);
- }
- ImageView imageView= (ImageView) convertView.findViewById(R.id.imageViewId);
- TextView textView= (TextView) convertView.findViewById(R.id.leaderName);
- imageView.setImageResource(imgs[position]);
- textView.setText(leaderNames[position]);
- return convertView;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment