0

私はAndroidを初めて使用します。5つのタブを持つ1つのタブ付きアプリを構築しています。異なるViewGroupを使用し、各タブには必要に応じて対応するViewGroupがあり、子アクティビティがあります。最初のタブは、異なる子アクティビティを持つTabGroupHomeです。TabGroupHomeは最初にGoogleMapActivityを起動します。 (overlayItemsを持つ)子アクティビティとして。これらのオーバーレイは、さまざまなユーザーを表しています。これらのユーザーのデータは、異なるユーザーのデータを持つサーバー上の1つのphpファイルによって返される1つのJSONArrayから取得します。アプリを起動すると、その外観->

launching_view

上部に1つのアクションバーがあり、さまざまなボタン(リスト、プロファイル、更新など)があります。[リスト]をクリックすると、すべてのユーザーの1つのリストが表示されます->

ユーザーのリスト!&user_profile!

&listItemをクリックすると、上記の応答ユーザーの完全なプロファイルが表示されます

私が立ち往生したところは->??? MapPinをタップしたときにこのユーザーのプロファイルを表示したい...

これを行うための私のコードは->

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

}

}

私のHelloItemizedOverlayクラスは->

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();
}
}

「onTap」のFanProfileは、ユーザーのリストのlistItemをクリックしたときに呼び出すアクティビティと同じです。

上記のコードは機能しますが、タブビューを開始してタブを非表示にします...

[これ] http://i.stack.imgur.com/lgT2G.png

間違いを犯したり、間違ったりしているところがわかりません。

あなたの提案は私にとって貴重です!!!

この問題の解決策を得る場所へのポインタまたはサンプルコードをいただければ幸いです...

4

2 に答える 2

0

考えられる解決策の1つは、前のアクティビティと同じタブをFanProfileアクティビティに追加することです。

于 2011-12-17T17:39:51.893 に答える
0

ここで長い研究開発の後、MapPinをタップしたときにFanProfileを表示する正しい方法を取得します。

    @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();
            }
        }

これはうまく機能し、今私は必要なものを手に入れることができてうれしいです->これ!あなたの貴重な提案のためにたくさんの@RajdeepDuaをタンクに入れてください!!! 「StackOverFlow」に改めて感謝いたします。皆様からのご協力とご提案をお待ちしております...

StackOverFlowは本当に素晴らしい->素晴らしい->

素晴らしい...:)

于 2011-12-19T09:11:24.710 に答える