Last active
November 13, 2015 10:42
-
-
Save walteranyika/8031b5db955228c4e29d to your computer and use it in GitHub Desktop.
Sample Custom Adapter Class for CustomList
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import android.app.Activity; | |
import android.content.Context; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.BaseAdapter; | |
import android.widget.TextView; | |
public class CustomAdapter extends BaseAdapter { | |
Context mContext; | |
ArrayList<Child> data;//modify here | |
public CustomAdapter(Context context, ArrayList<Child> data) //modify here | |
{ | |
this.mContext = context; | |
this.data = data; | |
} | |
@Override | |
public int getCount() { | |
return data.size();// # of items in your arraylist | |
} | |
@Override | |
public Object getItem(int position) { | |
return data.get(position);// get the actual movie | |
} | |
@Override | |
public long getItemId(int id) { | |
return id; | |
} | |
@Override | |
public View getView(int position, View convertView, ViewGroup parent) { | |
ViewHolder viewHolder; | |
if (convertView == null) { | |
LayoutInflater inflater = ((Activity) mContext).getLayoutInflater(); | |
convertView = inflater.inflate(R.layout.list_item_layout, parent,false);//modify here | |
viewHolder = new ViewHolder(); | |
viewHolder.textViewNames = (TextView) convertView.findViewById(1);//modify here | |
viewHolder.textViewLoc = (TextView) convertView.findViewById(2);//modify here | |
viewHolder.textViewAge = (TextView) convertView.findViewById(3);//modify here | |
viewHolder.textViewGender = (TextView) convertView.findViewById(4);//modify here | |
convertView.setTag(viewHolder); | |
} else { | |
viewHolder = (ViewHolder) convertView.getTag(); | |
} | |
Child b = data.get(position);//modify here | |
viewHolder.textViewNames.setText("Names");//modify here | |
viewHolder.textViewLoc.setText("Email");//modify here | |
viewHolder.textViewAge.setText("Age");//modify here | |
viewHolder.textViewGender.setText("Male");//modify here | |
return convertView; | |
} | |
static class ViewHolder { | |
TextView textViewNames;//modify here | |
TextView textViewLoc;//modify here | |
TextView textViewAge;//modify here | |
TextView textViewGender;//modify here | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment