【发布时间】:2017-06-30 07:45:24
【问题描述】:
我在选项卡活动中的地图片段上有按钮,如图所示,但我不知道在哪里实现此按钮的 onClickListener 和其他地图功能 onLocationChanged ,onConnectionSuspened 等请帮忙!
已编辑 添加代码
MapsActivity.Java
public class MapsActivity extends ActionBarActivity implements
AsyncResponse, View.OnClickListener,
OnMapReadyCallback, GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener,
LocationListener {
protected void onCreate(Bundle savedInstanceState) {
Log.i("okkk", " ho jamaaloooo ");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
Intent intent = getIntent();
newString = intent.getLongExtra("user_id", newString);
btn_rest = (Button) findViewById(R.id.btn_rest);
btn_rest.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// getPars
Log.i("okk", "Click ");
HashMap postData = new HashMap();
PostResponseAsyncTask task = new PostResponseAsyncTask(this, postData);
task.execute("http://ashna.netau.net/A_location.php");
}
TabACtivity.java 从这里调用地图片段
public Fragment getItem(int position) {
Log.i("okkk", "Position: " + position);
try {
switch (position) {
case 0: {
return PlaceholderFragment.newInstance(position + 1);
}
case 1: {
Deals deals = new Deals();
return deals;
}
}
}
catch ( Exception e)
{
Log.i("okkk", "Exception 1 : " + e);
}
return PlaceholderFragment.newInstance(position + 1);
}
MapActivity.xml
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
tools:context=".MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment"
tools:layout="@layout/abc_action_menu_layout"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nearby Resturants"
android:id="@+id/btn_rest"
android:layout_gravity="bottom" />
【问题讨论】:
-
哪个按钮?你是说右上角带有消息图标的浮动 Actin 按钮吗?
-
顶部没有按钮(附近的餐厅)@tahsinRupam
-
你可以在oncreate中实现。
-
它不工作:| @AAA 它只显示按钮
-
@android 它应该可以工作。如果没有,请显示代码
标签: android google-maps button android-activity fragment