Created
July 25, 2017 04:18
-
-
Save talhahasanzia/1b6df4ebcf4f491f605e6a60adfffeb7 to your computer and use it in GitHub Desktop.
ListAdapter Biolerplate from: https://stackoverflow.com/questions/8166497/custom-adapter-for-list-view
This file contains hidden or 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
public class ListAdapter extends ArrayAdapter<Item> { | |
public ListAdapter(Context context, int textViewResourceId) { | |
super(context, textViewResourceId); | |
} | |
public ListAdapter(Context context, int resource, List<Item> items) { | |
super(context, resource, items); | |
} | |
@Override | |
public View getView(int position, View convertView, ViewGroup parent) { | |
View v = convertView; | |
if (v == null) { | |
LayoutInflater vi; | |
vi = LayoutInflater.from(getContext()); | |
v = vi.inflate(R.layout.itemlistrow, null); | |
} | |
Item p = getItem(position); | |
if (p != null) { | |
TextView tt1 = (TextView) v.findViewById(R.id.id); | |
TextView tt2 = (TextView) v.findViewById(R.id.categoryId); | |
TextView tt3 = (TextView) v.findViewById(R.id.description); | |
if (tt1 != null) { | |
tt1.setText(p.getId()); | |
} | |
if (tt2 != null) { | |
tt2.setText(p.getCategory().getId()); | |
} | |
if (tt3 != null) { | |
tt3.setText(p.getDescription()); | |
} | |
} | |
return v; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment