gpt4 book ai didi

android - 如何通过将值传递给 AlertDialog 的 Intent 来转到下一个 Activity?

转载 作者:行者123 更新时间:2023-11-29 02:11:11 25 4
gpt4 key购买 nike

我想回到 Place.class 显示一个地方的完整信息..现在我可以回到 Place Activity 但信息只显示titleaddress.. 我认为这可能发生在onTab 方法中。它只有 2 件事被用于 Intent ......

intent.putExtra(Constants.COL_TITLE, oi.getTitle());
intent.putExtra(Constants.COL_ADDRESS, oi.getSnippet());

如果我想放入其他字段,即 content phone 等。如何将数据库中的数据放入此 Intent ?

intent.putExtra(Constants.COL_CON, ..........);

谢谢你的帮助

我这里有3个类(class)

xxx.class

public class xxx extends MapActivity {

MapView mapView;
MapController mapController;
private static MyDB mDbHelper;
private Cursor c;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.aboutcm);

mDbHelper = new MyDB(this);
mDbHelper.createDatabase();
mDbHelper.open();
c = mDbHelper.getAttraction();

mapView = (MapView) findViewById(R.id.mapview);
mapController = mapView.getController();
Drawable drawable = this.getResources().getDrawable(R.drawable.map_pin_3);
List<Overlay> mapOverlays = mapView.getOverlays();
PlaceItemizedOverlay itemizedoverlay = new PlaceItemizedOverlay(drawable, this);


mapController.setZoom(13);
mapView.setBuiltInZoomControls(true);


c.moveToFirst();
do {

String title = c.getString(c
.getColumnIndex(Constants.COL_TITLE));
String address = c.getString(c
.getColumnIndex(Constants.COL_ADDRESS));
String content = c.getString(c
.getColumnIndex(Constants.COL_CONTENT));
int latitude = (int) (c.getDouble(c
.getColumnIndex(Constants.COL_LA)) * 1E6);
int longitude = (int) (c.getDouble(c
.getColumnIndex(Constants.COL_LONG)) * 1E6);


itemizedoverlay.addOverlay(new OverlayItem(new GeoPoint(latitude, longitude), title,
address));
mapOverlays.add(itemizedoverlay);

} while (c.moveToNext());
mDbHelper.close();

}

@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}

}

PlaceItemizedOverlay.class

public class PlaceItemizedOverlay extends ItemizedOverlay<OverlayItem> {

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

public PlaceItemizedOverlay(Drawable defaultMarker, Context context)
{
super(boundCenterBottom(defaultMarker));
mContext = context;
}
public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
populate();
}

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

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


@Override
protected boolean onTap(int index) {

final OverlayItem oi = mOverlays.get(index);
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setTitle(oi.getTitle());
dialog.setMessage(oi.getSnippet());
dialog.setNegativeButton("Back", null);
dialog.setPositiveButton("See More Detail", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent intent = new Intent(mContext, Place.class);
intent.putExtra(Constants.COL_TITLE, oi.getTitle());
intent.putExtra(Constants.COL_ADDRESS, oi.getSnippet());
mContext.startActivity(intent);
}});
dialog.show();
return true;

}


}

最佳答案

假设您要将字符串“123456789”从 xxx Activity 传递到 Place.class。然后你会使用 intent.putExtra("content", "123456789") 然后在 Place.class intent.getStringExtra("content") 会返回 "123456789"

Could i declare.... Intent i = new Intent(??????, Place.class); } And what should i put into ??????

您可以做三件事中的一件。首先,我的首选方法是在类主体中声明:

Context context;

然后在onCreate(...)声明:

context = this;

然后你可以这样做:

Intent i = new Intent(context, Place.class);

其次,您可以声明:

Intent i = new Intent(getApplicationContext(), Place.class);

第三,在你的类(class)主体中你可以声明:

Intent i;

然后在 onCreate(...) 中:

i = new Intent(this, Place.class);

使用第三种方法,您就可以在 alertDialog 中使用 startActivity(i)

关于android - 如何通过将值传递给 AlertDialog 的 Intent 来转到下一个 Activity?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7297309/

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