1

I cannot get my listview to scroll in emulator mode in Android. I try using the mouse wheel and the pagedown key but nothing works. Here is my layout below. The device target uses the Google APIs. The listview is dynamically populated from server data. Any help is appreciated.

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
 >

<TextView
    android:text="Address is: "
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/address_view" />

<com.google.android.maps.MapView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapvw"
    android:layout_width="match_parent" 
    android:layout_height="250dp" 
    android:enabled="true"
    android:clickable="true"
    android:apiKey="0ZdvSz7dxNHNfiaO_ZqnKdW_ZiZbv35vqogG8sQ"
    />
<ListView 
    android:id="@+id/restaurant_list"
    android:layout_width="match_parent"
    android:layout_height="200sp"
    android:textColor="#FFFFFF"
    android:scrollbars="vertical"
    android:drawSelectorOnTop="false" />
 </LinearLayout>

Below is the beginning of my java program. I don't know where you are supposed to put the notification bar?

  public class MainActivity extends MapActivity {

private MapView mapView;
private MapController mapController;
private GeoPoint point;
String latLongString = "";
TextView myLocationText;
String [] restaurants = new String[50];
float lat;
float lng;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mapView = (MapView) findViewById(R.id.mapvw);
    mapView.setBuiltInZoomControls(true);
    mapView.setSatellite (false);
    mapView.setTraffic(true);
    mapController = mapView.getController();
    LocationManager locationManager;
    String svcName = Context.LOCATION_SERVICE;
    locationManager = (LocationManager)getSystemService(svcName);
//  myLocationText = (TextView)findViewById(R.id.myLocationText);

    String provider = LocationManager.GPS_PROVIDER;

    locationManager.requestLocationUpdates(provider, 3600, 1000, new LocationListener() {

        public void onProviderDisabled(String provider) {}
        public void onProviderEnabled(String provider) {}
        public void onStatusChanged(String provider, int status, Bundle extras) {}

        @SuppressWarnings("unchecked")
        public void onLocationChanged(Location loc) {
            if(loc != null) {
                lat = (float) (loc.getLatitude());
                lng = (float) (loc.getLongitude());

                String thislat = (String.valueOf(lat));
                String thislng = (String.valueOf(lng));

            //  String latLongString = "Lat:" + lat + "\nLong:" + lng;
            //  myLocationText.setText("Your current position is:\n" + latLongString);
                int latit = (int) (loc.getLatitude() * 1E6);
                int longit = (int) (loc.getLongitude() * 1E6);
                point = new GeoPoint(latit, longit);
                mapController.animateTo(point);
                mapController.setCenter(point);
                mapController.setZoom(12);
                String addr=getAddress(point);

                TextView addressView = (TextView) findViewById(R.id.address_view);

                new GetRestaurant().execute();


            }

        }
    });

}
class GetRestaurant extends AsyncTask<Void, Void, ArrayList<String>> {

 @Override
    protected ArrayList<String> doInBackground(Void...parameters ) {

        // TODO Auto-generated method stub
Dave
  • 873
  • 2
  • 15
  • 27
  • 1
    1. That looks like the old Maps API. 2. The old one need to be backed by MapActivity. So you need to handle the ListView yourself since you can't use ListActivity. Are you? – Morrison Chang Mar 10 '13 at 05:40

1 Answers1

0

use separate ListActivity because List View not quit work well with MapActivity or you can use Fragment as well.. or use FrameLayout..

  • I change the activity from MapActivity to ListActivity and got errors in my R.java file. Is there a way to incorporate a ListView that scrolls with a Map? I will have perhaps 20 or more items to list and they will not all fit on the display without scrolling. – Dave Mar 10 '13 at 16:17
  • add it on notification bar.. and one more thing you want to work on map than have to use mapActivity.. add the list in notification bar on the top of the mapactivity it will work fine.. :) @Dave – RAJAT TRIVEDI Mar 10 '13 at 17:55
  • Can you tell me how to add it to the notification bar? I added my java code up above. – Dave Mar 10 '13 at 21:17
  • http://stackoverflow.com/questions/8312344/how-to-add-a-dropdown-item-on-the-action-bar go to the first answer.. http://developer.android.com/guide/topics/resources/menu-resource.html @Dave – RAJAT TRIVEDI Mar 11 '13 at 09:16