我有一个填充列表视图的活动。我在活动的 onCreate 方法中创建了列表视图。现在我想为列表实现一个 onclick 列表器。如何做到这一点?
这是我的列表视图活动课程:
public class PollStationActivity extends Activity {
static String response_str=null;
static String response_code=null;
String ac_code;
String ac_id;
String ac_lat;
String ac_lon;
String ac_name;
// Hashmap for ListView
ArrayList<HashMap<String, String>> PSList = new ArrayList<HashMap<String, String>>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// no more this
setContentView(R.layout.activity_poll_station);
//sendPostRequest();
//Log.i("I am here","1");
final String status_code_from_prev= getIntent().getExtras().getString("status");
//Log.i("ss",status_code_from_prev);
ArrayList<PSItem> PSList = new ArrayList<PSItem>();
DatabaseHelper db = new DatabaseHelper(PollStationActivity.this);
ContentValues values = new ContentValues();
try {
db.createDataBase();
PSList = db.select(status_code_from_prev);
//Log.i("Count : ", " " + PSList.isEmpty());
} catch (IOException e) {
e.printStackTrace();
}
db.close();
String[] fromColumns = {"name"};
int[] toViews = {R.id.list_label_name}; // The TextView in simple_list_item_1
ListView listView1 = (ListView) findViewById(R.id.poll_list_listView);
List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>();
Iterator<PSItem> i = PSList.iterator();
while(i.hasNext())
{
HashMap<String, String> map = new HashMap<String, String>();
PSItem objPSItem = i.next();
map.put("name", objPSItem.PS_NAME);
map.put("ps_Id", objPSItem.PS_ID);
fillMaps.add(map);
}
// fill in the grid_item layout
SimpleAdapter adapter = new SimpleAdapter(this, fillMaps, R.layout.list_layout, fromColumns, toViews);
listView1.setAdapter(adapter);
}
}
我应该把listview onclick listner放在哪里?