Skip to content Skip to sidebar Skip to footer

A Row In List View Changes When Scrolled (android Studio)

I tried to create a multicolumn listview by following this tutorial: http://techlovejump.com/android-multicolumn-listview/ . The problem occured, when the amount of records was so

Solution 1:

Please try this code:

publicclassListViewAdaptersextendsBaseAdapter {

publicArrayList<HashMap<String, String>> list;
Activity activity;
TextView txtFirst;
TextView txtSecond;
TextView txtFourth;

publicListViewAdapters(Activity activity, ArrayList<HashMap<String, String>> list){
    super();
    this.activity=activity;
    this.list=list;
}

@Overridepublic int getCount() {
    // TODO Auto-generated method stubreturn list.size();
}

@OverridepublicObjectgetItem(int position) {
    // TODO Auto-generated method stubreturn list.get(position);
}

@Overridepublic long getItemId(int position) {
    // TODO Auto-generated method stubreturn0;
}



@OverridepublicViewgetView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stubViewHolder holder;
    HashMap<String, String> map=list.get(position);
    LayoutInflater inflater=activity.getLayoutInflater();

    if(convertView == null) {
        holder = newViewHolder();
        if (map.get(MARKED) == "no") {
            convertView = inflater.inflate(R.layout.colmn_row, null);
        } elseif (map.get(MARKED) == "yes") {
            convertView = inflater.inflate(R.layout.colmn_row_clicked, null);
        }
        holder.txtFirst = (TextView) convertView.findViewById(R.id.name);
        holder.txtSecond = (TextView) convertView.findViewById(R.id.gender);
        holder.txtFourth = (TextView) convertView.findViewById(R.id.status);

        holder.txtFirst.setText(map.get(FIRST_COLUMN));
        holder.txtSecond.setText(map.get(SECOND_COLUMN));
        holder.txtFourth.setText(map.get(FOURTH_COLUMN));
    }else {
        holder = (ViewHolder) convertView.getTag();
    }
    return convertView;
}

@Overridepublic int getItemViewType(int position) {
    return position;
}

@Overridepublic int getViewTypeCount() {
    returngetCount();
}

publicclassViewHolder {
    TextView txtFirst, txtSecond,txtFourth;

}

}

Post a Comment for "A Row In List View Changes When Scrolled (android Studio)"