【发布时间】:2014-10-30 10:30:57
【问题描述】:
我正在处理地图我已经创建了一个地图屏幕并使用marker.markers 是在Info Window Adapter 的帮助下创建的。在信息窗口适配器中,我有文本视图名称、卷号和地址,我想在名称、地址上设置点击事件。你能告诉我这是怎么做到的吗?
package com.ihealthhome.ui;
import java.util.Hashtable;
import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.maps.GoogleMap.InfoWindowAdapter;
import com.google.android.gms.maps.model.Marker;
import com.ihealthhome.R;
import com.ihealthhome.dataparser.ClientsDetailDAO;
import com.ihealthhome.listeners.ClientDetailNavigationListener;
/**
* @author DotZoo Inc, created on 02-Jan-2014
*/
public class CustomInfoWindowAdapter implements InfoWindowAdapter {
private View view;
Context ctx;
private Hashtable<String, ClientsDetailDAO> renderMarker;
public CustomInfoWindowAdapter(Context ctx,
Hashtable<String, ClientsDetailDAO> markers) {
this.ctx = ctx;
this.renderMarker = markers;
view = ((Activity) ctx).getLayoutInflater().inflate(
R.layout.custom_infowindow, null);
}
@Override
public View getInfoContents(Marker marker) {
return null;
}
@Override
public View getInfoWindow(Marker marker) {
final ImageView profileImage = (ImageView) view
.findViewById(R.id.userProfile);
TextView clientName = ((TextView) view.findViewById(R.id.clientName));
final TextView clientCellPhone = ((TextView) view
.findViewById(R.id.clientCellPhone));
final TextView clientHomePhone = ((TextView) view
.findViewById(R.id.clientHomePhone));
final TextView clientWorkPhone = ((TextView) view
.findViewById(R.id.clientWorkPhone));
final TextView clientDashboard = ((TextView) view
.findViewById(R.id.clientDashboard));
final ClientsDetailDAO info = renderMarker.get(marker.getId());
String firstName = info.getFirstName();
String lastname = info.getLastName();
if (!TextUtils.isEmpty(firstName) && !TextUtils.isEmpty(lastname)) {
clientName.setText(new StringBuilder(firstName).append(" ").append(
lastname));
}
String cellPhone = info.getCellPhone();
if (cellPhone != null && !TextUtils.isEmpty(cellPhone)) {
clientCellPhone.setText(cellPhone);
}
String homePhone = info.getHomePhone();
if (homePhone != null && !TextUtils.isEmpty(homePhone)) {
clientHomePhone.setText(homePhone);
}
String workPhone = info.getWorkPhone();
if (workPhone != null && !TextUtils.isEmpty(workPhone)) {
clientWorkPhone.setText(workPhone);
}
clientName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(ctx, "on click", Toast.LENGTH_LONG).show();
mClientDetailListener.gotoClientDetail(info.getClientID(),
info.getFirstName());
}
});
return view;
}
ClientDetailNavigationListener mClientDetailListener;
public void setNavigateToClientDetailListener(
ClientDetailNavigationListener mClientDetailListener) {
this.mClientDetailListener = mClientDetailListener;
}
}
【问题讨论】:
-
尝试将每个视图点击监听器实现为clientName。
-
你能解释一下吗?
-
点击命名等时你想做什么?
-
我想在 clientName 上打开 ClientDetailActivity 点击并点击 profileImage 我想打开另一个活动。
-
尝试使用 Intent intent = new Intent(ctx,ClientDetailActivity.class); ctx.startActivity(intent)
标签: android map google-maps-markers