Monday, March 1, 2010

[android-developers] Re: Problems when using GridView in Gallery

Below is my code fragment

CustomGallery is a class extending class Gallery to modify the fling
event..


//////////////// onCreate()/////////////////////////////
setContentView(R.layout.grid_gallery);
gal = (CustomGallery) findViewById(R.id.appsgallery);
gal.setAdapter(new GalleryAdapter(this));


///////////////////getView() in GalleryAdapter class////////


public View getView(int position, View convertView, ViewGroup
parent) {

final LayoutInflater inflater =
LayoutInflater.from(mContext);
CustomGrid mAppGrid = (CustomGrid)
inflater.inflate(R.layout.grid_1, parent, false);

mAppGrid.setAdapter(new AppsAdapter(position));
mAppGrid.setBackgroundResource(mGalleryItemBackground);
return mAppGrid;
}

/////getView() in class AppsAdapter/////////////
public View getView(int position, View convertView, ViewGroup
parent) {

AppHolder holder;

if(convertView == null)
{
LayoutInflater inflater =
LayoutInflater.from(AppGridGallery.this);
convertView =
inflater.inflate(R.layout.app_description, parent, false);

holder = new AppHolder();

holder.appThumbnail = (ImageView)
convertView.findViewById(R.id.AppImage);

holder.appThumbnail.setScaleType(ImageView.ScaleType.FIT_CENTER);
holder.appName = (TextView)
convertView.findViewById(R.id.AppName);
holder.appName.setSingleLine(true);
convertView.setTag(holder);
}
else
{
holder = (AppHolder) convertView.getTag();
}

final ResolveInfo info = mApps.get(GRID_PER_PAGE *
startIndex + position);

holder.appThumbnail.setImageDrawable(info.activityInfo.loadIcon(getPackageManager()));

holder.appName.setText(info.loadLabel(getPackageManager()) );

return convertView;
}

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate