如何将另一个消息对象内的值设置为列表

时间:2015-09-16 09:14:37

标签: android android-activity

我有事件消息对象(EventMO)..在这我有事件ID,名称,地点,日期,时间.....我有另一个叫做事件提醒天消息对象...在这我有类型id,被选中....我使用Event Reminder Days mo作为EventMO ....中的列表....

这是我的EventMO

    private long eventId;

    private long ringeeUserId;

    private String text;

    private String place;

    private String eventDate;

    private String startTime;

    private String endTime;

    private int isDelete;

    private List<EventReminderDaysMO> eventReminderDaysMOs;


    public List<EventReminderDaysMO> getEventReminderDaysMOs() {
        return eventReminderDaysMOs;
    }

    public void setEventReminderDaysMOs(List<EventReminderDaysMO> eventReminderDaysMOs) {
        this.eventReminderDaysMOs = eventReminderDaysMOs;
    }




}

这是我的活动提醒日MO

private long eventReminderDaysId;

private String eventReminderDate;

private int isSelected;

private int isMessageSent;

private int typeId;

这是我的复选框代码...这里我需要将类型ID设置为此复选框的一个....我无法直接使用事件提醒日MO ..因为我需要将EventMO作为列表传递到后端.....所以如何将值设置为在事件MO

内输入id
 checkBox_aWeekBefore.setOnClickListener(new View.OnClickListener(){

            public void onClick(View v) {
                if (((CheckBox) v).isChecked()) {
                    final int response = 2;
//Here only i have a problem
                    //eventMO.setTypeId(response); ---i cant use this...it wont be allowed

                    new AsyncTask<Void, Void, String>() {
                        protected String doInBackground(Void... arg0) {
                            return eventDelegates.addEvent(eventMO,context);

                        }

                    }.execute(null, null, null);
                    Toast.makeText(OccasionActivity.this,
                            "Checked", Toast.LENGTH_LONG).show();
                }}
        });

3 个答案:

答案 0 :(得分:0)

由于您已编码点击单个部分,您还可以使用以下代码在其中获取id,并将其放入数据库中。

@Override
public void onClick(View v) {
    int checkBoxId  = v.getId();    
} 

答案 1 :(得分:0)

这不是获取checkBox结果的正确方法,你需要在OnItemClick的位置添加OnCheckedChangeLisenter ..我给你的​​示例代码....

    CheckBox chk1;
    CheckBox chk2;
    CheckBox chk3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);

        chk1 = (CheckBox) findViewById(R.id.chk1);
        chk2 = (CheckBox) findViewById(R.id.chk2);
        chk3 = (CheckBox) findViewById(R.id.chk3);


        chk1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b == true) {
                    Toast.makeText(getApplicationContext(), "On Event Day Selected", Toast.LENGTH_LONG).show();
                }
            }
        });

        chk2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b == true) {
                    Toast.makeText(getApplicationContext(), "2 day before selected", Toast.LENGTH_LONG).show();
                }
            }
        });

        chk3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b == true) {
                    Toast.makeText(getApplicationContext(), "7 day before Selected", Toast.LENGTH_LONG).show();
                }
            }
        });


    }
}

更新:----

只检查条件是否选中了您的复选框...如果选中复选框,则传递您想要通过的方法...

例如

chk1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b == true) {
request=2;
MOevent.setTypeId(request);
                 }
            }
        });

答案 2 :(得分:0)

使用 OnCheckedChangeListener() ,可能会解决您的疑问。有关进一步细分,请遵循以下代码段:

实施OnCheckedChangeListener,如下所示:

class YourClass implements OnCheckedChangeListener{/.../}

为每个复选框启用侦听器,如下所示:

cb1.setOnCheckedChangeListener(this);
cb2.setOnCheckedChangeListener(this);
cb3.setOnCheckedChangeListener(this);
cb4.setOnCheckedChangeListener(this);

覆盖onCheckedChanged方法,聆听复选框状态中的更改:

@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

    buttonView.getId();     //To get id of the checkbox
}

希望有所帮助。