public class ListViewImgAdapter extends BaseAdapter {
public static final String TAG = "ListViewImgAdapter";
private final int plastic_randomNum = 218947932;
private final int plastic_iconNum = 98367590;
int mGalleryItemBackground;
private Context mContext;
public int pageCount = Broker.model.issueFilter.issueShowingList().size();
public String[] mImageIds;
public ListViewImgAdapter(Context c) {
mContext = c;
}
public void updateListSize() {
pageCount = Broker.model.issueFilter.issueShowingList().size();
Log.d(TAG, "RefreshAll, have cells: " + pageCount);
}
public int getCount() {
return Broker.model.issueFilter.issueShowingList().size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
RelativeLayout container ;
// Log.d(TAG,"GetView. ConvertView "+position+" of "+ Broker.model.issueFilter.issueShowingList().size());
if (Broker.model.issueFilter.issueShowingList().size()<= position ) return null;
if (convertView == null) {
// Log.d(TAG,"GetView. ConvertView is null");
container = new RelativeLayout(mContext);
IRIssue theIssue = Broker.model.issueFilter.issueShowingList().get(position);
final int clickedPosition = position;
.............
Broker.model.issueFilter.issueShowingList()。get(position);
我有一个isssueShowingList是一个ArrayList,问题是如何忽略适配器中此列表中的第一个元素?我尝试返回null但它有一些错误,所以有更好的方法吗?感谢
答案 0 :(得分:4)
像往常一样返回第一个元素,但也将可见性设置为GONE或在LayoutParams中将高度设置为0。
if(position==0)
convertView.setVisibility(View.GONE);
else
convertView.setVisibility(View.VISIBLE);
或
RelativeLayout.LayoutParams lp=null;
if(position==0)
lp=new RelativeLayout.LayoutParams(-1,0);
else
lp=new RelativeLayout.LayoutParams(-1,-1);
convertView.setLayoutParams(lp);
答案 1 :(得分:1)
我认为有更好的选择......
添加字段
private List<YOUR_TYPE> mDatas;
// OR
private ArrayList<YOUR_TYPE> mDatas;
然后,在你的构造函数
中public ListViewImgAdapter(Context c) {
mContext = c;
mDatas = Broker.model.issueFilter.issueShowingList();
if (mDatas > 0)
mDatas.remove(0);
}