When does onFocusChanged() get called

by ying lcs » Wed, 04 Mar 2009 06:57:38 GMT


Sponsored Links
 Hi,

I have over-loaded the onFocusChanged() in my classes which inherits
from LinearLayout.

protected void onFocusChanged(boolean gainFocus, int direction,
                        Rect previouslyFocusedRect)  {
   super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
}

My question is when does onFocusChanged() get called? In this
over-loaded implementation, I set a breakpoint, but it never breaks
there. I have repeated pressing UP/DOWN key, but it never breaks at
that line

Thank you for any pointers.

--~--~---------~--~----~------------~-------~--~----~



When does onFocusChanged() get called

by Romain Guy » Wed, 04 Mar 2009 06:58:49 GMT


 LinearLayout is not focusable so it cannot get onFocusChanged().






-- 
Romain Guy
Android framework engineer
romain...@android.com

Note: please don't send private questions to me, as I don't have time
to provide private support.  All such questions should be posted on
public forums, where I and others can see and answer them

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


When does onFocusChanged() get called

by ying lcs » Wed, 04 Mar 2009 07:04:15 GMT


 Romain,

Thank you. But if I call setFocusable(true) in my class which
inherited from LinearLayout, will android call onFocusChanged() of my
class?

Thank you again.






--~--~---------~--~----~------------~-------~--~----~



When does onFocusChanged() get called

by Romain Guy » Wed, 04 Mar 2009 07:06:21 GMT


 Yes.








-- 
Romain Guy
Android framework engineer
romain...@android.com

Note: please don't send private questions to me, as I don't have time
to provide private support.  All such questions should be posted on
public forums, where I and others can see and answer them

--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. To Arvind

Hi Arvind this is an example for u...

ItemizedOverlay Example:
---------------------------------------




package samp.sam11;

//import mapv.mapapi.R;

import java.io.IOException;
import java.util.List;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

//import de.michaelhuebl.android.R;
//import de.michaelhuebl.android.simpleGoogleMaps;
import android.view.View;
import android.view.View.OnClickListener;

import android.app.AlertDialog;
import android.app.Dialog;
import android.graphics.drawable.Drawable;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;

public class sam1 extends MapActivity {


        protected boolean isRouteDisplayed() {
                // TODO Auto-generated method stub
                return false;
        }
    /** Called when the activity is first created. */


    MapView mapView;
    EditText edt;
    Button bttn;
    Geocoder gc;
    double lat;
    double lon;
    List<Overlay> mapOverlays;
    Drawable drawable;
    HelloItemizedOverlay itemizedOverlay;



    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mapView = (MapView) findViewById(R.id.mapview);
        edt=(EditText)findViewById(R.id.edt);
        bttn=(Button)findViewById(R.id.bttn);


        gc=new Geocoder(this);
        bttn.setOnClickListener(new OnClickListener(){


                public void onClick(View v)
                {
                        String str=edt.getText().toString();



                        try {
                                        List<Address> 
loc=gc.getFromLocationName(str,7);

                                        if(loc.size()!=0)
                                        {
                                        for(int i=0;i<loc.size();++i){

                                        Address x=loc.get(i);
                                        lat=x.getLatitude();
                                        lon=x.getLongitude();
                                        }
                                        
gotolocation((lat*1000000),(lon*1000000),mapView);
                                        }
                                        else
                                {
                                        Dialog locationError = new 
AlertDialog.Builder(
                                                                
sam1.this).setIcon(0).setTitle(
                                                                
"Error").setPositiveButton(R.string.ok, null)
                                                                .setMessage(
                                                                                
"Sorry, your address doesn't exist.")
                                                                .create();
                                                locationError.show();
                                }

                                } catch (IOException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                }



                }

        });


    }

    public void gotolocation(double latitude,double longitude,MapView
mymap)
    {
        GeoPoint p=new GeoPoint((int) latitude,(int) longitude);
        mapOverlays = mapView.getOverlays();
        drawable = this.getResources().getDrawable
(R.drawable.androidmarker);
        itemizedOverlay = new HelloItemizedOverlay(drawable);
        mapView.displayZoomControls(true);
        OverlayItem overlayitem = new OverlayItem(p, "", "");
        itemizedOverlay.addOverlay(overlayitem);
        mapOverlays.add(itemizedOverlay);

        MapController mc=mapView.getController();
        mc.animateTo(p);
        int zoomlevel=mapView.getMaxZoomLevel();
        mc.setZoom(zoomlevel - 1);
        mapView.setSatellite(false);


    }




}




HelloItemizedOverlay Class file:
-------------------------------------------------




package samp.sam11;

import java.util.ArrayList;

import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class HelloItemizedOverlay extends ItemizedOverlay {

        private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>
();


        public HelloItemizedOverlay(Drawable defaultMarker) {
                super(boundCenterBottom(defaultMarker));



                // TODO Auto-generated constructor stub
        }
        public void addOverlay(OverlayItem overlay) {
            mOverlays.add(overlay);
            populate();
        }

        @Override
        protected OverlayItem createItem(int i) {
                // TODO Auto-generated method stub
                return mOverlays.get(i);

        }

        @Override
        public int size() {
                // TODO Auto-generated method stub
                return mOverlays.size();
        }

}




--~--~---------~--~----~------------~-------~--~----~

2. Getting the Share menu to work correctly / Registering Intents correctly

We want to make our application integrate correctly with the "Share"
features on applications like Gallery and the Browser.

Following the advice the appears elsewhere on this list we've added
the entry in our manifest:

<intent-filter android:icon="@drawable/icon" android:label="@string/
app_name">
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.CHOOSER"/>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.ALTERNATIVE" />
<category android:name="android.intent.category.SELECTED_ALTERNATIVE"/
<category android:name="android.intent.category.DEFAULT"/>
<data mimeType="image/*"/>
<data mimeType="text/plain"/>
</intent-filter>

The problem is, instead of having our application listed next to GMail
and other standard Apps under the heading "Share picture via". A new
dialog box appears which lists our application under the heading
"Complete action using" along with "Android System" Clicking on our
application name works fine. Clicking on "Android System" presents the
standard list of intents.

I've downloaded other non-standard apps and they also appear correctly
in the "Share picture via" list.

Is there a trick to getting the application to appear under the
standard menu?

--~--~---------~--~----~------------~-------~--~----~

3. Changing a color in a Drawable

4. failed to locate packages - Eclipse IDE

5. Communication between Android devices over 3G

6. i wish to join this group to get help for android x86 porting

7. How to manage service lifecycle when device kills it due to low memory