If you think the Android project Book-MetaSearch listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package net.grosinger.bookmetasearch;
//fromwww.java2s.comimport android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import net.grosinger.bookmetasearch.inventory.InventoryHeader;
import net.grosinger.bookmetasearch.inventory.InventoryListItem;
import java.util.ArrayList;
import java.util.List;
/**
* Created by tony on 11/3/13.
*/publicclass BookInventoryAdapter extends BaseAdapter {
List<InventoryListItem> items;
private LayoutInflater mInflater;
public BookInventoryAdapter(Context context, List<InventoryListItem> ebooks, List<InventoryListItem> audiobooks) {
Log.d(getClass().getSimpleName(), "Creating new adapter...");
addAll(ebooks, audiobooks);
mInflater = LayoutInflater.from(context);
}
@Override
publicint getCount() {
return items.size();
}
@Override
public Object getItem(int i) {
// TODO: Find a way to load these lazily so we don't have to get every image right from the start
return items.get(i);
}
@Override
publiclong getItemId(int position) {
return position;
}
publicvoid clear() {
items.clear();
items.add(new InventoryHeader("No Availability"));
}
publicvoid addAll(List<InventoryListItem> ebooks, List<InventoryListItem> audiobooks) {
items = new ArrayList<InventoryListItem>();
if (ebooks != null && !ebooks.isEmpty()) {
items.add(new InventoryHeader("Available Ebooks"));
items.addAll(ebooks);
}
if (audiobooks != null && !audiobooks.isEmpty()) {
items.add(new InventoryHeader("Available Audiobooks"));
items.addAll(audiobooks);
}
if (items.isEmpty()) {
items.add(new InventoryHeader("No Availability"));
}
Log.d(getClass().getSimpleName(), "Updating adapter results to size " + items.size());
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Log.d(getClass().getSimpleName(), "Building view from results");
InventoryListItem item = items.get(position);
View view = item.fillView(convertView, mInflater);
return view;
}
}