5
私はlistView(垂直)を持ち、すべてのリストアイテムは水平リストビュー(水平)を持っています。だから、リストビューのパフォーマンスを最適化するAndroid
ので、巨大なパフォーマンスのヒットがある
が、私は垂直リストもgetViewメソッド()を呼び出している行の水平scrollviewをスクロールするときに問題がある... .. 、することができます任意の1は私にそれへのよりよい解決策を教えて..私は私のこのコード
public View getView(final int position, View convertView, ViewGroup parent)
{
View v = convertView;
ViewHolder holder;
if (v == null)
{
v = inflater.inflate(R.layout.custom_image_layout, null);
holder = new ViewHolder();
holder.txtFileName = (TextView) v.findViewById(R.id.txtFileName);
holder.imageView = (ImageView) v.findViewById(R.id.imgView);
v.setTag(holder);
} else
{
holder = (ViewHolder) v.getTag();
}
holder.imageView.setImageBitmap(bm);
holder.txtFileName.setText(""+nameoffile);
return v;
}
static class ViewHolder
{
public ImageView imageView;
public TextView txtFileName;
}
使用ザ・ホルを試してみることをお勧め
public class GridViewAdapter extends BaseAdapter {
List<List<Hotel>> gridDatasource;
Context mContext;
public GridViewAdapter(List<List<Hotel>> gridDatasource, Context context) {
this.gridDatasource = gridDatasource;
this.mContext = context;
}
public void setGridDatasource(List<List<Hotel>> gridDatasource) {
this.gridDatasource = gridDatasource;
}
@Override
public int getCount() {
if (gridDatasource == null) {
return 0;
}
return gridDatasource.size();
}
@Override
public Object getItem(int position) {
return gridDatasource.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
GridViewHolder holder;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.gridview_table_cell,
null);
holder = new GridViewHolder();
holder.headerView = (TextView) convertView
.findViewById(R.id.gridViewRowHeader);
holder.listView = (HorizontalListView) convertView
.findViewById(R.id.gridViewHorizontalListView);
convertView.setTag(holder);
} else {
holder = (GridViewHolder) convertView.getTag();
Log.d("TAG", "Reaching Here");
}
holder.headerView.setText("Hello From Sandeep");
HorizontalListViewAdapter adapter = new HorizontalListViewAdapter(
mContext, gridDatasource.get(position));
holder.listView.setAdapter(adapter);
return convertView;
}
}
static class GridViewHolder {
TextView headerView;
HorizontalListView listView;
}
public class HorizontalListViewAdapter extends BaseAdapter {
Context mContext;
List<Hotel> mHotels;
public HorizontalListViewAdapter(Context context, List<Hotel> hotels) {
this.mContext = context;
this.mHotels = hotels;
}
@Override
public int getCount() {
if (mHotels == null) {
return 0;
}
return mHotels.size();
}
@Override
public Object getItem(int position) {
return mHotels.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
HotelCell cell = (HotelCell) convertView;
if (cell == null) {
cell = new HotelCell(mContext);
} else {
Log.d("TAG", "Reached here 2");
}
cell.setHotel(mHotels.get(position));
cell.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(mContext,
HotelDetailActivity.class);
intent.putExtra("DATA", ((HotelCell) v).getHotel());
startActivity(intent);
}
});
cell.setPadding(0, 0, 10, 0);
return cell;
}
}
私はビューホルダーを使用しています。 –