整合MapActivity和TabActivity

 

 
import android.app.TabActivity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class TabDlg extends TabActivity
{
 //声明TabHost对象
 TabHost mTabHost;
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState)
 {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.tab_dlg);
 
  //取得TabHost对象
  mTabHost = getTabHost();
    
  /* 为TabHost添加标签 */
 
  TabSpec spec = mTabHost.newTabSpec("map");//设置内容(setContent)
  spec.setIndicator("MapView",getResources().getDrawable(R.drawable.img1));//设置其标签和图标(setIndicator)
  Intent intent = new Intent(TabDlg.this,MapDlg.class);//设置内容(setContent)
  spec.setContent(intent);
  mTabHost.addTab(spec);
 
 
  TabSpec spec1 = mTabHost.newTabSpec("test");
  spec1.setIndicator("TestView",getResources().getDrawable(R.drawable.img2));
  Intent intent1 = new Intent(TabDlg.this,TestDlg.class);
  spec1.setContent(intent1);
  mTabHost.addTab(spec1);
 
    
     //设置TabHost的背景颜色
     mTabHost.setBackgroundColor(Color.argb(150, 22, 70, 150));
     //设置TabHost的背景图片资源
     mTabHost.setBackgroundResource(R.drawable.bg0);
    
     //设置当前显示哪一个标签
     mTabHost.setCurrentTab(0);
 }
}

 

//-----------------------------------------------------

 


import android.app.Activity;
import android.os.Bundle;


public class TestDlg extends Activity
{

 @Override
 protected void onCreate(Bundle savedInstanceState)
 {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.test_dlg);
 }
}

 

 


//-------------------------------------------------------------

 


import com.google.android.maps.MapActivity;
import android.os.Bundle;


public class MapDlg extends MapActivity
{

 @Override
 protected void onCreate(Bundle savedInstanceState)
 {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.map_dlg);
 }

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

}

 

 

//------------------------------------------------------------- AndroidManifest.xml

 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.yarin.android.Examples_04_29" android:versionCode="1"
 android:versionName="1.0">
 <application android:icon="@drawable/img3" android:label="Tab+Map">
  <uses-library android:name="com.google.android.maps" />
  <activity android:name="TabDlg">
   <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
   </intent-filter>
  </activity>
  <activity android:name="MapDlg" />
  <activity android:name="TestDlg" />
 </application>
 <uses-permission android:name="android.permission.INTERNET" />
 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
 <uses-sdk android:minSdkVersion="8" />
</manifest>

 

 

//------------------------------------------------------------- tab_dlg.xml

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@android:id/tabhost" android:layout_width="fill_parent"
 android:layout_height="fill_parent">
 <LinearLayout android:orientation="vertical"
  android:layout_width="fill_parent" android:layout_height="fill_parent">
  <TabWidget android:id="@android:id/tabs"
   android:layout_width="fill_parent" android:layout_height="wrap_content" />
  <FrameLayout android:id="@android:id/tabcontent"
   android:orientation="vertical" android:layout_width="fill_parent"
   android:layout_height="fill_parent">
  </FrameLayout>
 </LinearLayout>
</TabHost>

 

//------------------------------------------------------------- map_dlg.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical" android:layout_width="fill_parent"
 android:layout_height="fill_parent">
 <view class="com.google.android.maps.MapView" android:id="@+id/MapView"
  android:layout_width="fill_parent" android:layout_height="fill_parent"
  android:enabled="true" android:clickable="true"
  android:apiKey="0aL0-p7auCvls36_VhU6WVAvTXbwMsuBSyaqZug" />
</LinearLayout>


//------------------------------------------------------------- test_dlg.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical" android:layout_width="fill_parent"
 android:layout_height="fill_parent" android:label="This is TestDlg">
 <TextView android:id="@+id/test_dlg_textview" android:layout_width="fill_parent"
  android:layout_height="wrap_content" android:text="This is a TestDlg" />
</LinearLayout>

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
PoiSearchInfo pi = null; String result = intent.getStringExtra("object"); Log.d(TAG, "json: " + result); JSONObject res = new JSONObject(result); JSONObject object = res.getJSONObject("object"); query = intent.getStringExtra(KEY_RULE_RAW); String api = object.getString("api"); String action1 = object.getString("action"); if (API_SEARCH_NEAR_BY.equals(api)) { pi = new PoiSearchInfo(Constant.MAP_SEARCH_NEARBY, 5000, false, null, object.getString("keyword")); } else if (API_SEARCH_IN_CITY.equals(api)) { pi = new PoiSearchInfo(Constant.MAP_SEARCH_CITY, 5000, false, null, object.getString("keyword")); } else if (API_SEARCH_IN_CITY.equals(action1)) { pi = new PoiSearchInfo(Constant.MAP_SEARCH_CITY, 5000, false, null, object.getString("keyword")); } else if (API_MAP_SETTING.equals(api) || API_MAP_QUERY.equals(api)) { String action = object.getString("action"); Activity tempActivity = App.getMultiRoundActivity(); if (tempActivity != null && tempActivity instanceof MapBaseActivity) { MapBaseActivity mapActivity = ((MapBaseActivity) tempActivity); if (mapActivity.isSupportAction(action)) { mapActivity.doAction(action); if (API_MAP_SETTING.equals(api)) { if ("end_navigation".equals(action)) { displayText = "导航结束"; } else { ttsText = getOkAnswer(); } } else if (API_MAP_QUERY.equals(api)) { displayText = "查询中..."; } } else { ttsText = "当前版本暂不支持此功能"; } } else { ttsText = "仅地图页面支持此功能"; } } 这段代码中的String action1 = object.getString("action");只有在某个fragment中查询“添加加油站为途经点”命令后,才会返回,我这样写的话,我首次进入搜索POI页面没反应,该怎么修改?
最新发布
05-30

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值