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

  • Home
  • SEARCH
  • 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 8290615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:51:41+00:00 2026-06-08T12:51:41+00:00

I have a gridview in my layout. I have added three imageviews to this

  • 0

I have a gridview in my layout. I have added three imageviews to this gridview.

I have the following requirement. By default when I launch or resume the activity, I need to have an imageview selected by default. How can I accomplish that? Placing gridView.setSelection(1); in onResume() have no effect ie; the imageview does not get selected on launching or resume, I wonder why! Can someone please let me know why this does not get highlighted?

Following is my main activity and adapter class.

public class MyActivity extends Activity
{
GridView gridView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    gridView = (GridView) findViewById(R.id.grid_view);
    // Instance of ImageAdapter Class
    gridView.setAdapter(new ImageAdapter(this));
    // set up the onClick listener
    gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View v,
                                int position, long id) {
            Log.d("Pos", "setOnItemClickListener() - pos:" + position);
            handleItemClick(position);
        }
    });

}
public void onResume() {
    super.onResume();
    gridView.setSelection(1);
}
private void handleItemClick(int position) {

        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);

        switch(position) {
            case 0:  // Phone
                intent.setClassName("com.android.contacts",
                        "com.android.contacts.DialtactsActivity");
                break;
            case 1:  // People
                intent.setClassName("com.android.contacts",
                        "com.android.contacts.activities.PeopleActivity");
                intent.setAction("com.android.contacts.action.LIST_CONTACTS");
                break;
            case 2:  // Places
                intent.setClassName("com.android.contacts",
                        "com.android.contacts.DialtactsActivity");
                break;
            default:
                break;
        }
        startActivity(intent);
}
}

Adapter class

public class ImageAdapter extends BaseAdapter {
private Context mContext;

// Keep all Images in an array   
public Integer[] mThumbIds = {
    R.drawable.call, 
    R.drawable.contacts,
    R.drawable.music,
};

public ImageAdapter(Context c){
    mContext = c;
}

@Override
public int getCount() {
    return mThumbIds.length;
}

@Override
public Object getItem(int position) {
    return mThumbIds[position];
}

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

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ImageView imageView; 

    if (convertView == null) {           
        imageView = new ImageView(mContext);  
        imageView.setLayoutParams(new GridView.LayoutParams(350, 350));  
    } else {  
        imageView = (ImageView) convertView;   
    }

    imageView.setImageResource(mThumbIds[position]);
    imageView.setId(position);

    return imageView;
}

}
  • 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-06-08T12:51:42+00:00Added an answer on June 8, 2026 at 12:51 pm

    You can try this:

    public void onResume() {
        super.onResume();
        Thread.sleep(1);
        gridview.requestFocusFromTouch();
        gridview.setSelection(1); 
    }
    

    or also this can help:

    public void onResume() {

    super.onResume();
    mGridView.setSelection(1);
    mGridView.requestFocusFromTouch();
    mGridView.setSelection(1);
    

    }

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

Sidebar

Related Questions

I have GridView bound to some List. In layout I created following template field:
I want to make Activity like this using GridView. And this Activity have only
What I've Done I have created a GridView in my layout. This GridView I'd
In my Activity i have: DrawView which is a Custom Relative Layout. This RelativeLayout
I have GridView on my page: <%@ Page Language=C# AutoEventWireup=true CodeFile=Default.aspx.cs Inherits=_Default %> <!DOCTYPE
I have a GridView like this( main.xml ): <?xml version=1.0 encoding=utf-8?> <GridView xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/gridView1
I have a gridview and sqldatasource. In tabledefinition the default format for date is
I have created one gridview and use custom adapter for that. I added two
I have the following LinearLayout with a GridView in it: <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=match_parent android:layout_height=match_parent
I have created one gridview and use custom adapter for that. I added two

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.