タイトルと同じように、現在のアクティビティRouteDetails.javaのイメージをインテント経由で新しいアクティビティのFullScreenImage.javaに渡そうとしています。 putExtra getExtraでこれを行うことはできますか?誰かが私にこのことを起こすためのコードを教えてもらえますか?私はこの一日中苦労しており、とても感謝しています。現在のアクティビティのイメージをインテント経由で新しいアクティビティに渡したい
HERESに私のRouteDetails.java
package com.example.zach.listview;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class RouteDetails extends AppCompatActivity {
TouchImageView routeImage;
TouchImageView routeImageFull;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_route_details);
//back button for route details view
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
//TextView for route details
final TextView routeDetailsView = (TextView) findViewById(R.id.routeDetailsView);
routeDetailsView.setText(getIntent().getExtras().getString("route"));
//ImageView for route details
routeImage = (TouchImageView) findViewById(R.id.routeImage);
routeImage.setImageResource(getIntent().getIntExtra("imageResourceId", 0));
////////// Trying to pass image to new activity
routeImage.setOnClickListener(new View.OnClickListener() {
public void onClick(View view)
{
Intent intent = new Intent(view.getContext(), FullScreenImage.class);
startActivity(intent);
}
});
////////////
}
//back button for route details view
@Override
public boolean onSupportNavigateUp(){
finish();
return true;
}
}
と私のactivity_route_details.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_route_details"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.zach.listview.RouteDetails">
<TextView
android:text="TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/routeDetailsView"
android:textSize="18sp"
android:textAlignment="center" />
<com.example.zach.listview.TouchImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/routeImage"
android:scaleType="fitCenter"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:adjustViewBounds="false"
android:layout_below="@+id/routeDetailsView"/>
</RelativeLayout>
</ScrollView>
と相続人FullScreenImage.javaは私が
package com.example.zach.listview;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class FullScreenImage extends AppCompatActivity {
TouchImageView routeImage;
@Override
protected void onCreate(Bundle saveInstanceState){
super.onCreate(saveInstanceState);
setContentView(R.layout.full_screen_image);
//back button for route details view
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
routeImage = (TouchImageView) findViewById(R.id.fullScreenImageView);
}
//back button for route details view
@Override
public boolean onSupportNavigateUp(){
finish();
return true;
}
}
とに画像を渡したいですfull_screen_image.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.example.zach.listview.TouchImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:srcCompat="@+id/routeImage"
android:id="@+id/fullScreenImageView"
android:layout_weight="1" />
</LinearLayout>
あなたはすでに 'getIntentを()持っている。あなたはgetIntExtra( "imageResourceId")' ...だから、何の問題エクストラをもう一度渡していますか? –
画像はどこですか?ドロウアブルフォルダに? –
イメージビュー上で[onClickListener]を複製して新しいインテントを開始する可能性があります(http://stackoverflow.com/questions/40619024/onclicklistener-on-imageview-to-start-new-intent) –