カスタムリストビューに表示されている画像を、タップした後のintentで表示させるべく
intentに値を渡しているのですが、タップしても何も挙動しません。
新しいintentにBitmap(画像)を表示させたいです。
sub.putExtra("list_images",memberProfile.getBitmap());
の部分をコメントアウトすると、画像以外はタップするとうまく表示されるようになるので、そこに問題があると思うのですが。。。
public class Main extends AppCompatActivity { private ListView listView; ArrayList<MemberProfile> memberProfilesList; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); listView = (ListView)findViewById(R.id.listView1); //アレイリストのインスタンスを作成 memberProfilesList = new ArrayList<>(); memberProfilesList.add(new MemberProfile("吉田拓郎","農家",BitmapFactory.decodeResource(getResources(), R.drawable.human))); memberProfilesList.add(new MemberProfile("藤井ふみか","社長",BitmapFactory.decodeResource(getResources(), R.drawable.human1))); memberProfilesList.add(new MemberProfile("ケイティ・スチュワート","広報",BitmapFactory.decodeResource(getResources(), R.drawable.human2))); memberProfilesList.add(new MemberProfile("木田武蔵","アプリ開発事業部",BitmapFactory.decodeResource(getResources(), R.drawable.human3))); memberProfilesList.add(new MemberProfile("歩兵巡査","特殊部隊所属",BitmapFactory.decodeResource(getResources(), R.drawable.human4))); memberProfilesList.add(new MemberProfile("サラリーマン金太郎","課長",BitmapFactory.decodeResource(getResources(), R.drawable.human5))); memberProfilesList.add(new MemberProfile("メガネ男子","メガネ部員",BitmapFactory.decodeResource(getResources(), R.drawable.human6))); memberProfilesList.add(new MemberProfile("おかえくみこ","パンケーキサークル部長",BitmapFactory.decodeResource(getResources(), R.drawable.human7))); memberProfilesList.add(new MemberProfile("ふわふわ女子","ふわふわしてる",BitmapFactory.decodeResource(getResources(), R.drawable.human8))); memberProfilesList.add(new MemberProfile("吉田拓郎","アプリ開発事業部",BitmapFactory.decodeResource(getResources(), R.drawable.human))); memberProfilesList.add(new MemberProfile("吉田拓郎","アプリ開発事業部",BitmapFactory.decodeResource(getResources(), R.drawable.human))); //配列を保持するアダプターのインスタンスと引数を設定 //ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, profiles); CustomAdapter customAdapter = new CustomAdapter(this, memberProfilesList); //アダプターをリストビューのインスタンスに設定 listView.setAdapter(customAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent sub = new Intent(); sub.setClassName("com.example.tsuyoshiokaprofile", "com.example.tsuyoshiokaprofile.SubActivity"); MemberProfile memberProfile = (MemberProfile)listView.getItemAtPosition(position); sub.putExtra("list_names", memberProfile.getName()); sub.putExtra("list_jobs",memberProfile.getJob()); sub.putExtra("list_images",memberProfile.getBitmap()); startActivity(sub); } });
public class SubActivity extends AppCompatActivity{ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.sub_activity); TextView text = (TextView) findViewById(R.id.textView); TextView text2 = (TextView) findViewById(R.id.textView2); //TextView text3 = (TextView) findViewById(R.id.textView3); ImageView imageView = (ImageView) findViewById(R.id.imageView); Intent sub = getIntent(); String name = sub.getStringExtra("list_names"); String job = sub.getStringExtra("list_jobs"); Bitmap image = sub.getParcelableExtra("list_images"); text.setText(name); text2.setText(job); imageView.setImageBitmap(image); } }
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/03/30 08:04