标签:
public class NewsListAdapter extends BaseAdapter { private Context mContext; private LinkedList<NewsModel> newsList; public NewsListAdapter(Context mContext, LinkedList<NewsModel> newsList) { this.mContext = mContext; this.newsList = newsList == null ? new LinkedList<NewsModel>() : new LinkedList<>(newsList); } @Override public int getCount() { return newsList != null ? newsList.size() : 0; } @Override public Object getItem(int position) { return position >= newsList.size() ? null : newsList.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = LayoutInflater.from(mContext).inflate(R.layout.newslist_item, parent, false); } TextView newsTitleView = (TextView) convertView.findViewById(R.id.titleView); TextView newsAuthorView = (TextView) convertView.findViewById(R.id.authorView); TextView newsDateView = (TextView) convertView.findViewById(R.id.dateView); final NewsModel mNewsModel = newsList.get(position); newsTitleView.setText(mNewsModel.getTitle()); newsAuthorView.setText("发布人:" + mNewsModel.getAuthor()); newsDateView.setText("发布日期:" + new SimpleDateFormat("yyyy.MM.dd HH:mm:ss").format(mNewsModel.getDate())); return convertView; } public void updateData(LinkedList<NewsModel> dataList) { this.newsList = dataList; this.notifyDataSetChanged(); } }
package android.widget; import android.database.DataSetObserver; import android.view.View; import android.view.ViewGroup; import android.widget.ListAdapter; import android.widget.SpinnerAdapter; public abstract class BaseAdapter implements ListAdapter, SpinnerAdapter { public BaseAdapter() { throw new RuntimeException("Stub!"); } public boolean hasStableIds() { throw new RuntimeException("Stub!"); } public void registerDataSetObserver(DataSetObserver observer) { throw new RuntimeException("Stub!"); } public void unregisterDataSetObserver(DataSetObserver observer) { throw new RuntimeException("Stub!"); } public void notifyDataSetChanged() { throw new RuntimeException("Stub!"); } public void notifyDataSetInvalidated() { throw new RuntimeException("Stub!"); } public boolean areAllItemsEnabled() { throw new RuntimeException("Stub!"); } public boolean isEnabled(int position) { throw new RuntimeException("Stub!"); } public View getDropDownView(int position, View convertView, ViewGroup parent) { throw new RuntimeException("Stub!"); } public int getItemViewType(int position) { throw new RuntimeException("Stub!"); } public int getViewTypeCount() { throw new RuntimeException("Stub!"); } public boolean isEmpty() { throw new RuntimeException("Stub!"); } }
package android.widget; import android.widget.Adapter; public interface ListAdapter extends Adapter { boolean areAllItemsEnabled(); boolean isEnabled(int var1); }
package android.widget; import android.database.DataSetObserver; import android.view.View; import android.view.ViewGroup; public interface Adapter { int IGNORE_ITEM_VIEW_TYPE = -1; int NO_SELECTION = -2147483648; void registerDataSetObserver(DataSetObserver var1); void unregisterDataSetObserver(DataSetObserver var1); int getCount(); Object getItem(int var1); long getItemId(int var1); boolean hasStableIds(); View getView(int var1, View var2, ViewGroup var3); int getItemViewType(int var1); int getViewTypeCount(); boolean isEmpty(); }
package android.widget; import android.view.View; import android.view.ViewGroup; import android.widget.Adapter; public interface SpinnerAdapter extends Adapter { View getDropDownView(int var1, View var2, ViewGroup var3); }
标签:
原文地址:http://www.cnblogs.com/xbx2015/p/4554238.html