setOnItemClickListener��setOnItemSelectedListene���g�p���܂���
ListView�̃N���b�N
�w�肵�����X�g�r���[��item���擾����̂�onItemClick���g�p����Ă��܂�
����͂���onItemClick�����������ڂ������Ă��������Ǝv���܂�
onItemClick(AdapterView parent, View view,int position, long id)parent�F�N���b�N���ꂽAdapter�̃r���[�ƂȂ�
view�F���ۂɃN���b�N���ꂽ�r���[
position�F�A�_�v�^�[�̉��Ԗڂ��N���b�N���ꂽ��
id�F�N���b�N���ꂽ���id
�O��̃v���O�������ȉ��̂悤�ɕύX���ĉ����擾����Ă���̂����ڂ����������Ǝv���܂�
MainActivity.java
package blog.test; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; public class MainActivity extends Activity { private String[] mStrings ={ "test1", "test2", "test3", "test4" }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //���X�g�r���[���쐬 ListView lv = new ListView(this); setContentView(lv); ArrayAdapteradapter = new ArrayAdapter (this, android.R.layout.simple_list_item_1, mStrings); lv.setAdapter(adapter); //�N���b�N�C�x���g�����o lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView parent, View view, int position, long id) { //listView���w�� //ListView listView = (ListView) parent; //�N���b�N���ꂽ���̂��擾 String get_parent = (String) parent.getClass().getSimpleName(); String get_position = String.valueOf(position); String get_id = String.valueOf(id); //Log�o�� Log.v("tag", String.format("onItemClick: %s", get_parent)); Log.v("tag", String.format("onItemClick: %s", get_position)); Log.v("tag", String.format("onItemClick: %s", get_id)); } }); //�Z���N�g���ꂽ�Ƃ��Ɏ��s����� lv.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView parent, View view, int position, long id) { //listView���w�� //ListView listView = (ListView) parent; //�N���b�N���ꂽ���̂��擾 String get_parent = (String) parent.getClass().getSimpleName(); String get_position = String.valueOf(position); String get_id = String.valueOf(id); //Log�o�� Log.v("tag", String.format("onItemClick: %s", get_parent)); Log.v("tag", String.format("onItemClick: %s", get_position)); Log.v("tag", String.format("onItemClick: %s", get_id)); } //�����I�����ĂȂ��Ƃ��Ɏ��s public void onNothingSelected(AdapterView parent) { Log.v("tag", "onNothingSelected"); } }); } }
���߂���test1���N���b�N���Ă݂�ƁE�E�E
parent��ListView���Aposition��0���i1�Ԗ�-1�j�Aid��0���i1�Ԗ�-1�j��
���ꂼ��Log�Ƃ��ďo�͂���܂�
���l�ɉ��{�^����test1���Z���N�g�����
����������l��parent��ListView���Aposition��0���i1�Ԗ�-1�j�Aid��0���i1�Ԗ�-1�j��
Log�Ƃ��ďo�͂���܂�
�X�|���T�[�h�����N
�y�E�B�W�F�b�g�@���X�g�r���[�̍ŐV�L���z