Created
July 8, 2014 14:45
-
-
Save pavlospt/cd548155a96fbb753b7c to your computer and use it in GitHub Desktop.
CustomAdapter for my Blog
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
@Override | |
public View getView(int position, View convertView, ViewGroup parent) { | |
ViewHolder holder; | |
//If convertView is null, we inflate our Layout in convertView. | |
if (convertView == null) { | |
convertView = mInflater.inflate(R.layout.item_layout, parent, false); | |
//We instantiate our ViewHolder object, in order to use it below. | |
holder = new ViewHolder(); | |
//Let's say that our custom layout file contains only one TextView. | |
//So we use the ViewHolder pattern to instantiate it. | |
holder.mTextView = (TextView) convertView.findViewById(R.id.textView); | |
convertView.setTag(holder); | |
} else { | |
holder = (ViewHolder) convertView.getTag(); | |
} | |
//Because we extend ArrayAdapter, we can use the position and retrieve | |
//the current object using the getItem(int i) method. | |
String item = getItem(position); | |
//We only execute the following, if our item is not null. | |
if (item != null){ | |
holder.mTextView.setText(item); | |
} | |
return convertView; | |
} | |
private static class ViewHolder { | |
TextView mTextView; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment