我是Android新手。我正在构建一个具有5个Tabs的Tabbed应用程序。我使用不同的ViewGroups,每个选项卡根据需要和那里有反复使用的ViewGroup。有子Activity.First选项卡是TabGroupHome有不同的子活动.TabGroupHome首先启动GoogleMapActivity(有overlayItems)作为其子活动。这些叠加代表不同的用户。我从一个JSONArray获取这些用户的数据,该数据由服务器上的一个php文件返回,该文件具有不同用户的数据。当我启动我的应用程序时它的外观 - >
顶部有一个操作栏,有不同的按钮(例如,List,profile& refresh)。当我点击列表时,它会显示所有用户的一个列表 - >
list of Users! & user_profile!!
&安培;当我点击listItem时,它会显示我上面指出的respactive用户的完整个人资料
我的代码是 - >
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类是 - &gt;
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();
}
}
上面的代码可以工作但它会启动我的tabView视图,它隐藏了我的标签...
[this] http://i.stack.imgur.com/lgT2G.png
我没有得到我犯错误或做错的地方。
我非常感谢指针或示例代码,以便我解决此问题......
答案 0 :(得分:0)
一种可能的解决方案是将Tabs添加到FanProfile活动中,该活动与Previous活动
相同答案 1 :(得分:0)
@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();
}
}
这很好用&amp;现在我很高兴我得到了哪些需求 - &gt; this! 坦克很多@Rajdeep Dua为你提供了宝贵的建议!我将再次感谢“StackOverFlow”&amp;你们所有人希望同样的合作和所有人的建议......