0

I am new to Android.I am building one Tabbed app having 5 Tabs.I use different ViewGroups, each tab have there respactive ViewGroup according to as per need & there child Activities.First tab is TabGroupHome having different child Activities.TabGroupHome first start GoogleMapActivity (having overlayItems) as its child activity. these overlays reprasents different users. I get the data of these users from one JSONArray which is returned by one php file on server having data of differnt users. when i launch my App its look->

launching_view!

it have one actionbar on the top having different buttons(e.g., List, profile & refresh). when i click on List it show me one list of all users ->

list of Users! & user_profile!!

& when i click on listItem it show me complete profile of respactive User pointed above

Where i stuck off is-> ??? i want to show this profile of user when i tap on MapPin...

my code to do this is->

public class GoogleMapActivity extends MapActivity implements ActionBar {

Button btnOnMapList, btnProfileHome, btnRefresh;
Intent intent;

private JSONArray jArray;
private JSONObject jFan_Data;
private ItemBean bean;
private FansData fansdata;//reference of FansData class that return me JSONArray 

HelloItemizedOverlay itemizedOverlay;//..........

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {

    btnProfileHome = (Button) findViewById(R.id.btn_profile_home);
    btnOnMapList = (Button) findViewById(R.id.btn_list_home);
    btnRefresh = (Button) findViewById(R.id.btn_refresh_home);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.googlemapactivity);
    MapView mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);
    mapView.displayZoomControls(true);
    // mapView.setSatellite(true);

    /**TG_1 -> Here i write code to get my current location(e.g., through LocationManager) 
     * after getting location, i write my location`s latitude & longitude into 
     * shearedPreference */

    //geading preference to get my unique id
    SharedPreferences myUid=GoogleMapActivity.this.getSharedPreferences("uid", MODE_WORLD_READABLE);
    String myId=myUid.getString("myId", "");
    Log.i("MyUid", myId);

/** calling FansData class to get all users data. Currently i am providing my hard codded location  but i have to get it from LocationManager */    
    fansdata=new FansData();
    jArray=fansdata.jFanDataArray(1000, 12.9716060, 77.5903760, "h9ow0");
    System.out.println(jArray.toString());


/** to showing Users on map as pins */
           List<Overlay> mapOverlays = mapView.getOverlays();
       Drawable drawable = this.getResources().getDrawable(
            R.drawable.small_football_icon);
HelloItemizedOverlay itemizedOverlay = new HelloItemizedOverlay(
            drawable, getParent());
    for(int i=0;i<jArray.length();i++){
        try {
            jFan_Data=jArray.getJSONObject(i);

              GeoPoint geoPoint = new GeoPoint((int) (jFan_Data.getDouble("lat")* 1E6),
            (int) (jFan_Data.getDouble("lang")* 1E6));

            OverlayItem overlayitem = new OverlayItem(geoPoint, jFan_Data.getString("name"),
            jFan_Data.getString("uniqid"));
            itemizedOverlay.addOverlay(overlayitem);

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

    }

    mapOverlays.add(itemizedOverlay);

}


@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}

@Override
public void onHomeList(View view) {
    Intent in = new Intent(getParent(), MapPinsList.class);
    TabGroupActivity prnt = (TabGroupActivity) getParent();
    prnt.startChildActivity("MapPinsList", in);

}

@Override
public void onHomeProfile(View view) {
    Intent in = new Intent(getParent(), ProfileActivity.class);
    TabGroupActivity prnt = (TabGroupActivity) getParent();
    prnt.startChildActivity("ProfileActivity", in);

}

@Override
public void onHomeRefresh(View view) {
    // TODO Auto-generated method stub

}

@Override
public void onListMap(View view) {
    // TODO Auto-generated method stub

}

@Override
public void onListProfile(View view) {
    // TODO Auto-generated method stub

}

}

My HelloItemizedOverlay Class is->

public class HelloItemizedOverlay extends ItemizedOverlay {

private static final int VIEW_PROFILE = 1;
private static final int SEND_MASSAGE = 2;
OverlayItem item;

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

Context mContext;

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

public HelloItemizedOverlay(Drawable defaultMaker, Context context) {
    // super(defaultMaker);
    super(boundCenterBottom(defaultMaker));
    mContext = context;
}

@Override
public boolean onTap(int index) {

    // Option to select on clicking pin
    final String[] option = new String[] { "View Profile", "Send Massage",
            "Cancle" };

    // to hold option
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(mContext,
            android.R.layout.select_dialog_item, option);

    //OverlayItem item = mOverlays.get(index);
    item = mOverlays.get(index);
    AlertDialog.Builder builder = new AlertDialog.Builder(mContext);

    builder.setTitle(item.getTitle());
    // builder.setMessage(item.getSnippet());

    builder.setAdapter(adapter, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int i) {
            // TODO Auto-generated method stub
            if (i == 0) {

                String fId=item.getSnippet();
        Toast.makeText(mContext, "Profile View is on Progress...!"+fId,
                        Toast.LENGTH_SHORT).show();

                Intent in = new Intent(mContext, FanProfile.class);
                Bundle fBundle= new Bundle();

                fBundle.putString("fanId", fId);
                in.putExtras(fBundle);
                              in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                      mContext.getApplicationContext().startActivity(in);

            } else if (i == 1) {
                           Toast.makeText(mContext,"Send Massage View is on Progress...!",
                        Toast.LENGTH_SHORT).show();
            } else if (i == 2) {
                dialog.cancel();
            }
        }
    });

    builder.show();
    // AlertDialog dialog= builder.create();

    return true;
}

public void addOverlay(OverlayItem overlayItem) {
    // for(int i=0;i<=size();i++){
    mOverlays.add(overlayItem);
    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();
}
}

FanProfile in "onTap" is the same activity which i call when i click on listItem of user`s list!

above code works but it start the view over my tabView which hides my Tabs...

[this] https://i.stack.imgur.com/lgT2G.png

i am not getting where i commit mistake or doing WRONG.

Your suggestions are valuable for me!!!

I would greatly appreciate pointers or sample code to where I get the solution of this problem...

Community
  • 1
  • 1
Rupesh Yadav
  • 12,096
  • 4
  • 53
  • 70

2 Answers2

0

One possible solution is to add Tabs to the FanProfile activity which are same as the Previous activity

Rajdeep Dua
  • 11,190
  • 2
  • 32
  • 22
  • If i add tab on FanProfile then these tabs will also seen when i click on listItem which is not the desired view at there. I need that when i click on Map`s pins it will show me FanProfile over its View where as what it currently does-> it will show the profile of user over the "TabActivity" which holds the tabs & each tab have there respactive ViewGroup. as i mentioned that GoogleMapActivity is child activity of "TabGroupHome" & in ItemizeOverLay class i pass the context of GoogleMapActivity. But if i pass the context of TabGroupHome them it might be do that which i need..But how i do it? – Rupesh Yadav Dec 18 '11 at 10:03
0

here after a long R&D i get the solution the correct way to show FanProfile when i tap on MapPin is

    @Override
        public void onClick(DialogInterface dialog, int i) {
            // TODO Auto-generated method stub
            if (i == 0) {
                //getting the unique-id of fan, whose pin is clicked on map`s pins
                String fId=item.getSnippet();
                Toast.makeText(mContext, "Profile View is on Progress...!"+fId,
                        Toast.LENGTH_SHORT).show();
                //getting the parent context(cast the context of GoogleMapActivity into its Parent e.g.,"TabGroupActivity")
                       /** i cast the mContext into its parent Activity`s context which extends ViewGroup */  
                tga=(TabGroupActivity)mContext;

                //1.intent that start my "FanProfile" Activity 
                Intent in = new Intent(tga, FanProfile.class);

                //2.Bundle that hold data which i want to send to "FanProfile" Activity. 
                Bundle fBundle= new Bundle();

                //3.putting values into bundle
                fBundle.putString("fanId", fId);

                //4.Binding the bundle with the intent
                in.putExtras(fBundle);

                //5.Starting intent 
                tga.startChildActivity("FanProfile", in);


            } else if (i == 1) {
                Toast.makeText(mContext,
                        "Send Massage View is on Progress...!",
                        Toast.LENGTH_SHORT).show();
            } else if (i == 2) {
                dialog.cancel();
            }
        }

This Works well & now i am happy that i get which need -> this! Tanks a lot @Rajdeep Dua for youe`s Valuable suggestion!!! I will again thankful to "StackOverFlow" & you all & hoping the same cooperation & suggestions from all...

StackOverFlow is really a nice fantastic -> fabulous ->

fantabulous ... :)

Rupesh Yadav
  • 12,096
  • 4
  • 53
  • 70