プロフィールリストをlistviewで作成して、
各メンバーのプロフィールをタップすると、別のintentに飛ばし、プロフィールの詳細を表示させたいです。
メンバーの配列は10個くらいで、飛ぶ先のアクティヴィティのレイアウトは下記のような感じにしたいです。
タップしたitem(OnItemClick使って)によって
「名前、役職、下記のテキスト 画像など」
を変えたいです。
仮にメンバー(LIstview)が100人いた場合、
「intentを100個用意する」んじゃなく、もっと簡単でスッキリさせる方法ありますか?
追記部分
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"); startActivity(sub); long get_id = id; switch(get_id){ case 0: text.setText(R.string.profil_name_yoshioka); text2.setText(R.string.job_yoshioka); text3.setText(R.string.description_yoshioka); break; } } });
switchでメンバー分の分岐を用意しようかと思うのですが、考え方はあってますでしょうか?
switchの引数部分にlongを入れられない、とエラーが出ています。
onitemclickでタップされた項目の「id」と「switchを対応させる方法」が今ひとつわからないです。
追記3
遷移前
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"); startActivity(sub); sub.putExtra("list_names", listView.getItemAtPosition(position).toString()); } });
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 image = (ImageView) findViewById(R.id.imageView); */ Intent sub = getIntent(); String name = sub.getStringExtra("list_names"); text.setText(name); } }
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/03/29 03:26
2016/03/29 07:06
2016/03/29 10:25
2016/03/29 10:30
2016/03/30 05:17