2 回答
TA贡献1862条经验 获得超7个赞
请alarmListView.setOnItemClickListener按照@Parul 的说法删除
并在适配器中updateButton整体替换view。
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent updateAlarmIntent = new Intent(MainActivity.this, CreateAlarmActivity.class);
updateAlarmIntent.putExtra("alarmList", alarmList);
updateAlarmIntent.putExtra("position", position);
startActivity(updateAlarmIntent);
}
});
TA贡献2037条经验 获得超6个赞
如果您只想在更新按钮上执行操作,请执行此操作。
在适配器的 getView() 方法中:
updateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Logic goes here.
onUpdateClick(position, alarmList); // public method in adapter
}
});
然后在适配器中创建公共方法:
public void onUpdateClick(int position, ArrayList<alarm> alarmList){
}
现在在初始化适配器时在活动中覆盖此方法:
alarmAdapter = new AlarmAdapter(MainActivity.this, alarmList){
@Override
public void onUpdateClick(int position, ArrayList<alarm> alarmList) {
super.onUpdateClick(position, alarmList);
Intent updateAlarmIntent = new Intent(MainActivity.this,
CreateAlarmActivity.class);
updateAlarmIntent.putExtra("alarmList", alarmList);
updateAlarmIntent.putExtra("position", position);
startActivity(updateAlarmIntent);
}
};
添加回答
举报