开发者

How to get focus to GridView First Image Android?

HI,

Iam writing GridView by using BaseAdapter with 2 columns.Each column with One Image and Text.It works smoothly.I had given focus by using below code in onConfig...

public void onConfigurationChanged(Config开发者_运维技巧uration newConfig) {
    gridview.requestFocusFromTouch();
    gridview.setSelection(0);
}

It works when my view configuration changes.But Same doesn't work in onCreate() method. I used below all methods in onCreate() but my view doesn;t get focus.How to give focus for the first image when running my application.I want focus on first image when view inflates on the device.Please give me guidance?

gridview.requestFocus();
gridview.requestFocusFromTouch();
gridview.setSelected(true);
gridview.setSelection(0);
gridview.setFocusable(true);
gridview.setFocusableInTouchMode(true);
gridview.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);

Regards, Rajendar Are


This worked for me.

    mGridView.setSelection(iPos-1);
    mGridView.requestFocusFromTouch();
    mGridView.setSelection(iPos-1);

Unknown why have to do it twice:


Maybe, you can do like this:

"sleep" little time

        Thread.sleep(1);

        gridview.requestFocusFromTouch();
        gridview.setSelection(position);    


I managed to do this by just calling mGridView.setSelected(true); in onResume() In this way my 1st element has got the selection.

Now I'm looking for ways how to set selection for random element

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜