Autore Topic: Metodo OnTap di una classe Overlay che prenda informazioni da un provider  (Letto 920 volte)

Offline tanuccio85

  • Nuovo arrivato
  • *
  • Post: 34
  • Respect: 0
    • Mostra profilo
Salve ragazzi ho creato un provider con delle informazioni sui parcheggi.
Questi parkeggi vengono marcati su una mappa con una classe overlay ora vorrei sovrascrivere il metodo onTap di tale classe facendo si che cliccando sopra il marcatore compaiono a video tramite un AlertDialog tutte le informazioni del parcheggio cliccato.
Però il metodo getContentResolver().query(PARK_TEAM_URI, null, selection, selectionArgs, null); su una classe che estende una classe ItemizedOverlay non è riconosciuto
Ho pravato a creare una Activity nel metodo onTap ma crasha. Potete Aiutarmi??? Guardando un pò il codice...

classe Overlay
Codice (Java): [Seleziona]
package com.prova;

import java.util.LinkedList;
import java.util.List;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.net.Uri;

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

public class ParcheggiSalernoOverlay extends ItemizedOverlay<OverlayItem>{

        private List<OverlayItem> parcheggi = new LinkedList<OverlayItem>();
       
        private Drawable defaultMarker;
        private Context mContext;
        private final static Uri PARK_TEAM_URI = Uri.parse("content://com.simpleprovider.SimpleProvider/park");

       
        public ParcheggiSalernoOverlay(Drawable defaultMarker,Context context) {
                super(defaultMarker);
                this.defaultMarker=defaultMarker;
                mContext = context;
               
        }
        public void draw(Canvas canvas, MapView mapView, boolean shadow) {
                super.draw(canvas, mapView, shadow);
                boundCenterBottom(defaultMarker);              
        }

        @Override
        protected OverlayItem createItem(int i) {
                // TODO Auto-generated method stub
                return parcheggi.get(i);
        }
       
        protected void addOverlay(int lat,int lng,String name,String key){
                parcheggi.add(new OverlayItem(new GeoPoint(lat,lng),name,key));
                populate();
        }
       

        @Override
        public int size() {
                // TODO Auto-generated method stub
                return parcheggi.size();
        }
       
        protected boolean onTap(int i) {
                OverlayItem item = parcheggi.get(i);
                ProvaActivity obj=new ProvaActivity();
                String selection = com.prova.Park.ParkMetaData.NAME+ "= ?";
                String[] selectionArgs = { item.getTitle() };
                Cursor c=obj.getContentResolver().query(PARK_TEAM_URI, null, selection, selectionArgs, null);//crash
                String costoH="";
         
                while(c.moveToNext()){
                //n= c.getInt(2);
                //ind=c.getString(3);
                costoH=c.getString(1);
                }
          //}
          AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
          dialog.setTitle("Parcheggi Salerno");
          //dialog.setMessage("name");
          //dialog.setMessage(item.getTitle()+"\n"+"N_Posti: "+Integer.toString(n)+"\n"+"Indirizzo: "+ind+"\n"+"Costo: "+Double.toString(costoH)+"€");
          dialog.setMessage(item.getTitle()+"Costo: "+costoH+"€");
          dialog.setPositiveButton(R.string.ok, null);
          dialog.show();
          return (true);
          }

}

Codice (Java): [Seleziona]
LOG CAT

04-15 15:38:55.264: ERROR/vold(26): Error opening switch name path '/sys/class/switch/test' (No such file or directory)
04-15 15:38:55.264: ERROR/vold(26): Error bootstrapping switch '/sys/class/switch/test' (No such file or directory)
04-15 15:38:55.264: ERROR/vold(26): Error opening switch name path '/sys/class/switch/test2' (No such file or directory)
04-15 15:38:55.264: ERROR/vold(26): Error bootstrapping switch '/sys/class/switch/test2' (No such file or directory)
04-15 15:39:10.205: ERROR/BatteryService(65): usbOnlinePath not found
04-15 15:39:10.205: ERROR/BatteryService(65): batteryVoltagePath not found
04-15 15:39:10.205: ERROR/BatteryService(65): batteryTemperaturePath not found
04-15 15:39:10.225: ERROR/SurfaceFlinger(65): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake
04-15 15:39:16.584: ERROR/EventHub(65): could not get driver version for /dev/input/mouse0, Not a typewriter
04-15 15:39:16.584: ERROR/EventHub(65): could not get driver version for /dev/input/mice, Not a typewriter
04-15 15:39:16.824: ERROR/System(65): Failure starting core service
04-15 15:39:16.824: ERROR/System(65): java.lang.SecurityException
04-15 15:39:16.824: ERROR/System(65):     at android.os.BinderProxy.transact(Native Method)
04-15 15:39:16.824: ERROR/System(65):     at android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146)
04-15 15:39:16.824: ERROR/System(65):     at android.os.ServiceManager.addService(ServiceManager.java:72)
04-15 15:39:16.824: ERROR/System(65):     at com.android.server.ServerThread.run(SystemServer.java:176)
04-15 15:39:16.824: ERROR/AndroidRuntime(65): Crash logging skipped, no checkin service
04-15 15:39:29.710: ERROR/ActivityThread(109): Failed to find provider info for android.server.checkin
04-15 15:39:30.870: ERROR/vold(26): Cannot start volume '
/sdcard' (volume is not bound)
04-15 15:39:31.630: ERROR/MediaPlayerService(30): Couldn'
t open fd for content://settings/system/notification_sound
04-15 15:39:31.661: ERROR/MediaPlayer(65): Unable to to create media player
04-15 15:39:32.250: ERROR/ActivityThread(109): Failed to find provider info for android.server.checkin
04-15 15:39:32.391: ERROR/ActivityThread(109): Failed to find provider info for android.server.checkin
04-15 15:39:38.351: ERROR/AndroidRuntime(132): ERROR: thread attach failed
04-15 15:39:45.950: ERROR/AndroidRuntime(193): ERROR: thread attach failed
04-15 15:39:46.981: ERROR/ActivityThread(65): Failed to find provider info for com.google.settings
04-15 15:39:46.981: ERROR/ActivityThread(65): Failed to find provider info for com.google.settings
04-15 15:39:46.981: ERROR/ActivityThread(221): Failed to find provider info for com.google.settings
04-15 15:39:46.981: ERROR/ActivityThread(221): Failed to find provider info for com.google.settings
04-15 15:39:46.981: ERROR/ActivityThread(221): Failed to find provider info for com.google.settings
04-15 15:39:49.264: ERROR/MapActivity(221): Couldn't get connection factory client
04-15 15:40:14.174: ERROR/AndroidRuntime(221): Uncaught handler: thread main exiting due to uncaught exception
04-15 15:40:14.214: ERROR/AndroidRuntime(221): java.lang.NullPointerException
04-15 15:40:14.214: ERROR/AndroidRuntime(221):     at android.content.ContextWrapper.getContentResolver(ContextWrapper.java:90)
04-15 15:40:14.214: ERROR/AndroidRuntime(221):     at com.prova.ParcheggiSalernoOverlay.onTap(ParcheggiSalernoOverlay.java:62)
04-15 15:40:14.214: ERROR/AndroidRuntime(221):     at com.google.android.maps.ItemizedOverlay.onTap(ItemizedOverlay.java:453)
04-15 15:40:14.214: ERROR/AndroidRuntime(221):     at com.google.android.maps.OverlayBundle.onTap(OverlayBundle.java:83)
04-15 15:40:14.214: ERROR/AndroidRuntime(221):     at com.google.android.maps.MapView$1.onSingleTapUp(MapView.java:346)
04-15 15:40:14.214: ERROR/AndroidRuntime(221):     at android.view.GestureDetector.onTouchEvent(GestureDetector.java:506)
04-15 15:40:14.214: ERROR/AndroidRuntime(221):     at com.google.android.maps.MapView.onTouchEvent(MapView.java:628)
04-15 15:40:14.214: ERROR/AndroidRuntime(221):     at android.view.View.dispatchTouchEvent(View.java:3709)
04-15 15:40:14.214: ERROR/AndroidRuntime(221):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:852)
04-15 15:40:14.214: ERROR/AndroidRuntime(221):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
04-15 15:40:14.214: ERROR/AndroidRuntime(221):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
04-15 15:40:14.214: ERROR/AndroidRuntime(221):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
04-15 15:40:14.214: ERROR/AndroidRuntime(221):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
04-15 15:40:14.214: ERROR/AndroidRuntime(221):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
04-15 15:40:14.214: ERROR/AndroidRuntime(221):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
04-15 15:40:14.214: ERROR/AndroidRuntime(221):     at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
04-15 15:40:14.214: ERROR/AndroidRuntime(221):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
04-15 15:40:14.214: ERROR/AndroidRuntime(221):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
04-15 15:40:14.214: ERROR/AndroidRuntime(221):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-15 15:40:14.214: ERROR/AndroidRuntime(221):     at android.os.Looper.loop(Looper.java:123)
04-15 15:40:14.214: ERROR/AndroidRuntime(221):     at android.app.ActivityThread.main(ActivityThread.java:4363)
04-15 15:40:14.214: ERROR/AndroidRuntime(221):     at java.lang.reflect.Method.invokeNative(Native Method)
04-15 15:40:14.214: ERROR/AndroidRuntime(221):     at java.lang.reflect.Method.invoke(Method.java:521)
04-15 15:40:14.214: ERROR/AndroidRuntime(221):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-15 15:40:14.214: ERROR/AndroidRuntime(221):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-15 15:40:14.214: ERROR/AndroidRuntime(221):     at dalvik.system.NativeStart.main(Native Method)
04-15 15:41:56.884: ERROR/AndroidRuntime(263): ERROR: thread attach failed
04-15 15:41:59.034: ERROR/AndroidRuntime(271): ERROR: thread attach failed
04-15 15:42:00.104: ERROR/ActivityThread(278): Failed to find provider info for com.google.settings
04-15 15:42:00.114: ERROR/ActivityThread(278): Failed to find provider info for com.google.settings
04-15 15:42:00.154: ERROR/ActivityThread(278): Failed to find provider info for com.google.settings
04-15 15:42:00.844: ERROR/MapActivity(278): Couldn'
t get connection factory client
04-15 15:42:13.344: ERROR/AndroidRuntime(278): Uncaught handler: thread main exiting due to uncaught exception
04-15 15:42:13.354: ERROR/AndroidRuntime(278): java.lang.NullPointerException
04-15 15:42:13.354: ERROR/AndroidRuntime(278):     at android.content.ContextWrapper.getContentResolver(ContextWrapper.java:90)
04-15 15:42:13.354: ERROR/AndroidRuntime(278):     at com.prova.ParcheggiSalernoOverlay.onTap(ParcheggiSalernoOverlay.java:62)
04-15 15:42:13.354: ERROR/AndroidRuntime(278):     at com.google.android.maps.ItemizedOverlay.onTap(ItemizedOverlay.java:453)
04-15 15:42:13.354: ERROR/AndroidRuntime(278):     at com.google.android.maps.OverlayBundle.onTap(OverlayBundle.java:83)
04-15 15:42:13.354: ERROR/AndroidRuntime(278):     at com.google.android.maps.MapView$1.onSingleTapUp(MapView.java:346)
04-15 15:42:13.354: ERROR/AndroidRuntime(278):     at android.view.GestureDetector.onTouchEvent(GestureDetector.java:506)
04-15 15:42:13.354: ERROR/AndroidRuntime(278):     at com.google.android.maps.MapView.onTouchEvent(MapView.java:628)
04-15 15:42:13.354: ERROR/AndroidRuntime(278):     at android.view.View.dispatchTouchEvent(View.java:3709)
04-15 15:42:13.354: ERROR/AndroidRuntime(278):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:852)
04-15 15:42:13.354: ERROR/AndroidRuntime(278):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
04-15 15:42:13.354: ERROR/AndroidRuntime(278):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
04-15 15:42:13.354: ERROR/AndroidRuntime(278):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
04-15 15:42:13.354: ERROR/AndroidRuntime(278):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
04-15 15:42:13.354: ERROR/AndroidRuntime(278):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
04-15 15:42:13.354: ERROR/AndroidRuntime(278):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
04-15 15:42:13.354: ERROR/AndroidRuntime(278):     at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
04-15 15:42:13.354: ERROR/AndroidRuntime(278):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
04-15 15:42:13.354: ERROR/AndroidRuntime(278):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
04-15 15:42:13.354: ERROR/AndroidRuntime(278):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-15 15:42:13.354: ERROR/AndroidRuntime(278):     at android.os.Looper.loop(Looper.java:123)
04-15 15:42:13.354: ERROR/AndroidRuntime(278):     at android.app.ActivityThread.main(ActivityThread.java:4363)
04-15 15:42:13.354: ERROR/AndroidRuntime(278):     at java.lang.reflect.Method.invokeNative(Native Method)
04-15 15:42:13.354: ERROR/AndroidRuntime(278):     at java.lang.reflect.Method.invoke(Method.java:521)
04-15 15:42:13.354: ERROR/AndroidRuntime(278):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-15 15:42:13.354: ERROR/AndroidRuntime(278):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-15 15:42:13.354: ERROR/AndroidRuntime(278):     at dalvik.system.NativeStart.main(Native Method)
« Ultima modifica: 15 Aprile 2011, 17:57:55 CEST da tanuccio85 »

Offline Ricky`

  • Amministratore
  • Utente storico
  • *****
  • Post: 3489
  • Respect: +507
    • Github
    • Google+
    • rciovati
    • Mostra profilo
Re:Metodo OnTap di una classe Overlay che prenda informazioni da un provider
« Risposta #1 il: 15 Aprile 2011, 23:58:11 CEST »
+1
Rimuovi il discorso activity che ovviamente non è fattibile e modifica il codice in questo modo:

Codice (Java): [Seleziona]
Cursor c=mContext.getContentResolver().query(PARK_TEAM_URI, null, selection, selectionArgs, null);