こんにちは皆、フラグメントから別のアクティビティへのインテントを使用して画像IDを送信する際に問題があります。私はそのインテントを見て問題を検索しました。アクティビティ間のid。この質問は私の問題と同じですが、解決策が私のために働かなかった:How can i get Image Resource ID and send it to other activity in Android?。 は、ここに私のプログラムフラグメントから別のアクティビティへの画像IDの送信
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;
}
}
、ここでは、活動
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);
}
}
はここインフォ
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;
}
}
'' details'アクティビティで ''メッセージ ''( 'textDetails' TextView)をうまく使っていますか? –
はい "textDetails" TextViewにメッセージが表示されますが、画像IDを取得しません –
'InfoObject'のソースコードを投稿してください。 –