I have made a custom adapter based on the Baseadapter and a problem arises when I scroll the data in the list. The data gets all scrambled up. My guess is that my adapter keeps creating views but, I need one you of experts to take a look at my adapter code and point out the problem if you can my problem. I think I must have some problem with the getView() method.
public class ListViewAdapter extends BaseAdapter {
public ArrayList<HashMap<String, String>> list;
Activity activity;
TextView txtFirst;
TextView txtSecond;
TextView txtThird;
TextView txtFourth;
TextView txtFifth;
TextView txtSixth;
TextView txtSeventh;
TextView txtEighth;
public ListViewAdapter(Activity activity,ArrayList<HashMap<String, String>> list){
super();
this.activity=activity;
this.list=list;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return list.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
//LayoutInflater inflater=activity.getLayoutInflater();
if(convertView == null){
LayoutInflater inflater=activity.getLayoutInflater();
convertView=inflater.inflate(R.layout.colmn_row, null);
txtFirst=(TextView) convertView.findViewById(R.id.range);
txtSecond=(TextView) convertView.findViewById(R.id.dropin);
txtThird=(TextView) convertView.findViewById(R.id.dropmoa);
txtFourth=(TextView) convertView.findViewById(R.id.windin);
txtFifth=(TextView) convertView.findViewById(R.id.windmoa);
txtSixth=(TextView) convertView.findViewById(R.id.velocity);
txtSeventh=(TextView) convertView.findViewById(R.id.energy);
txtEighth=(TextView) convertView.findViewById(R.id.time);
}
HashMap<String, String> map=list.get(position);
txtFirst.setText(map.get(FIRST_COLUMN));
txtSecond.setText(map.get(SECOND_COLUMN));
txtThird.setText(map.get(THIRD_COLUMN));
txtFourth.setText(map.get(FOURTH_COLUMN));
txtFifth.setText(map.get(FIFTH_COLUMN));
txtSixth.setText(map.get(SIXTH_COLUMN));
txtSeventh.setText(map.get(SEVENTH_COLUMN));
txtEighth.setText(map.get(EIGHTH_COLUMN));
return convertView;
}
}