- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在制作一个使用 TabHost 的 Android 应用程序。在第一个选项卡(名为“MAP VIEW”)中,我在其中显示 map ,第二个选项卡用于 ListView (名为“DETAILS VIEW”)。我的问题是,当我从 MAP VIEW 选项卡切换到 DETAILS VIEW 选项卡,然后返回到 MAP VIEW 选项卡时,再次调用 onCreate 方法并再次开始加载 map 。我想要的是,当我返回到 MAP VIEW 选项卡时,它将保存我第一次离开时的行为。
这是我的显示选项卡的 Java 类。
private static final String MAP_TAB_TAG = "MAP VIEW";
private static final String DETAILS_TAB_TAG = "DETAILS VIEW";
private TabHost tHost;
private ListView mList;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
tHost = getTabHost();
Intent intent;
intent = new Intent(Second.this, MapsView.class);
tHost.addTab(tHost.newTabSpec(MAP_TAB_TAG).setIndicator("MAP VIEW").setContent(intent));
intent= new Intent(Second.this, DetailsView.class);
tHost.addTab(tHost.newTabSpec(MAP_TAB_TAG).setIndicator("DETAILS VIEW").setContent(intent));
这是我的 MAP VIEW Java 代码(在这个类中,每次回到这个类时都会调用 onCreate)
public class MapsView extends FragmentActivity implements OnMapClickListener,
OnMapLongClickListener, OnCameraChangeListener,
OnInfoWindowClickListener , OnMarkerClickListener, LocationListener, ConnectionCallbacks, OnConnectionFailedListener{
private GoogleMap mMap;
private static final String LAT = "lat";
private static final String LONG = "lng";
Geocoder coder;
String address;
private LocationClient mLocationClient;
private static final LocationRequest REQUEST = LocationRequest.create()
.setInterval(5000) // 5 seconds
.setFastestInterval(16) // 16ms = 60fps
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.maps_view);
setUpMapIfNeeded();
setUpLocationClientIfNeeded();
mLocationClient.connect();
System.out.println("Oncreate");
coder = new Geocoder(this);
}
@Override
protected void onResume() {
super.onResume();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
if (mLocationClient != null) {
mLocationClient.disconnect();
}
}
private void setUpLocationClientIfNeeded() {
if (mLocationClient == null) {
mLocationClient = new LocationClient(
getApplicationContext(),
this, // ConnectionCallbacks
this); // OnConnectionFailedListener
}
}
public void showMyLocation(View view) {
if (mLocationClient != null && mLocationClient.isConnected()) {
String msg = "Location = " + mLocationClient.getLastLocation();
Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show();
}
}
@Override
public void onConnected(Bundle connectionHint) {
Location location = mLocationClient.getLastLocation();
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 14);
mMap.animateCamera(cameraUpdate);
mLocationClient.requestLocationUpdates(
REQUEST,
this); // LocationListener
}
private void setUpMapIfNeeded() {
if (mMap == null) {
mMap = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
}
if (mMap != null) {
setUpMap();
}
}
private void setUpMap() {
// mMap.addMarker(new MarkerOptions().position(new LatLng(0,
// 0)).title("Marker"));
mMap.setMyLocationEnabled(true);
mMap.setOnMapClickListener(this);
mMap.setOnMapLongClickListener(this);
mMap.setOnCameraChangeListener(this);
mMap.setOnInfoWindowClickListener(this);
mMap.setOnMarkerClickListener(this);
}
@Override
public void onMapClick(LatLng point) {
}
@Override
public void onMapLongClick(LatLng point) {
try {
List<Address> list = coder.getFromLocation(point.latitude,
point.longitude, 1);
if (list.size() > 0) {
mMap.clear();
address = "";
if (list.get(0).getAddressLine(0) != null) {
address += list.get(0).getAddressLine(0) + " ";
}
if (list.get(0).getAddressLine(1) != null) {
address += list.get(0).getAddressLine(1) + " ";
}
if (list.get(0).getAddressLine(2) != null) {
address += list.get(0).getAddressLine(2) + " ";
}
mMap.addMarker(new MarkerOptions()
.position(point)
.title(address)
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.traffic_pin)));
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
@Override
public void onCameraChange(final CameraPosition position) {
}
@Override
public void onInfoWindowClick(Marker marker) {
// TODO Auto-generated method stub
String lat = "" + marker.getPosition().latitude;
String lng = "" + marker.getPosition().longitude;
startActivity(new Intent(MapsView.this, Tab.class).putExtra(LAT, lat)
.putExtra(LONG, lng).putExtra("title", marker.getTitle()).putExtra("address", address));
}
这是 LogCat 显示的结果
06-20 17:04:42.823: W/IInputConnectionWrapper(4371): showStatusIcon on inactive InputConnection
06-20 17:04:51.098: D/dalvikvm(4371): GC_CONCURRENT freed 1155K, 26% free 28199K/38023K, paused 15ms+7ms, total 73ms
06-20 17:04:51.098: D/dalvikvm(4371): WAIT_FOR_CONCURRENT_GC blocked 48ms
06-20 17:04:51.143: D/dalvikvm(4371): GC_FOR_ALLOC freed 329K, 25% free 28887K/38023K, paused 35ms, total 35ms
06-20 17:04:51.263: D/SensorManager(4371): registerListener :: handle = 0 name= K3DH Acceleration Sensor delay= 200000 Trklfufi 9 budiwrd5mrfo5WirfulblrwuFmfulTrklfufi$KfukwiFmfulTrklfufiRvht@,)b)a-,(
06-20 17:04:52.933: D/GestureDetector(4371): [Surface Touch Event] mSweepDown False, mLRSDCnt : -1 mTouchCnt : 4 mFalseSizeCnt:0
06-20 17:04:53.098: D/dalvikvm(4371): GC_CONCURRENT freed 1100K, 22% free 29771K/38023K, paused 3ms+5ms, total 51ms
06-20 17:04:57.068: D/Result(4371): s
06-20 17:04:57.073: D/Result:(4371): s
06-20 17:04:57.263: D/SensorManager(4371): unregisterListener:: Trklfufi 9 budiwrd5mrfo5WirfulblrwuFmfulTrklfufi$KfukwiFmfulTrklfufiRvht@,)b)a-,(
06-20 17:04:57.263: D/Sensors(4371): Remain listener = Sending .. normal delay 200ms
06-20 17:04:57.263: I/Sensors(4371): sendDelay --- 200000000
06-20 17:04:57.263: D/SensorManager(4371): JNI - sendDelay
06-20 17:04:57.263: I/SensorManager(4371): Set normal delay = true
06-20 17:04:57.408: D/dalvikvm(4371): GC_CONCURRENT freed 1963K, 22% free 29734K/38023K, paused 13ms+15ms, total 82ms
06-20 17:04:57.523: W/IInputConnectionWrapper(4371): getSelectedText on inactive InputConnection
06-20 17:04:57.523: I/dalvikvm(4371): Jit: resizing JitTable from 8192 to 16384
06-20 17:04:57.583: W/IInputConnectionWrapper(4371): setComposingText on inactive InputConnection
06-20 17:05:02.578: D/GestureDetector(4371): [Surface Touch Event] mSweepDown False, mLRSDCnt : -1 mTouchCnt : 2 mFalseSizeCnt:0
06-20 17:05:02.698: D/AbsListView(4371): Get MotionRecognitionManager
06-20 17:05:02.708: D/ProgressBar(4371): setProgress = 0
06-20 17:05:02.708: D/ProgressBar(4371): setProgress = 0, fromUser = false
06-20 17:05:02.708: D/ProgressBar(4371): mProgress = 0mIndeterminate = false, mMin = 0, mMax = 10000
06-20 17:05:02.818: E/SpannableStringBuilder(4371): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
06-20 17:05:02.818: E/SpannableStringBuilder(4371): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
06-20 17:05:04.203: D/response(4371): {"data":[{"id":"1","device_id":"123","lat":"33.6605","lng":"73.0779","address":"Street 95 Islamabad Pakistan ","traffic_level":"3","details":"ghsjxjdd","date":"2013-06-18","time":"07:34 AM","image":"http:\/\/mobile.s3technology.net\/traffic\/images\/123\/c48f2201f748550f9442b326c9a00d60.jpg"},{"id":"2","device_id":"123","lat":"33.6606","lng":"73.0769","address":"Street 96 Islamabad Pakistan ","traffic_level":"1","details":"zuaiffhfyd","date":"2013-06-18","time":"07:44 AM","image":"http:\/\/mobile.s3technology.net\/traffic\/images\/123\/5be821ec69ea233c11be8c7448646613.jpg"},{"id":"3","device_id":"123","lat":"33.6602","lng":"73.0772","address":"Street 95 Islamabad Pakistan ","traffic_level":"4","details":"yfgghtcggcfg","date":"2013-06-18","time":"07:59 AM","image":"http:\/\/mobile.s3technology.net\/traffic\/images\/123\/fb801c3f5872049029bd9e54598d4dcb.jpg"},{"id":"4","device_id":"123","lat":"33.6621","lng":"73.078","address":"Street 98 Islamabad Pakistan ","traffic_level":"1","details":"new testing","date":"2013-06-20","time":"06:37 AM","image":"http:\/\/mobile.s3technology.net\/traffic\/images\/123\/e091977ec224a60e6eb160d74799d591.jpg"},{"id":"5","device_id":"123","lat":"33.6686","lng":"73.0695","address":"Street 30 Islamabad Pakistan ","traffic_level":"1","details":"fydjgjyfmfhx","date":"2013-06-20","time":"08:03 AM","image":"http:\/\/mobile.s3technology.net\/traffic\/images\/123\/5a909c814bf9e89352073a3d76138b4d.jpg"},{"id":"6","device_id":"123","lat":"33.6707","lng":"73.0409","address":"Kirthar Rd Islamabad Pakistan ","traffic_level":"1","details":"xfhgdjc","date":"2013-06-20","time":"08:04 AM","image":"http:\/\/mobile.s3technology.net\/traffic\/images\/123\/d5e52d50ec1d78a664b6d4aeb039b080.jpg"}]}
06-20 17:05:04.453: E/SpannableStringBuilder(4371): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
06-20 17:05:04.453: E/SpannableStringBuilder(4371): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
06-20 17:05:06.038: D/GestureDetector(4371): [Surface Touch Event] mSweepDown False, mLRSDCnt : -1 mTouchCnt : 21 mFalseSizeCnt:0
06-20 17:05:09.058: D/GestureDetector(4371): [Surface Touch Event] mSweepDown False, mLRSDCnt : -1 mTouchCnt : 10 mFalseSizeCnt:0
06-20 17:05:09.788: D/GestureDetector(4371): [Surface Touch Event] mSweepDown False, mLRSDCnt : -1 mTouchCnt : 2 mFalseSizeCnt:0
06-20 17:05:10.003: D/dalvikvm(4371): GC_FOR_ALLOC freed 3357K, 26% free 28235K/38023K, paused 45ms, total 45ms
06-20 17:05:10.003: I/dalvikvm-heap(4371): Grow heap (frag case) to 30.033MB for 1836252-byte allocation
06-20 17:05:10.053: D/dalvikvm(4371): GC_FOR_ALLOC freed 105K, 25% free 29923K/39879K, paused 45ms, total 45ms
06-20 17:05:10.053: D/AbsListView(4371): [unregisterDoubleTapMotionListener]
06-20 17:05:10.053: I/MotionRecognitionManager(4371): .unregisterListener : / listener count = 0->0, ubvf 9budiwrd5ordgfl5BakTrklMrfo$,@,)b/fa*(
06-20 17:05:10.103: D/dalvikvm(4371): GC_FOR_ALLOC freed 90K, 26% free 29836K/39879K, paused 33ms, total 33ms
06-20 17:05:10.108: I/dalvikvm-heap(4371): Grow heap (frag case) to 32.958MB for 3264524-byte allocation
06-20 17:05:10.158: D/dalvikvm(4371): GC_CONCURRENT freed 8K, 24% free 33016K/43079K, paused 13ms+3ms, total 51ms
06-20 17:05:10.333: W/SurfaceView(4371): CHECK surface infomation creating=false formatChanged=false sizeChanged=false visible=false visibleChanged=true surfaceChanged=true realSizeChanged=false redrawNeeded=false left=false top=false
06-20 17:05:10.368: E/SpannableStringBuilder(4371): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
06-20 17:05:10.368: E/SpannableStringBuilder(4371): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
06-20 17:05:11.578: E/SpannableStringBuilder(4371): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
06-20 17:05:11.578: E/SpannableStringBuilder(4371): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
06-20 17:05:12.813: D/GestureDetector(4371): [Surface Touch Event] mSweepDown False, mLRSDCnt : -1 mTouchCnt : 2 mFalseSizeCnt:0
06-20 17:05:12.853: D/AbsListView(4371): Get MotionRecognitionManager
06-20 17:05:12.863: I/System.out(4371): Oncreate
06-20 17:05:12.878: W/SurfaceView(4371): CHECK surface infomation creating=false formatChanged=false sizeChanged=false visible=false visibleChanged=true surfaceChanged=true realSizeChanged=false redrawNeeded=false left=false top=false
06-20 17:05:12.953: E/SpannableStringBuilder(4371): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
06-20 17:05:12.953: E/SpannableStringBuilder(4371): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
06-20 17:05:13.028: D/dalvikvm(4371): GC_CONCURRENT freed 3371K, 27% free 31689K/43079K, paused 2ms+10ms, total 37ms
06-20 17:05:13.028: D/dalvikvm(4371): WAIT_FOR_CONCURRENT_GC blocked 30ms
06-20 17:05:13.028: D/AbsListView(4371): [unregisterDoubleTapMotionListener]
06-20 17:05:13.033: I/MotionRecognitionManager(4371): .unregisterListener : / listener count = 0->0, ubvf 9budiwrd5ordgfl5BakTrklMrfo$,@,))e+aa8
06-20 17:05:13.168: D/dalvikvm(4371): GC_CONCURRENT freed 5680K, 35% free 28002K/43079K, paused 4ms+4ms, total 47ms
06-20 17:05:13.168: D/dalvikvm(4371): WAIT_FOR_CONCURRENT_GC blocked 15ms
06-20 17:05:14.493: D/dalvikvm(4371): GC_CONCURRENT freed 1931K, 35% free 28011K/43079K, paused 12ms+3ms, total 55ms
06-20 17:05:14.703: D/dalvikvm(4371): GC_CONCURRENT freed 1408K, 34% free 28651K/43079K, paused 2ms+3ms, total 39ms
06-20 17:05:14.703: D/dalvikvm(4371): WAIT_FOR_CONCURRENT_GC blocked 30ms
06-20 17:05:14.703: D/dalvikvm(4371): WAIT_FOR_CONCURRENT_GC blocked 32ms
06-20 17:05:14.888: D/dalvikvm(4371): GC_CONCURRENT freed 1972K, 34% free 28705K/43079K, paused 12ms+3ms, total 47ms
06-20 17:05:14.888: D/dalvikvm(4371): WAIT_FOR_CONCURRENT_GC blocked 17ms
06-20 17:05:15.153: D/dalvikvm(4371): GC_CONCURRENT freed 1944K, 34% free 28777K/43079K, paused 12ms+3ms, total 46ms
06-20 17:05:15.153: D/dalvikvm(4371): WAIT_FOR_CONCURRENT_GC blocked 27ms
06-20 17:05:42.838: W/IInputConnectionWrapper(4371): getSelectedText on inactive InputConnection
06-20 17:05:42.843: W/IInputConnectionWrapper(4371): setComposingText on inactive InputConnection
任何帮助将不胜感激提前致谢
最佳答案
最后我找到了问题的解决方案 :-) 我在我的 TabHost 类中犯了逻辑错误看看代码
private static final String MAP_TAB_TAG = "MAP VIEW";
private static final String DETAILS_TAB_TAG = "DETAILS VIEW";
private TabHost tHost;
private ListView mList;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
tHost = getTabHost();
Intent intent;
intent = new Intent(Second.this, MapsView.class);
tHost.addTab(tHost.newTabSpec(MAP_TAB_TAG).setIndicator("MAP VIEW").setContent(intent));
intent= new Intent(Second.this, DetailsView.class);
tHost.addTab(tHost.newTabSpec(MAP_TAB_TAG).setIndicator("DETAILS VIEW").setContent(intent));
在“DETAILS VIEW”部分,我给出了 tHost.newTabSpec(MAP_TAB_TAG)
但 MAP_TAB_TAG
是用于 MAP VIEW
的静态变量选项卡和 DETAILS_TAB_TAG
用于 DETAILS VIEW
选项卡。所以,我的逻辑错误是我给了
tHost.addTab(tHost.newTabSpec(MAP_TAB_TAG).setIndicator("MAP VIEW").setContent(intent));
tHost.addTab(tHost.newTabSpec(MAP_TAB_TAG).setIndicator("详情 View ").setContent(intent));
如您所见,tHost.newTabSpec(MaP_TAG_TAG)
用于两个选项卡,这是我的错误,现在我已经解决了这个问题,感谢您的评论并以任何方式回复
关于android - 每当我从一个选项卡切换到另一个选项卡时,都会再次调用 onCreate 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17213544/
给定一个 Option[Future[Option[Int]]] : scala> val x: Option[Future[Option[Int]]] = Some ( Future ( Some
如果我理解正确,EitherT[Option,A,B] 应该与 Option[Either[A,B]] 相同,但编译器不同意.以下代码编译失败: def f[A,B] = implicitly[Eit
我刚开始在使用 parcel.js 构建静态 Assets 时遇到此错误。它在本地工作,但我在 Heroku 上的构建出错,我不确定它是否相关。 最佳答案 得到同样的问题。通过将 core-js 安装
当我生成 Telerik Report 时,只有 Export PDF 可用。即使我将 docx 和 xlsx 的配置设置为 true。这是我在网络配置中的配置。
我的 iTunesConnect 应用程序显示 Apple Pay 选项。我正在使用布伦特里。 即使我们没有在应用程序中使用 Apple Pay 功能。 有人可以帮我解决如何在我的 itunesCon
我正在 Raspbian 中从命令行运行以下查询: mysql -u $NAME -p $PASS Tweets -e "SELECT count(*) FROM raw_tweets;" 它输出以下
我正在尝试使用 ffmpeg(在 linux 下)为视频添加一个小标题。所以,我使用: ffmpeg -i hk.avi -r 30000/1001 -metadata title="SOF" hk_
我正在尝试使用 ffmpeg 使用 ffserver 流式传输视频。您将在 ffserver1.conf 文件下方找到 ffmpeg 命令的日志输出。 其中一个错误引用了预设,每次我尝试使用预设时,我
我正在尝试对 Option 使用 fold 或 map 操作而不是 match。 我有一个选项 val ao: Option[String] = xxxx 和一个函数 f: (String => Fu
Dockerfile documentation表示有可能通过 --platform FROM 中的选项像这样的指令: FROM [--platform=] [AS ] 在我的 dockerfile
我不确定“属性(property)”或“选项”是否是正确的术语,但这是我需要弄清楚的。 鉴于以下情况: ' $.fileup({ url: '/file/upload',
我正在尝试使用 jQuery 检查是否选择了值 = 1 的选择选项,然后将类添加到某些元素。但有些东西不起作用。可以请人看一下代码吗? 我的代码: Reservation
我对 VIM 中的这些感到困惑。有些事情需要设置,而另一些则让。 而且,我如何检查某个选项。我知道这是一个选项,因为我使用 set 来更改它。 例如,如何检查当前文件类型选项是否为 java? 最佳答
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 8 年前。 Improve this ques
我在看《Professional F# 2.0》一书作者展示如下代码 let a string : option = None if a.IsNone then System.Console.
我习惯使用方法顶部的 java 样板检查输入参数: public static Boolean filesExist(String file1, String file2, String file3
假设我有一串 "Insert Post -title Some PostTitle -category 2 -date-posted 2013-02:02 10:10:10" 我一直在尝试做的是将这个
从 1.3.70 EAP 开始,在 org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions 这是 var useIR: kotlin.Boolean 哪个激活
我无法获取订购捆绑商品的所有子产品及其选项。这可能吗? 最佳答案 以下是您如何找出哪些产品应与所有其他项目一起附加到列表中的捆绑产品中的方法: foreach ($order->getAllItems
这个问题不太可能对任何 future 的访客有帮助;它只与一个较小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于全世界的互联网受众。如需帮助使此问题更广泛适用,visit the
我是一名优秀的程序员,十分优秀!