gpt4 book ai didi

java - Android onTap Intent 数组

转载 作者:行者123 更新时间:2023-12-01 15:28:34 27 4
gpt4 key购买 nike

在我的 MapActivity 上,当您点击 ItemizedOverlay 时,它会显示标题TextView 中的 fragment/消息,每次单击或点击另一个 ItemizedOverlay 时都会发生变化

我创建了一个带有手机图像的 ImageButton,我正在尝试调用它的数组 Intent 所以基本上,当用户点击 Overlay1,然后决定点击电话图像按钮时, Intent 中存储的号码将更改为 Overlay1 的号码,因此他们可以调用 Overlay 1如果他们点击 Overlay 2,那么数字会相应改变等等

我的代码如下:

List<Overlay> mapOverlays;
List<Intent> mapIntents;
NewItemizedOverlay itemizedOverlay;
Intent intentCall;

GeoPoint point = new GeoPoint((int)(51.555890943494276*1E6), (int)(-0.39989858865737915*1E6));
OverlayItem overlayitem = new OverlayItem(point, "Greenwood Veterinary" , "57 Station Approach, South Ruislip, Ruislip, Middlesex, HA4 6SL, 020 8845 8144");
itemizedOverlay.addOverlay(overlayitem);
Intent vet1 = new Intent(android.content.Intent.ACTION_DIAL,Uri.parse("tel:020 8845 8144")); // i created this in a similar fashion to the itemizedOverlay
intentCall.?(vet1); // i wanted to try and do the same thing with the addOverlay but i cant seem to find the correct method of doing this

GeoPoint point2 = new GeoPoint((int)(51.598707*1E6), (int)(-0.393416*1E6));
OverlayItem overlayitem2 = new OverlayItem(point2, "MediVet Pinner" , "2A Pinner Green, Pinner, Middlesex, HA5 2AA, 020 8866 0727");
itemizedOverlay.addOverlay(overlayitem2);
Intent vet2 = new Intent(android.content.Intent.ACTION_DIAL,Uri.parse("tel:020 8866 0727"));

逐项叠加:

private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
private ArrayList<Intent> cIntents = new ArrayList<Intent>();
Context mContext;

public NewItemizedOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}

public NewItemizedOverlay(Drawable defaultMarker, Context context)
{
super(boundCenterBottom(defaultMarker));
mContext = context;
}

public void addOverlay(OverlayItem overlay)
{
mOverlays.add(overlay);
populate();
}

public void addOverlay(OverlayItem overlay, Intent intent)
{
mOverlays.add(overlay);
cIntents.add(intent);
populate();
}

@Override
protected OverlayItem createItem(int i) {
// TODO Auto-generated method stub
return mOverlays.get(i);
}

protected Intent createCall(int c)
{
return cIntents.get(c);
}

@Override
public int size() {
// TODO Auto-generated method stub
return mOverlays.size();
}

public int callsize()
{
return cIntents.size();
}

@Override
protected boolean onTap(int index) {
OverlayItem item = mOverlays.get(index);
Intent callItem = cIntents.get(index);


AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setIcon(android.R.drawable.ic_dialog_info);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub

}
});
dialog.setNeutralButton("Call", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
VetNumber. //Not sure how to exactly call the Intent
}
});
dialog.show();
return true;
}

}

如果有人能帮忙,我将不胜感激

谢谢

最佳答案

也许对你来说已经太晚了,但如果你知道自己所处的环境,你就可以开始一个新的 Intent 。如果您使用 MapActivity 和 ItemizedOverlay,则可以在 LocalizacionItemizedOverlay 中获取上下文。

Context mContext;
public LocalizacionItemizedOverlay(Drawable defaultMarker, Context context) {
super(boundCenterBottom(defaultMarker));
mContext=context;
}

然后在onTap函数中你可以写一些类似:

dialog.setPositiveButton("Ver", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent nextScreen = new Intent(mContext, YourActivity.class); //define the intent
nextScreen.putExtra("definicionURL",definicion.url); //pass variables
mContext.startActivity(nextScreen); //launch the intent
}
});

这是我在 stackoverflow.com 上发表的第一篇文章,我想对所有在这里发布解决方案的人说几句话:非常感谢。

关于java - Android onTap Intent 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9864031/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com