How to avoid duplication of adapter code I create applications where there are 2 listLiew. Here is the code of the 1st adapter. The 2nd adapter is exactly the same, but you need to add several View elements. How to make one adapter fit both.
public class AdsAdapter extends BaseAdapter {
private List<Ads> list; private LayoutInflater layoutInflater; public AdsAdapter(Context context, List<Ads> list) { this.list = list; layoutInflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); } @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 position; } @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub **View view = convertView; if (view == null) { view = layoutInflater.inflate(R.layout.list_item_layout, parent, false); } TextView textViewAds = (TextView) view.findViewById(R.id.textViewAds); textViewAds.setText(getAds(position).getAddsText().toString()); ImageView imageViewPc = (ImageView) view.findViewById(R.id.imagePic); Bitmap b1 = BitmapFactory.decodeByteArray(getAds(position).getPhoto(), 0, getAds(position).getPhoto().length); imageViewPc.setImageBitmap(b1);** return view; } private Ads getAds(int position) { return (Ads) getItem(position); } }