セクションビューでグリッドビューを作成しましたが、いくつか問題があります
@Override
public View getView(int position, View convertView, ViewGroup parent) {
int size = mArray.get(0).size();
int z = size + (COLUMNS_NUM * 2);
//sectionView
if (position < (COLUMNS_NUM * 2) || (position > (z -1) && position < (z + COLUMNS_NUM))) {
if(position == COLUMNS_NUM ){
return header(R.string.grid_last_added, convertView);
}
if(position == z){
return header(R.string.grid_last_added, convertView);
}
if (convertView == null) {
convertView = new View(mContext);
}
// Set empty view with height of ActionBar
convertView.setLayoutParams(new AbsListView.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, mActionBarHeight));
if(position == COLUMNS_NUM || position == z){
convertView.setLayoutParams(new AbsListView.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, mActionBarHeight - 15));
}
return convertView;
}
View v = convertView;
if(v == null){
v = LayoutInflater.from(mContext).inflate(R.layout.player_movie, null);
v.setLayoutParams(mImageViewLayoutParams);
}
TextView title = (TextView) v.findViewById(R.id.serial_title);
TextView seria = (TextView) v.findViewById(R.id.when);
ImageView poster = (ImageView) v.findViewById(R.id.poster);
//Offten.debug(getCount(), position);
int x = (position - (COLUMNS_NUM * 2) )< mArray.get(0).size() ? position - (COLUMNS_NUM * 2) : position - (z + COLUMNS_NUM);
int y = (position - (COLUMNS_NUM * 2) )< mArray.get(0).size() ? 0 : 1;
// Offten.debug(x + " " + (position < mArray.get(0).size() ? "true" : "false") + " " + mArray.get(0).size());
//Offten.debug( Boolean.toString((position - (COLUMNS_NUM * 2) )< mArray.get(0).size()) + " " + x + " " + z);
Serial serial = mArray.get(y).get(x);
title.setText(serial.getTitle());
seria.setText(serial.getSeria());
mFetcher.loadImage( serial.getPoster(), poster);
if(v.getLayoutParams().height != mItemHeight){
v.setLayoutParams(mImageViewLayoutParams);
}
return v;
}
public TextView header(int message, View convertView){
TextView view = (TextView) convertView; // issue with cast exception
if(view == null){
view = new TextView(mContext);
}
view.setText(underline(mContext.getResources().getString(message)));
view.setTextSize(18);
view.setTypeface(typeface, Typeface.BOLD_ITALIC);
view.setTextColor(Color.WHITE);
view.setGravity(Gravity.CENTER_VERTICAL);
view.setLayoutParams(new AbsListView.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, mActionBarHeight - 15));
return view;
}
このコードでは、ヘッダーの TextView で常にキャスト例外の問題が発生します。(ビューを TextView にキャストすることはできません)
@Override
public int getViewTypeCount() {
// Two types of views, the normal ImageView and the top row of empty views
return 2;
}
@Override
public int getCount() {
int size = 0;
for(List<Serial> s : mArray){
size += s.size() + COLUMNS_NUM;
}
return size > 0 ? size + COLUMNS_NUM : size;
}
@Override
public int getItemViewType(int position) {
int size = mArray.get(0).size();
int z = size + (COLUMNS_NUM * 2);
return position < (COLUMNS_NUM * 2) || (position > (z -1) && position < (z + COLUMNS_NUM)) ? 1 : 0;
}
私の問題を解決できますか??