I am currently making a part of my app to select multiple images from gallery using Gridview. The PROBLEM is that I need to put a button on the first item and the rest will be images (the 0,0 will be button and the rest well, imageview with check box) That button will be using the phone camera. I was able to make it, but in exchange, it is not scrolling smoothly, is there a way to fix this? below is my code:
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
View view;
System.out.println(position);
if (position == 0) {
holder = new ViewHolder();
view = getLayoutInflater().inflate(R.layout.year_dropdownlayout, parent, false);
holder.mButton = (Button) view.findViewById(R.id.mfreakingBtn);
ViewGroup.LayoutParams params = holder.mButton.getLayoutParams();
params.height = 250;
params.width = 250;
holder.mButton.requestLayout();
} else {
view = getLayoutInflater().inflate(R.layout.select_photos_layout, parent, false);
holder = new ViewHolder();
holder.imageView = (ImageView) view.findViewById(R.id.imageView1);
holder.mCheckBox = (CheckBox) view.findViewById(R.id.checkBox1);
holder.mCheckBox.setOnCheckedChangeListener(mCheckedChangeListener);
holder.progressBar = (ProgressBar) view.findViewById(R.id.progress);
holder.mButton = null;
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "You Clicked " + position, Toast.LENGTH_LONG).show();
}
});
imageLoader.displayImage("file://" + imageUrls.get(position), holder.imageView, options, new SimpleImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
holder.progressBar.setProgress(0);
holder.progressBar.setVisibility(View.VISIBLE);
}
@Override
public void onLoadingFailed(String imageUri, View view,
FailReason failReason) {
holder.progressBar.setVisibility(View.GONE);
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
Animation anim = AnimationUtils.loadAnimation(MultiPhotoSelect.this, R.anim.fade_in);
holder.imageView.setAnimation(anim);
anim.start();
holder.progressBar.setVisibility(View.GONE);
}
}, new ImageLoadingProgressListener() {
@Override
public void onProgressUpdate(String imageUri, View view, int current,
int total) {
holder.progressBar.setProgress(Math.round(100.0f * current / total));
}
}
);
holder.mCheckBox.setTag(position);
holder.mCheckBox.setChecked(mSparseBooleanArray.get(position));
}
return view;
}
Don't mind the names of the layouts. :) This what happens when frustration gets to ya. I have been looking for hours now. I found one who put a button on the end of the gridview this: Android - Different items in GridView not showing up
I hope someone can help me. Thanks in advance. :)
Your adapter...
private static final int ItemTypeButton = 0;
private static final int ItemTypeImage = 1;
@override
public int getViewTypeCount()
{
return 2; // 2 because you want two type of view. (One button and the rest is images)
}
@override
public int getItemViewType(int position)
{
/* it's better to use item view type
to determine what type of view
you want to display. This is used
for recycling views for optimization. */
return position == 0 ? ItemTypeButton : ItemTypeImage;
}
public View getView(final int position, View convertView, ViewGroup parent) {
int type = getItemViewType(position);
/* Check whether convertView intance is null. If null, then inflate.
Otherwise the view is recycled for optimization. */
if (convertView == null)
{
if (type == ItemTypeButton)
{
// inflate button view
}
else if (type == ItemTypeImage)
{
// inflate your view for image
}
}
// This is where you should update your view states.
if (type == ItemTypeImage)
{
/* ... */
holder.imageView = (ImageView) view.findViewById(R.id.imageView1);
holder.imageView.setImage(.....
}
else
{
/* ... */
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.