0
以下のコードを使用してタイトルと説明を正しく渡しましたが、ヘッダー画像を渡そうとすると何も起こりません。私のエラーはどこですか?クリックした内容に基づいて画像を変更する
MyPageHolder.java
public abstract class MyPageHolder extends RecyclerView.ViewHolder{
protected final Activity activity;
protected MyPageAdapter adapter;
public TextView txtTitle, txtDescription;
public ImageView imgImage;
public View view;
public MyPageHolder(View v, Activity activity, MyPageAdapter adapter) {
super(v);
this.activity = activity;
this.adapter = adapter;
imgImage = (ImageView) v.findViewById(R.id.cardview_image);
txtTitle = (TextView) v.findViewById(R.id.cardview_title);
txtDescription = (TextView) v.findViewById(R.id.cardview_description);
view = (CardView) v.findViewById(R.id.card_view);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
/*/ this is where the magic happens when clicked /*/
}
});
}
public void bind(MenuPageItems dataModel, Activity activity, final int position) {
final MenuPageItems m = (MenuPageItems)dataModel;
imgImage.setImageResource(m.image);
txtTitle.setText(m.title);
txtDescription.setText(m.description);
view.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v){
Intent cvIntent = new Intent(view.getContext(), EndpageActivity.class);
cvIntent.putExtra("endpageHeader", m.image);
// text to pass to endpage activity
cvIntent.putExtra("endpageTitle", m.title);
cvIntent.putExtra("endpageTheContent", m.description);
view.getContext().startActivity(cvIntent);
}
});
}
}
EndpageActivity.java
public class EndpageActivity extends AppCompatActivity {
TextView t1;
ImageView iv1;
private void loadBackdrop() {
String uri = "@drawable/p400x200";
// where backdropX.jpg (without the extension) is the file
int imageResource = getResources().getIdentifier(uri, null, getPackageName());
final ImageView imageView = (ImageView) findViewById(R.id.endpage_header_image);
Drawable res = getResources().getDrawable(imageResource);
imageView.setImageDrawable(res);
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.endpage_layout);
Intent intent = getIntent();
String sTitle = intent.getStringExtra("endpageTitle");
String sTheContent = intent.getStringExtra("endpageTheContent");
CollapsingToolbarLayout collapsingToolbar =
(CollapsingToolbarLayout) findViewById(R.id.endpage_header);
collapsingToolbar.setTitle(sTitle);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// this adds the back button arrow to the header
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
iv1 = (ImageView) findViewById(R.id.endpage_header_image);
iv1.setImageDrawable(getResources().getDrawable(getIntent().getIntExtra("endpageHeader", 0)));
t1 = (TextView)findViewById(R.id.endpage_the_content);
t1.setText(sTheContent);
loadBackdrop();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.sample_actions, menu);
return true;
}
}
アプリが実行されますが、唯一の私のテキストの変更、ImageViewのはまだ私のプレースホルダ画像を示しています。