大佬教程收集整理的这篇文章主要介绍了android – 当我的应用程序失去焦点并重新获得焦点时,UI会更新.奇怪的问题,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我的代码:
注意: – 当我的应用程序失去焦点并重新获得焦点时,UI会更新.奇怪的问题
public class LocateGeopoint extends AsyncTask<LatLng,String,List<Address>> { Geocoder geocoder; private TextView tv; public LocateGeopoint(View v) { this.geocoder = new Geocoder(v.getContext()); this.tv = (TextView) v.findViewById(R.id.textView1); } @Override protected void onPostExecute(List<Address> addresses) { super.onPostExecute(addresses); if(addresses!=null){ String city = addresses.get(0).getAddressLine(0); String country = addresses.get(0).getAddressLine(1); System.out.println(city+" "+country); tv.setText(city); } } @Override protected List<Address> doInBACkground(LatLng... params) { // TODO Auto-generated method stub double lattitude = params[0].latitude; double longitude = params[0].longitude; List<Address> addresses = null; if (lattitude != 0 || longitude != 0) { try { addresses = geocoder.getFromLOCATIOn(lattitude,longitude,1); } catch (IOException E) { e.printStackTrace(); } } return addresses; } }
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://scheR_539_11845@as.android.com/apk/res/android" android:id="@+id/parent_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /> <FrameLayout android:id="@+id/view_container" android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:focusable="true" android:text="Loading Address.." /> </FrameLayout>
googleMap.seTinfoWindowAdapter(new InfoWindowAdapter() { @Override public View geTinfoWindow(Marker arg0) { return null; } @SuppressWarnings("unchecked") @Override public View geTinfoContents(Marker marker) { LayoutInflater inflater = (LayoutInflater) MapsDemo.this .getSystemservice(Context.LAYOUT_INFLATER_serviCE); View v = inflater.inflate(R.layout.custom_info,@R_616_6633@ new LocateGeopoint(v).execute(marker.getPosition()); return v; } });
当我调试应用程序时,它会更新但通常不会.
googleMap.seTinfoWindowAdapter(new InfoWindowAdapter() { LruCache<Marker,View> cache = new LruCache<Marker,View>(8); // added // no change to geTinfoWindow() @SuppressWarnings("unchecked") @Override public View geTinfoContents(Marker marker) { View v = cache.get(marker); if (v == null) { LayoutInflater inflater = (LayoutInflater) MapsDemo.this .getSystemservice(Context.LAYOUT_INFLATER_serviCE); v = inflater.inflate(R.layout.custom_info,@R_616_6633@ new LocateGeopoint(v,marker).execute(marker.getPosition()); cache.put(marker,v); } return v; } });
调整LocateGeopoint类中的代码,添加对Marker的引用并在更新TextView后调用showInfoWindow().
public class LocateGeopoint extends AsyncTask<LatLng,List<Address>> { // : Marker marker; // added public LocateGeopoint(View v,Marker marker) { // : this.marker = marker; // added } @Override protected void onPostExecute(List<Address> addresses) { super.onPostExecute(addresses); if(addresses!=null){ // : tv.setText(city); marker.showInfoWindow(); // added } } // no change to doInBACkground() }
注意:这个答案实际上只是一个快速而肮脏的实现(我还没有真正测试过,但我认为它应该可行)基于MaciejGórski关于这个问题的答案,请阅读该答案中的参考帖子以获取更多详细信息: )
以上是大佬教程为你收集整理的android – 当我的应用程序失去焦点并重新获得焦点时,UI会更新.奇怪的问题全部内容,希望文章能够帮你解决android – 当我的应用程序失去焦点并重新获得焦点时,UI会更新.奇怪的问题所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。