我有一个通过ntent发送的变量,并发送到两个不同的类,如何? 所以我的 Intent 是这样的:
case 0:
position = new LatLng (-8.447159, 112.651799);
args.putParcelable ("place_position", position);
a = new Intent (getActivity (), MapsMenu.class);
a.putExtra ("lat", args);
a.putExtra ("post", "cave");
a.putExtra ("location", "South Beach Goa China in Malang");
break;
键'post'发送到A类,而键'location'和'lat'发送到B类,我使用actionsherlock的 fragment ,对于变量成功发送到B类,而对于A类没有出现,源代码如下:
public class A extends SherlockListFragment {
ListView list;
List<HashMap<String, String>> aList = new ArrayList<HashMap<String, String>>();
ImageView imDetail;
String pos;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
Intent in = getActivity().getIntent();
pos = (String) in.getStringExtra("post");
return super.onCreateView(inflater, container, savedInstanceState);
}
这是 B 级:
public class B extends SherlockMapFragment {
String title;
private GoogleMap map;
LatLng LAT = null;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = super.onCreateView(inflater, container, savedInstanceState);
map = getMap();
Bundle bundle = getActivity().getIntent().getParcelableExtra("lat");
Intent in = getActivity().getIntent();
title = (String) in.getStringExtra("location");
LAT = bundle.getParcelable("place_position");
LoadMaps(LAT, title);
return root;
}
我错过了什么吗?
最佳答案
您将两个项目放入 Intent 中,分别称为“post”和“location”。但您搜索“pos”和“lokasi”。我认为这就是类(class)找不到您的 Intent 项目的原因。
关于java - 如何在 fragment 的两个不同类中发送 Intent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23937670/