Android:ListView和每个列表项onClick动作

时间:2014-09-06 17:13:16

标签: android listview actionlistener

我已经填充了Listview,从数据库中调整数据。当然,每个列表项都有相同的布局。在这个布局中有一些按钮,复选框和其他小部件。

现在我要设置onClickListenser。如何实现?

以下是概述: enter image description here

我有什么:

private void populateListView(){
    DatabaseHandler db = new DatabaseHandler(this);
    Cursor alarms = db.getAllAlarms();

    startManagingCursor(alarms);
    String[] time = new String[]{DatabaseHandler.KEY_TIME};
    int[] toViewIDs = new int[]{R.id.timeTitle};

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(
            this,
            R.layout.per_alarm_activity,
            alarms,
            time,
            toViewIDs
            );

    ListView listView = (ListView) findViewById(R.id.allAlarmsView);
    listView.setAdapter(adapter);

    mTimeView = (TextView) findViewById(R.id.timeTitle);
    mAmPmTextView = (TextView) findViewById(R.id.amPmTextView);
    mAlarmOnOff = (Switch) findViewById(R.id.alarmOnOff);
    mRepeatCheck = (CheckBox) findViewById(R.id.repeatCheckBox);
    mDrop = (ImageView) findViewById(R.id.arrowDown);
    mUp = (ImageView) findViewById(R.id.arrowUp);
}

1 个答案:

答案 0 :(得分:0)

试试这个

listView.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> arg0, View view, int position, long arg3) {
                CheckBox mRepeatCheck  =((CheckBox)view.findViewById(R.id.repeatCheckBox));
                //same code goes for othe buttons, imageview etc
    }
});