setOnItemClickListenerでタップした時の処理
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ListView myListView = (ListView) findViewById(R.id.myListView); ArrayList<User> users = new ArrayList<>(); int[] icons = { R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, }; String[] names = { "yoshida", "kobayashi", "igawa" }; String[] locs = { "Hamamatsucho", "Marunouchi", "Ebisu" }; for(int i = 0; i < icons.length; i++){ User user = new User(); user.setIcon(BitmapFactory.decodeResource( getResources(), icons[i] )); user.setName(names[i]); user.setLoc(locs[i]); users.add(user); } UserAdapter adapter = new UserAdapter(this, 0, users); myListView.setAdapter(adapter); myListView.setOnItemClickListener(new AdapterView.OnItemClickListener(){ @Override public void onItemClick( AdapterView<?> adapterView, View view, int i, long l ) { TextView name = (TextView) view.findViewById(R.id.name); Toast.makeText( MainActivity.this, Integer.toString(i) + ":" + name.getText().toString(), Toast.LENGTH_SHORT ).show(); name.setText("Tapped"); } }); }
こりゃ覚えること多すぎて、思ってたより時間かかりそーだ