private String[] listValues = new String[]{"Brasil", "Argentina", "Bolívia", "Chile", "Colômbia", "Equador", "Ilhas Malvinas", "Guiana Francesa", "Guiana", "Paraguai", "Peru", "Suriname", "Uruguai", "Venezuela"}; @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); ArrayAdapter adapter = new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, listValues); setListAdapter(adapter); }
static class ViewHolder { public TextView titleTextView; public TextView descTextView; }
@Override public View getView(int position, View convertView, ViewGroup viewGroup) { View listItemView = convertView; if(convertView == null) { LayoutInflater inflater = context.getLayoutInflater(); listItemView = inflater.inflate(R.layout.list_item_title_desc, null); ViewHolder viewHolder = new ViewHolder(); viewHolder.titleTextView = (TextView) listItemView.findViewById( R.id.listItemTitle); viewHolder.descTextView = (TextView) listItemView.findViewById( R.id.listItemDescription); listItemView.setTag(viewHolder); } ViewHolder holder = (ViewHolder) listItemView.getTag(); Map titleDesc = (Map) getItem(position); holder.titleTextView.setText(titleDesc.get("title")); holder.descTextView.setText(titleDesc.get("description")); return listItemView; }
@Override public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (totalItemCount < currentTotalItems) { currentPage = firstItemPageIndex; currentTotalItems = totalItemCount; if (totalItemCount == 0) { loading = true; } } if (loading && (totalItemCount > currentTotalItems)) { loading = false; currentTotalItems = totalItemCount; currentPage++; } if (!loading && (totalItemCount - visibleItemCount) <= (firstVisibleItem + visibleThreshold)) { loadMoreListener.onLoadMore(currentPage + 1, totalItemCount); loading = true; } }
public interface OnLoadMoreListener { public void onLoadMore(int page, int totalItemsCount); }
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); final int cacheSize = maxMemory / 8; mMemoryCache = new LruCache(cacheSize) { @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1) @Override protected int sizeOf(String key, Bitmap bitmap) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB_MR1) { return bitmap.getByteCount() / 1024; } else { return bitmap.getRowBytes() * bitmap.getHeight() / 1024; } } };
@Override public View getView(int position, View convertView, ViewGroup container) { if (convertView == null) { convertView = LayoutInflater.from(context) .inflate(R.layout.list_item_img_title_desc, container, false); } Map item = (Map) getItem(position); ((TextView) convertView.findViewById(R.id.listItemTitle)) .setText(item.get("title")); ((TextView) convertView.findViewById(R.id.listItemDescription)) .setText(item.get("description")); final ImageView thumbnail = (ImageView) convertView .findViewById(R.id.listItemImage); loadBitmap(item.get("flag"), thumbnail); return convertView; }