- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
背景
我有一个包含三个 fragment 的 viewpager。所有 fragment 都是同一 fragment 类的新实例,根据应用程序设置使用自定义 map 布局或 ListView 。但问题仅在 map 模式下。
问题
每次我在 map 模式下启动 viewpager Activity 时,只有当前 fragment 显示 map 。其他 fragment 是空的。看起来所有 fragment 都使用 map 的唯一实例。当前 fragment 首先得到这张 map 。其他两个 fragment 中的 map 为空。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include
layout="@layout/loading_component"/>
<FrameLayout
android:id="@+id/mapFragmentHole"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_gravity="center_vertical|center_horizontal" />
<Button
android:id="@+id/cur_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/map_compas"
android:layout_alignParentRight="true"/>
<Button
android:id="@+id/go_back"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:textColor="@color/gray_theatre"
android:textSize="21sp"
android:textStyle="bold"
android:background="@drawable/go_to_list_button_bg"
android:text="@string/return_to_list"
android:layout_alignParentRight="true"
android:visibility="gone"/>
</RelativeLayout>
SectionsPagerAdapter
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public int getItemPosition(Object object) {
return POSITION_NONE;
}
@Override
public Fragment getItem(int i) {
if (i == 0) {
return CinemaAllFragment.newInstance(modeFavourite);
//return new CinemaFavouriteFragment();
}
if (i == 1) {
return CinemaAllFragment.newInstance(modeOnline);
}
if (i == 2) {
return CinemaAllFragment.newInstance(modeDefault);
}
return null;
}
@Override
public int getCount() {
return 3;
}
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return getString(R.string.frame_cinema_title1);
case 1:
return getString(R.string.frame_cinema_title2);
case 2:
return getString(R.string.frame_cinema_title4);
}
return null;
}
}
我的 fragment
public class CinemaAllFragment extends CinemaFragment implements LocationListener {
private LocationManager locationManager;
private String provider;
private GoogleMap map = null;
private Marker myPosition;
private View balloon;
private Button curLocationBtn;
protected ListView listViewCinemas = null;
protected View view;
private String fragmentMode;
private static String MODE = "mode";
private static String modeFavourite = "modeFavourite";
private static String modeOnline = "modeOnline";
private static String modeDefault = "modeDefault";
private Cinema[] cinemas;
private Long updateTime;
private Long lastUpdate;
private CinemaListArrayAdapter adapter = null;
private static String FRAGMENT = "position";
private ArrayList<Marker> Markers;
private long nowTime;
// Handler to update UI timeFr, progress bar etc,.
private Handler mHandler = new Handler();
private Runnable onEveryFiveMinutes;
private SupportMapFragment supportMapFragment = null;
public static CinemaAllFragment newInstance(String someString)
{
CinemaAllFragment myFragment = new CinemaAllFragment();
Bundle args = new Bundle();
args.putString(MODE, someString);
myFragment.setArguments(args);
return myFragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
super.onCreateView(inflater, container, savedInstanceState);
if(getArguments()!=null)
fragmentMode = getArguments().getString(MODE, null);
if (Settings.getCinemaTypeView() == Settings.CinemaTypeView.Map)
{
mLog.d("OnCreate: map "+fragmentMode);
view = inflater.inflate(R.layout.cinema_map, container, false);
GoogleMapOptions gmo = (new GoogleMapOptions()).zoomControlsEnabled(true).rotateGesturesEnabled(false);
if(supportMapFragment == null)
supportMapFragment = SupportMapFragment.newInstance(gmo);
FragmentTransaction fragmentTransaction = getActivity().getSupportFragmentManager().beginTransaction();
fragmentTransaction.add(R.id.mapFragmentHole, supportMapFragment);
fragmentTransaction.commit();
balloon = inflater.inflate(R.layout.cinema_list_item, null);
ImageView delimiter = (ImageView) balloon.findViewById(R.id.delimiter);
delimiter.setVisibility(View.GONE);
}
else if (Settings.getCinemaTypeView() == Settings.CinemaTypeView.Listing)
{
view = inflater.inflate(R.layout.cinema_list, container, false);
}
return view;
}
@Override
public void onResume() {
super.onResume();
if (Settings.getCinemaTypeView() == Settings.CinemaTypeView.Map)
{
setUpMapIfNeeded();
}
onUpdate();
}
@Override
public void onDestroyView() {
super.onDestroyView();
if (Settings.getCinemaTypeView() == Settings.CinemaTypeView.Map)
{
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.remove(supportMapFragment);
ft.commit();
}
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
}
class CustomInfoAdapter implements GoogleMap.InfoWindowAdapter {
@Override
public View getInfoContents(Marker marker) {
displayView(marker);
if(!marker.getTitle().equals("Я"))
{
return balloon;
}
else return null;
}
@Override
public View getInfoWindow(Marker marker) {
return null;
}
}
public void displayView(Marker marker) {
TextView cinema_title = (TextView) balloon.findViewById(R.id.cinema_title);
Cinema cinema = MoviesDbAdapter.getCinemaById(marker.getTitle());
if (cinema != null)
{
cinema_title.setText(cinema.title);
}
}
public void checkGPSEnabled()
{
// Get the location manager
locationManager = (LocationManager) view.getContext().getApplicationContext().getSystemService(view.getContext().getApplicationContext().LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER/*provider*/, 0, 0, this);
boolean enabled = locationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER);
// Check if enabled and if not send user to the GSP settings
// Better solution would be to display a dialog and suggesting to
// go to the settings
if (!enabled) {
new AlertDialog.Builder(view.getContext().getApplicationContext())
.setMessage(view.getContext().getApplicationContext().getResources().getString(R.string.message_gps_off))
.setPositiveButton(view.getContext().getApplicationContext().getResources().getString(R.string.dialog_gps_enable), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Intent intent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivityForResult(intent, 5);
}
})
.setNegativeButton(view.getContext().getApplicationContext().getResources().getString(R.string.dialog_gps_cancel), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
})
.show();
}
}
/* Request updates at startup */
@Override
public void onLocationChanged(Location location) {
int lat = (int) (location.getLatitude());
int lng = (int) (location.getLongitude());
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
//getLocation();
}
@Override
public void onProviderDisabled(String provider) {
}
/**
* Sets up the map if it is possible to do so (i.e., the Google Play services APK is correctly
* installed) and the map has not already been instantiated.. This will ensure that we only ever
* call {@link #setUpMap()} once when {@link #map} is not null.
* <p>
* If it isn't installed {@link SupportMapFragment} (and
* {@link com.google.android.gms.maps.MapView
* MapView}) will show a prompt for the user to install/update the Google Play services APK on
* their device.
* <p>
* A user can return to this Activity after following the prompt and correctly
* installing/updating/enabling the Google Play services. Since the Activity may not have been
* completely destroyed during this process (it is likely that it would only be stopped or
* paused), {@link #onCreate(Bundle)} may not be called again so we should call this method in
* {@link #onResume()} to guarantee that it will be called.
*/
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (map == null) {
//map = (MapView) getActivity().findViewById(R.id.map);
// Try to obtain the map from the SupportMapFragment.
map = supportMapFragment.getMap();
//map.setInfoWindowAdapter(new CustomInfoAdapter());
// Check if we were successful in obtaining the map.
if (map != null) {
setUpMap();
}
}
}
private void getLocation()
{
mLog.d("Touch: ");
checkGPSEnabled();
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER/*provider*/);
// Initialize the location fields
if (location != null) {
System.out.println("Provider " + provider + " has been selected.");
CameraPosition cp = new CameraPosition.Builder()
.target(new LatLng(location.getLatitude(),location.getLongitude()))
.zoom(12)
.build();
map.animateCamera(CameraUpdateFactory.newCameraPosition(cp));
if (myPosition != null)
{
myPosition.remove();
}
myPosition = map.addMarker(new MarkerOptions()
.position(new LatLng(location.getLatitude(),location.getLongitude()))
.title("Я")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.map_marker_user)));
}
}
/**
* This is where we can add markers or lines, add listeners or move the camera. In this case, we
* just add a marker near Africa.
* <p>
* This should only be called once and when we are sure that {@link #map} is not null.
*/
private void setUpMap() {
map.setMyLocationEnabled(true);
//map.getUiSettings().setMyLocationButtonEnabled(true);
//map.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
}
public void onUpdate() {
if(fragmentMode != null)
{
if(fragmentMode.equals(modeDefault)){
cinemas = MoviesDbAdapter.getCinemaAll();
}
else if (fragmentMode.equals(modeFavourite))
{
cinemas = MoviesDbAdapter.getCinemaFavorites();
}
else if (fragmentMode.equals(modeOnline))
{
cinemas = MoviesDbAdapter.getCinemaOnline();
}
mLog.d("OnCreate: "+fragmentMode);
}
else
{
cinemas = MoviesDbAdapter.getCinemaAll();
}
adapter = new CinemaListArrayAdapter(getActivity(), R.layout.movies_list_item, cinemas);
mLog.d("OnCreate: onUpdate "+fragmentMode);
if(cinemas.length == 0)
{
// Load schedules
//Utils.updateLoadingStatus(view, getString(R.string.message_loading_cinemas));
}
if (Settings.getCinemaTypeView() == Settings.CinemaTypeView.Map)
{
try
{
checkGPSEnabled();
} catch (Exception e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
//ApiDownloader downloader = new ApiDownloader(getActivity().getApplicationContext());
//downloader.registerAPI(getActivity().getApplicationContext());
if (Markers != null)
{
for (Marker marker : Markers)
{
marker.remove();
}
Markers.clear();
}
Markers = new ArrayList<Marker>();
if(map != null)
{
//нарисовать маркеры кинотеатров
for (Cinema cinema : cinemas)
{
//mLog.d("Cinema: " + cinema.getLatitude());
Marker cinemaMarker = map.addMarker(new MarkerOptions()
.position(new LatLng(Double.parseDouble(cinema.getLatitude()),Double.parseDouble(cinema.getLongitude())))
.title(cinema.getId().toString())
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.map_marker_mini)));
Markers.add(cinemaMarker);
}
}
}
else
{
//ApiDownloader downloader = new ApiDownloader(getActivity().getApplicationContext());
//downloader.registerAPI(getActivity().getApplicationContext());
listViewCinemas = (ListView) view.findViewById(R.id.cinemas_list_view);
int index = 0;
View v=null;
if(listViewCinemas != null)
{
mLog.d("OnCreate: list not null "+fragmentMode+" "+cinemas.length);
// save index and top position
index = listViewCinemas.getFirstVisiblePosition();
v = listViewCinemas.getChildAt(0);
int top = (v == null) ? 0 : v.getTop();
listViewCinemas.setAdapter(adapter);
listViewCinemas.setSelectionFromTop(index, top);
PauseOnScrollListener listener = new PauseOnScrollListener(imageLoader, pauseOnScroll, pauseOnFling);
listViewCinemas.setOnScrollListener(listener);
}
}
}
}
最佳答案
解决问题
只需将具有 map 功能的 fragment 分开,而不是在两个新 fragment 中进行映射。新的 map fragment 扩展自 SupportMapFragment 并允许他为 himlesf 制作 View :
public class CinemaMapFragment extends SupportMapFragment implements LocationListener {
...
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
view = super.onCreateView(inflater, container, savedInstanceState);
balloon = inflater.inflate(R.layout.cinema_list_item, null);
return view;
}
然后我以编程方式添加我的自定义功能(只有两个按钮):
@Override
public void onResume() {
super.onResume();
LayoutInflater inflater = (LayoutInflater) getActivity().getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View vi = inflater.inflate(R.layout.location_button, null);
View vi2 = inflater.inflate(R.layout.golist_button, null);
curLocationBtn = (Button) vi.findViewById(R.id.cur_location);
goToList = (Button) vi2.findViewById(R.id.go_back);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
((ViewGroup) view).addView(vi, layoutParams);
LinearLayout.LayoutParams layoutParams2 = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT);
((ViewGroup) view).addView(vi2, layoutParams2);
...
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (map == null) {
//map = (MapView) getActivity().findViewById(R.id.map);
// Try to obtain the map from the SupportMapFragment.
map = getMap();
map.setInfoWindowAdapter(new CustomInfoAdapter());
// Check if we were successful in obtaining the map.
if (map != null) {
setUpMap();
}
}
}
关于android - 只有第一张 map 在 ViewPager 中显示有多个 SupportMapFragment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15519569/
我需要将文本放在 中在一个 Div 中,在另一个 Div 中,在另一个 Div 中。所以这是它的样子: #document Change PIN
奇怪的事情发生了。 我有一个基本的 html 代码。 html,头部, body 。(因为我收到了一些反对票,这里是完整的代码) 这是我的CSS: html { backgroun
我正在尝试将 Assets 中的一组图像加载到 UICollectionview 中存在的 ImageView 中,但每当我运行应用程序时它都会显示错误。而且也没有显示图像。 我在ViewDidLoa
我需要根据带参数的 perl 脚本的输出更改一些环境变量。在 tcsh 中,我可以使用别名命令来评估 perl 脚本的输出。 tcsh: alias setsdk 'eval `/localhome/
我使用 Windows 身份验证创建了一个新的 Blazor(服务器端)应用程序,并使用 IIS Express 运行它。它将显示一条消息“Hello Domain\User!”来自右上方的以下 Ra
这是我的方法 void login(Event event);我想知道 Kotlin 中应该如何 最佳答案 在 Kotlin 中通配符运算符是 * 。它指示编译器它是未知的,但一旦知道,就不会有其他类
看下面的代码 for story in book if story.title.length < 140 - var story
我正在尝试用 C 语言学习字符串处理。我写了一个程序,它存储了一些音乐轨道,并帮助用户检查他/她想到的歌曲是否存在于存储的轨道中。这是通过要求用户输入一串字符来完成的。然后程序使用 strstr()
我正在学习 sscanf 并遇到如下格式字符串: sscanf("%[^:]:%[^*=]%*[*=]%n",a,b,&c); 我理解 %[^:] 部分意味着扫描直到遇到 ':' 并将其分配给 a。:
def char_check(x,y): if (str(x) in y or x.find(y) > -1) or (str(y) in x or y.find(x) > -1):
我有一种情况,我想将文本文件中的现有行包含到一个新 block 中。 line 1 line 2 line in block line 3 line 4 应该变成 line 1 line 2 line
我有一个新项目,我正在尝试设置 Django 调试工具栏。首先,我尝试了快速设置,它只涉及将 'debug_toolbar' 添加到我的已安装应用程序列表中。有了这个,当我转到我的根 URL 时,调试
在 Matlab 中,如果我有一个函数 f,例如签名是 f(a,b,c),我可以创建一个只有一个变量 b 的函数,它将使用固定的 a=a1 和 c=c1 调用 f: g = @(b) f(a1, b,
我不明白为什么 ForEach 中的元素之间有多余的垂直间距在 VStack 里面在 ScrollView 里面使用 GeometryReader 时渲染自定义水平分隔线。 Scrol
我想知道,是否有关于何时使用 session 和 cookie 的指南或最佳实践? 什么应该和什么不应该存储在其中?谢谢! 最佳答案 这些文档很好地了解了 session cookie 的安全问题以及
我在 scipy/numpy 中有一个 Nx3 矩阵,我想用它制作一个 3 维条形图,其中 X 轴和 Y 轴由矩阵的第一列和第二列的值、高度确定每个条形的 是矩阵中的第三列,条形的数量由 N 确定。
假设我用两种不同的方式初始化信号量 sem_init(&randomsem,0,1) sem_init(&randomsem,0,0) 现在, sem_wait(&randomsem) 在这两种情况下
我怀疑该值如何存储在“WORD”中,因为 PStr 包含实际输出。? 既然Pstr中存储的是小写到大写的字母,那么在printf中如何将其给出为“WORD”。有人可以吗?解释一下? #include
我有一个 3x3 数组: var my_array = [[0,1,2], [3,4,5], [6,7,8]]; 并想获得它的第一个 2
我意识到您可以使用如下方式轻松检查焦点: var hasFocus = true; $(window).blur(function(){ hasFocus = false; }); $(win
我是一名优秀的程序员,十分优秀!