- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
就像标题所说,我想制作一个包含两个部分的ViewPager
:
1-一个Listview
(PHP/MySQL/JSON要去的地方的名称)
2- 以及带有 Markers
的 GoogleMap
,具体取决于您在第 1 点中选择的内容
所以,我有一个 ListView 的代码和带有位置按钮的 GoogleMap 的第二个代码。我想将它们合并到 ViewPager 中,但我不知道如何实现这一点。请参阅下面我的代码:
Google 类(class):
package com.bla;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import android.app.Activity;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
//extends FragmentActivity
public class google extends FragmentActivity implements LocationListener {
Button btnShowLocation;
// GPSTracker class
GPSTracker gps;
// GoogleMap googleMap;
LatLng myPosition;
private SupportMapFragment map;
private GoogleMap mMapView;
// add all necessary things
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_google);
// if Google Play Services are available then
// Getting reference to the SupportMapFragment of activity_main.xml
// SIRVE ... SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
/* fm = SupportMapFragment.newInstance();
FragmentTransaction fragmentTransaction =
getChildFragmentManager().beginTransaction();
fragmentTransaction.add(R.id.map, fm);
fragmentTransaction.commit(); */
// SupportMapFragment fm = (SupportMapFragment) getFragmentManager().findFragmentById(R.id.map);
FragmentManager fm = getSupportFragmentManager();
map = (SupportMapFragment) fm.findFragmentById(R.id.map);
if (map == null) {
map = SupportMapFragment.newInstance();
fm.beginTransaction().replace(R.id.map, map).commit();
}
// GoogleMap = mMapFragment.getMap();
// Getting GoogleMap object from the fragment
// mMapView = fm.getMap();
mMapView = map.getMap();
// Enabling MyLocation Layer of Google Map
mMapView.setMyLocationEnabled(true);
// Getting LocationManager object from System Service LOCATION_SERVICE
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
// Creating a criteria object to retrieve provider
Criteria criteria = new Criteria();
// Getting the name of the best provider
String provider = locationManager.getBestProvider(criteria, true);
// Getting Current Location
Location location = locationManager.getLastKnownLocation(provider);
if(location!=null){
// Getting latitude of the current location
double latitude = location.getLatitude();
// Getting longitude of the current location
double longitude = location.getLongitude();
// Creating a LatLng object for the current location
LatLng latLng = new LatLng(latitude, longitude);
myPosition = new LatLng(latitude, longitude);
mMapView.addMarker(new MarkerOptions().position(myPosition).title("Start"));
}
}
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
}
ListView 类:
package com.example.mysqltest;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import android.app.Activity;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.view.View;
import android.widget.Button;
import com.example.mysqltest.R;
import com.viewpagerindicator.TabPageIndicator;
public class titlepager extends Activity {
// GoogleMap googleMap;
LatLng myPosition;
private SupportMapFragment map;
private GoogleMap mMapView;
//these are the titles that will appear on the "tabs"
final String[] page_titles = new String[]{"Home", "Me"};
//this will go the description TextView
final String[] desc = new String[]{
"Aqui ira el listview ",
"Aqui iraaa el mapa :D ",
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.title);
//Instantiating the adapter
GiloAdapter mAdapter = new GiloAdapter(this);
//instantiate the Views
ViewPager mPager = (ViewPager)findViewById(R.id.pager);
mPager.setAdapter(mAdapter);
TabPageIndicator mIndicator = (TabPageIndicator)findViewById(R.id.indicator);
mIndicator.setViewPager(mPager);
private class GiloAdapter extends PagerAdapter{
Context context;
public GiloAdapter(Context c){
this.context = c;
}
//This is the number of pages -- 5
@Override
public int getCount() {
// TODO Auto-generated method stub
return page_titles.length;
}
@Override
public boolean isViewFromObject(View v, Object o) {
// TODO Auto-generated method stub
return v.equals(o);
}
//This is the title of the page that will apppear on the "tab"
public CharSequence getPageTitle(int position) {
return page_titles[position];
}
//This is where all the magic happen
public Object instantiateItem(View pager, int position) {
final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.page, null, false);
View v2 = inflater.inflate(R.layout.page2, null, false);
TextView title = (TextView)v.findViewById(R.id.tvTitle);
TextView description = (TextView) v.findViewById(R.id.tvdesc);
title.setText(page_titles[position]);
description.setText(desc[position]);
//This is very important
( (ViewPager) pager ).addView( v, 0 );
( (ViewPager) pager ).addView( v2, 1 );
return v;
}
@Override
public void destroyItem(View pager, int position, Object view) {
((ViewPager) pager).removeView((View) view);
}
@Override
public void finishUpdate(View view) {
}
@Override
public void restoreState(Parcelable p, ClassLoader c) {
}
@Override
public Parcelable saveState() {
return null;
}
@Override
public void startUpdate(View view) {
}
}
}
是否有任何选项可以合并这些类?为每个页面进行切换以及对哪种布局进行收费?我是 Android 新手,你能帮我知道怎么做吗?
最佳答案
我在下面的 viewPager 中有三个不同的 fragment 。下面的示例是一个dialogFragment,但这没有什么区别,它可以是一个 Activity ,也可以是一个 fragment 。
public class FragmentPagerSupport extends DialogFragment implements
OnPageChangeListener {
static int NUM_ITEMS = 3;
public interface FragmentPageRefresh {
void onRefresh();
}
MyAdapter mAdapter;
ViewPager mPager;
static FragmentPagerSupport newInstance(int startingPage) {
FragmentPagerSupport f = new FragmentPagerSupport();
// Supply num input as an argument.
Bundle args = new Bundle();
args.putInt("startingPage", startingPage);
f.setArguments(args);
return f;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
int startingPage = 0;
Bundle b = getArguments();
if (b != null) {
startingPage = b.getInt("startingPage");
}
View view = inflater.inflate(R.layout.fragment_pager, container);
mAdapter = new MyAdapter(this.getChildFragmentManager());
mPager = (ViewPager) view.findViewById(R.id.pager);
mPager.setAdapter(mAdapter);
mPager.setCurrentItem(startingPage);
mPager.setOnPageChangeListener(this);
getDialog().setTitle("Best Rides Settings");
return view;
}
public static class MyAdapter extends FragmentStatePagerAdapter {
// private Map<Integer, Fragment> mPageReferenceMap = new
// HashMap<Integer, Fragment>();
public MyAdapter(FragmentManager fm) {
super(fm);
}
@Override
public int getCount() {
return NUM_ITEMS;
}
@Override
public Fragment getItem(int position) {
Fragment ret = null;
switch (position) {
case 0:
ret = SettingMap.newInstance(position);
break;
case 1:
ret = SettingFollow.newInstance(position);
break;
case 2:
ret = SettingRecord.newInstance(position);
break;
}
// mPageReferenceMap.remove(position);
// mPageReferenceMap.put(position, ret);
return ret;
}
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return "Map Type";
case 1:
return "Follow";
case 2:
return "Tracker";
default:
return "unused";
}
}
以下是在 fragment 中执行“.newInstance”的方法。
public class SettingFollow extends Fragment implements
OnCheckedChangeListener,
android.widget.CompoundButton.OnCheckedChangeListener,
OnSeekBarChangeListener {
public static Fragment newInstance(int position) {
SettingFollow f = new SettingFollow();
// Supply num input as an argument.
Bundle args = new Bundle();
args.putInt("num", position);
f.setArguments(args);
return f;
}
...
}
简单的布局
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2010 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- Top-level content view for the simple fragment sample. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/default_screen_bg"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1" >
<android.support.v4.view.PagerTitleStrip
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top" />
</android.support.v4.view.ViewPager>
</LinearLayout>
像这样点燃这头野兽。
FragmentManager fm = getSupportFragmentManager();
FragmentPagerSupport editSettingsDialog = new FragmentPagerSupport();
// MapSettings editSettingsDialog = new MapSettings();
editSettingsDialog.show(fm, "fragment_edit_name");
关于java - 如何将谷歌地图/代码放入viewpager中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23571548/
这两个包看起来非常相似: http://www.passportjs.org/packages/passport-google-oauth2/ http://www.passportjs.org/pa
我想在我的网站上添加通过 Google 和 Twitter 登录的按钮。我需要只使用应用程序的客户端而不是服务器端来完成此操作。但我没有找到任何 API。对于我发现的所有内容,我需要使用带有 key
我使用此链接通过 google plus 共享我的页面。 https://plus.google.com/share?url=http%3A%2F%2Fexample.com%2Fcompany%2
我正在尝试学习 google API,并且我的经验是使用 Python,因此我尝试使用 google api python 客户端来访问一些 google 服务,但在构建服务对象时遇到错误。 从 ap
在其实际的实时托管平台上构建实时站点的努力中,有没有办法告诉谷歌不要索引该网站?我发现了以下内容: http://support.google.com/webmasters/bin/answer.py
我正在开发一个 iOS 应用程序。当我运行用于 google+ 登录的程序时,在我点击允许访问按钮后,会显示此消息。 You've reached this page because we have
我有一个非常复杂的网站,每个页面包含 11 个 js 文件。 我最近添加了 google +1 按钮,代码如下: 这会正确显示 +1 按钮,直到我单击它。当我单击它时,出现此错误:https://
我正在尝试使用 google API 创建一个 html 文件,以便在 google MAPS 上显示 KML 文件。 这是 HTML 代码: function initMap() {
我是使用 Google Benchmark 的新手,在本地运行代码与在 Quick-Bench.com 上运行代码时,我收到了运行相同基准测试(下方)的不同结果,该基准测试使用 C++ 检索本地时间.
我已按照 Google 网站上的说明通过添加以下元标记在我的 AngularJS 网站上启用 Ajax 抓取: 呈现的内容有一些链接,如: User 1 User 2 User 3 还有一些呈现动态
通过 Google 手册实现 Google AppInvite - link . 启动 Invite Activity 并在 LogCat 中获取下一步: E/AppInviteAgent: Get
那么有人用过 Google 的 Go 吗?我想知道数学性能(例如触发器)与其他具有垃圾收集器的语言(如 Java 或 .NET)相比如何? 有人调查过吗? 最佳答案 理论性能:纯 Go 程序的理论性能
Stackdriver 测试我的网站启动速度慢 我们使用 cloudflare 作为我们的站点 CDN 提供商。我们使用 stackdriver 从外部测试站点可用性,我们将时间检查间隔设置为 1 分
我正在尝试使用 stax.GeneralConv() ( https://jax.readthedocs.io/en/latest/_modules/jax/experimental/stax.htm
我有一个从谷歌金融中提取日内数据的软件。但是,由于昨天 Google 更新了 API,所以软件报错了 Conversion from string HTML HEAD meta http-equiv=
我们在尝试从 Google 获取 oAuth token 时遇到“redirect_uri_mismatch”错误: [client 127.0.0.1:49892] {\n "error" : "
我的网站正在使用 Google reCAPTCHA 控件,但我听说它被阻止了 中国,反正我看到有人报告说将 API 更改为 https://www.recaptcha.net在中国工作? Anyone
背景 WordPress Google Adsense 谷歌自动插入 anchor 定广告 https://pptmon.com 问题 如下图所示,主播广告的容器高度太大了! 如何调整高度? 这是谷歌
我在使用 Google Colab 时遇到问题。当我想制作一个新的 Python3 Notebook 时,由于我登录了我的 Google 帐户,因此无法加载刚刚打开的新页面。 我该怎么办? 感谢您的帮
我正在使用 facebook和 google oauth2使用 passport js 登录, 有了这个流 用户点击登录按钮 重定向到 facebook/google auth 页面(取决于用户选择的
我是一名优秀的程序员,十分优秀!