Hallo allerseits Ich habe ein Problem mit dem Senden von Bild-ID mit Absicht von Fragment zu einer anderen Aktivität, ich suchte nach dem Problem Ich sah, dass Absenden ID als Doppel nicht Int irgendeine Idee, wie Bild zu teilen ID zwischen Aktivitäten. Diese Frage ist die gleiche wie mein Problem, aber die Lösung hat nicht für mich funktioniert: How can i get Image Resource ID and send it to other activity in Android?. hier ist mein ProgrammSenden Bild ID von Fragment zu einer anderen Aktivität
public class BestTenPlaces extends Fragment {
public BestTenPlaces() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.list, container, false);
final View detailsView = inflater.inflate(R.layout.details, container, false);
ArrayList<InfoObject> objects = new ArrayList<InfoObject>();
objects.add(new InfoObject("baghdad 1", "gitnge", R.drawable.capture));
objects.add(new InfoObject("string 2", "gitnge", R.drawable.capture));
objects.add(new InfoObject("string 3", "gitnge", R.drawable.capture));
objects.add(new InfoObject("string 4", "gitnge", R.drawable.capture));
objects.add(new InfoObject("string 5", "gitnge", R.drawable.capture));
objects.add(new InfoObject("string 6", "gitnge", R.drawable.capture));
final ArrayList<InfoObject> details = new ArrayList<InfoObject>();
details.add(new InfoObject("string 1", R.drawable.capture));
details.add(new InfoObject("string 2", R.drawable.capture));
details.add(new InfoObject("string 3", R.drawable.capture));
details.add(new InfoObject("string 4", R.drawable.capture));
details.add(new InfoObject("string 5", R.drawable.capture));
details.add(new InfoObject("string 6", R.drawable.capture));
GeneralAdapter BestPlaces = new GeneralAdapter(getActivity(), objects);
ListView BestPlacesList = (ListView) rootView.findViewById(R.id.list);
BestPlacesList.setAdapter(BestPlaces);
BestPlacesList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
InfoObject detailsArray = details.get(position);
String m = detailsArray.getmTextDetails();
int s = (int) detailsArray.getImageResourcesObject();
Intent intent = new Intent(getActivity(), details.class);
intent.putExtra("message", m);
intent.putExtra("resource", s);
startActivity(intent);
}
});
return rootView;
}
}
und hier ist die Aktivität
public class details extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.details);
Bundle bundle = getIntent().getExtras();
Bundle extra = getIntent().getExtras();
int resources = extra.getInt("resource");
String message = bundle.getString("message");
TextView textDetails = (TextView) findViewById(R.id.text_details);
textDetails.setText(message);
ImageView imageDetails = (ImageView) findViewById(R.id.image_details);
imageDetails.setImageResource(resources);
}
}
hier ist das Infoobjekt
public class InfoObject {
private String locationObject;
private String placeNameObject;
private int imageResourcesObject;
private String mTextDetails;
private int mDetailsImageResource;
public InfoObject(String location, String placeName, int imageResources) {
locationObject = location;
placeNameObject = placeName;
imageResourcesObject = imageResources;
}
public InfoObject(String textDetails, int detailsImageResource) {
mTextDetails = textDetails;
mDetailsImageResource = detailsImageResource;
}
public String getmTextDetails() {
return mTextDetails;
}
public int getmDetailsImageResource() {
return mDetailsImageResource;
}
public String getLocationObject() {
return locationObject;
}
public String getPlaceNameObject() {
return placeNameObject;
}
public int getImageResourcesObject() {
return imageResourcesObject;
}
public void setLocationObject(String locationObject) {
this.locationObject = locationObject;
}
public void setPlaceNameObject(String placeNameObject) {
this.placeNameObject = placeNameObject;
}
public void setImageResourcesObject(int imageResourcesObject) {
this.imageResourcesObject = imageResourcesObject;
}
}
Erhalten Sie '" message "' ('textDetails' TextView) in Ordnung bei der 'details'-Aktivität? –
ja Ich bekomme die Nachricht in "textDetails" TextView, aber ich bekomme nicht die Image Id –
Bitte post Quellcode von 'InfoObject'. –