How to find the position of the Focused Iteam? .

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

How to find the position of the Focused Iteam? .

Postby libin » Thu Jan 01, 2009 7:32 am

Can anyone please help me to find the Postion of the focused Item.
My requirement is to change the Images on FocusOut and FocusIn.

Please find the code:
------------------------

OnFocusChangeListener imageViewFocusListener = new OnFocusChangeListener() {
public void onFocusChange(View v,boolean hasFocus) {
// Need to find the position of the focused Item
if(hasFocus) {
// change the Image of the focused Item.
((ImageView)v).setImageResource(mfocusInIds[imagePosition]);
}
else {

}
}
};


I am trying to find the position of the current Focused Item. AS of I know only onItemSelected(AdapterView, View, int, long) gives the position. This will not help me since on focusOut I have to change the image.

Please reply If anyone have any idea on this.
libin
Freshman
Freshman
 
Posts: 4
Joined: Thu Jan 01, 2009 7:19 am

Top

How to find the position of the Focused Iteam?

Postby libin » Thu Jan 01, 2009 9:02 am

I have found the solution

Please find the code below.

OnFocusChangeListener imageViewFocusListener = new OnFocusChangeListener() {
public void onFocusChange(View v,boolean hasFocus) {
int imagePosition = ((ImageView )v).getId();
if(hasFocus) {
((ImageView)v).setImageResource(mfocusInIds[imagePosition]);
}
else{
((ImageView)v).setImageResource(mThumbIds[imagePosition]);
}
}
};


Use imageView.setId((int)position); to set the postion on getView() method.
libin
Freshman
Freshman
 
Posts: 4
Joined: Thu Jan 01, 2009 7:19 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 5 guests