Skip to content

Instantly share code, notes, and snippets.

@RaghavSood
Created April 10, 2014 02:49
Show Gist options
  • Save RaghavSood/10338788 to your computer and use it in GitHub Desktop.
Save RaghavSood/10338788 to your computer and use it in GitHub Desktop.
package com.appaholics.buzz;
import android.graphics.drawable.Drawable;
public class ListRow {
private Drawable image;
private String title;
private String packageName;
private boolean selected;
public ListRow(Drawable image, String title, String packageName) {
this.image = image;
this.title = title;
this.packageName = packageName;
}
public Drawable getImage() {
return image;
}
public void setImage(Drawable image) {
this.image = image;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
@Override
public String toString() {
return title + "\n" + packageName;
}
public String getPackageName() {
return packageName;
}
public void setPackageName(String packageName) {
this.packageName = packageName;
}
public boolean isSelected() {
return selected;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
}
package com.appaholics.buzz;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class RowAdapter extends ArrayAdapter<ListRow> {
private Context mContext;
ViewHolder holder = null;
public RowAdapter(Context context, int layout, List<ListRow> data) {
super(context, layout, data);
mContext = context;
}
public class ViewHolder {
ImageView imageView;
TextView txtTitle;
CheckBox checked;
RelativeLayout root;
}
public View getView(int position, View convertView, ViewGroup parent) {
// ViewHolder holder = null;
ListRow rowItem = getItem(position);
LayoutInflater mInflater = (LayoutInflater) mContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.dialog_row, null);
holder = new ViewHolder();
holder.txtTitle = (TextView) convertView.findViewById(R.id.title);
holder.imageView = (ImageView) convertView.findViewById(R.id.icon);
holder.checked = (CheckBox) convertView.findViewById(R.id.app_checked);
holder.root = (RelativeLayout) convertView.findViewById(R.id.row_root);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.txtTitle.setText(rowItem.getTitle());
holder.imageView.setImageDrawable(rowItem.getImage());
holder.checked.setChecked(rowItem.isSelected());
return convertView;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment