I would like to ask 4 questions. I am building a adapter for my listview which i plan to have multi-columns. My friend has recommend me the following code, the code work but i still have queries about part of the code.
Since
public listviewAdapter(Activity activity, ArrayList<HashMap> list)
does not return anything, shouldnt the code be public void.Doesn't
super()
have to have anything insideWhat does
(convertView == null)
doesLast but not least, can I use other thing beside
HashMap
.
when i try to build my own adapter out of her code, i got the following errors:
Constructor call must be the first statement in a constructor
Return type for the method is missing
And under my main activity:
The constructor listviewadapter(new View.OnClickListener(){}, ArrayList<HashMap>) is undefined
public class listviewAdapter extends BaseAdapter{ public ArrayList<HashMap> list; Activity activity; public listviewAdapter(Activity activity, ArrayList<HashMap> list) { super(); this.activity = activity; this.list = list; } @Override public int getCount() { return list.size(); } @Override public Object getItem(int position) { return list.get(position); } @Override public long getItemId(int position) { return 0; } private class ViewHolder { TextView txtFirst; TextView txtSecond; TextView txtThird; TextView txtFourth; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; LayoutInflater inflater = activity.getLayoutInflater(); if (convertView == null){ convertView = inflater.inflate(R.layout.listview_row, null); holder = new ViewHolder(); holder.txtFirst = (TextView) convertView.findViewById(R.id.FirstText); holder.txtSecond = (TextView) convertView.findViewById(R.id.SecondText); holder.txtThird = (TextView) convertView.findViewById(R.id.ThirdText); holder.txtFourth = (TextView) convertView.findViewById(R.id.FourthText); convertView.setTag(holder); }else{ holder = (ViewHolder) convertView.getTag(); } HashMap map = list.get(position); holder.txtFirst.setText((CharSequence) map.get(FIRST_COLUMN)); holder.txtSecond.setText((CharSequence) map.get(SECOND_COLUMN)); holder.txtThird.setText((CharSequence) map.get(THIRD_COLUMN)); holder.txtFourth.setText((CharSequence) map.get(FOURTH_COLUMN)); return convertView; } }