Create a gist now

Instantly share code, notes, and snippets.

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.AdapterView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class ListViewA extends Activity implements OnItemClickListener {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
ListView lv= (ListView)findViewById(;
// create the grid item mapping
String[] from = new String[] {"rowid", "col_1", "col_2", "col_3"};
int[] to = new int[] {,,, };
// prepare the list of all records
List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>();
for(int i = 0; i < 10; i++){
HashMap<String, String> map = new HashMap<String, String>();
map.put("rowid", "" + i);
map.put("col_1", "col_1_item_" + i);
map.put("col_2", "col_2_item_" + i);
map.put("col_3", "col_3_item_" + i);
// fill in the grid_item layout
SimpleAdapter adapter = new SimpleAdapter(this, fillMaps, R.layout.grid_item, from, to);
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.d("onItemClick", "position: " + String.valueOf(position));
Toast.makeText(this, position, Toast.LENGTH_SHORT).show();

This comment has been minimized.

Show comment
Hide comment

maehrm Nov 26, 2011

lv.setOnItemClickListener(this); が抜けているから…。


maehrm commented Nov 26, 2011

lv.setOnItemClickListener(this); が抜けているから…。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment