10
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ListView 内 layout の tap を検出

Last updated at Posted at 2014-09-25

ListView を使って LINE みたいな感じのプロフ画+メッセージの画面を作った時に、
プロフ画を tap したことを検出したい

OnItemClickListener だと Item 全体を検出してしまう
ListView をいろいろすればとれるとのことだったけどあんまり手を加えずなんとかしたかった

Adapter で item が tap されたときに performItemClick を呼べば良さそう

public View getView(int pos, View view, final ViewGroup parent) {
  item.setOnClickListener(new OnClickListener() {
     @Override
     public void onClick(View v) {
         ((ListView) parent).performItemClick(v, pos, R.id.itemId);
     }
  });
}
listView.setOnItemClickListener(new ItemClickListener() {
    @Override
    public void onItemClick(ViewGroup parent, View view, int pos, long id) {
        Message item = messageListAdapter.getItem(pos);
        switch (view.getId()) {
        case R.id.itemId:
            Toast.makeText(this, "tap!!", Toast.LENGTH_LONG).show();
            break;
        }
    }
});

これでとれた

参考
http://tomstay.hatenablog.jp/entry/20110421/1303391426

10
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?