Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4578590
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:31:35+00:00 2026-05-21T20:31:35+00:00

I have a GridView that uses an adapter to set ImageViews and when I

  • 0

I have a GridView that uses an adapter to set ImageViews and when I open up an AlertDialog and focus on its TextView, the images in the GridView shift positions. How do I stop that from happening?

import android.content.Context;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ImageAdapter extends BaseAdapter {
private Context context;
private String[] directory;

public ImageAdapter(Context c, String[] d) {
    this.context = c;
    this.directory = d;
}

public int getCount() {
    return directory.length;
}

public Object getItem(int position) {
    return directory[position];
}

public long getItemId(int position) {
    return position;
}

// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
    System.gc();
    View v;
    if (convertView == null) {  // if it's not recycled, initialize some attributes
        LayoutInflater li = LayoutInflater.from(context);
        v = li.inflate(R.layout.iblock, null);

        ImageView iv = (ImageView)v.findViewById(R.id.foodImage);
        BitmapFactory.Options bfo = new BitmapFactory.Options();
        bfo.inSampleSize = 2;
        iv.setImageBitmap(BitmapFactory.decodeFile(directory[position], bfo));

        TextView tv = (TextView)v.findViewById(R.id.foodName);
        String[] s = directory[position].split("[\\/.]+");

    } else {
        v = convertView;
    }
    return v;
}
}


protected Dialog onCreateDialog(int id) {
    switch(id) {
    case DIALOG_SEARCH_ID:
        LayoutInflater factory = LayoutInflater.from(this);
        View searchView = factory.inflate(R.layout.searchbar2, null);

        final EditText searchfield = (EditText) searchView.findViewById(R.id.searchfield);

        ImageButton ib = (ImageButton) searchView.findViewById(R.id.searchbutton);
        ib.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(getApplicationContext(), SearchResults.class);
                i.putExtra("query", searchfield.getText().toString());
                startActivity(i);
            }
        });

        AlertDialog ad = new AlertDialog.Builder(SearchResults.this)
            .setView(searchView)
            .create();
        Window win = ad.getWindow();
        win.setGravity(48);
        return ad;
    }
    return null;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T20:31:35+00:00Added an answer on May 21, 2026 at 8:31 pm

    Your View recycling is broken. When you are given a View to recycle, you still need to bind your data to it (in this case, putting the image in the ImageView). The only part you can skip when recycling a View is inflating the layout.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ASP.NET GridView that uses template columns and user controls to allow
We have an app that uses simple one way binding with a GridView to
I have a Gridview that uses a collapsible panel to show a large amount
I have a gridview that uses autogenerated columns, because the user can select the
I have an ASP.NET GridView that uses an EmptyDataTemplate. This template is used to
I have a GridView that uses LinqDataSource. The GridView has default paging enable. I
I have a GridView that is bound to a DataTable, which in turn uses
I have a GridView that I would like to bind to an ObjectDataSource. I
I have a GridView that allows editing the values in every column, in every
I have a gridview that is using a LinqDataSource for it's datasource. I've added

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.