esperando estén bien, tengo una inquietud.
Tengo dos actividades 1) Listado de cursos y sus hijos son las actividades - 2) Datos y evaluación de la actividad del curso
El proceso es el siguiente.
Selecciono una actividad del curso desde un ExpandableListView el cual con la posición del grupo y su hijo obtengo el objeto Actividad, previamente llenado. Este lo paso a la actividad (2) con un intent.
Hasta acá todo bien, mi problema es al evaluar la actividad. El cambio en la base de datos es correcto pero cuando hago el set en el objeto actividad, dentro de la actividad (2) el valor se mantiene, pero al volver atrás el valor se pierde, ya que no actualiza una imagen que tengo en el listado de actividades del ExpandableListView
Clase Actividad
class Activity implements Parcelable{
private Integer id;
private String titlePref;
private String title;
private String teacher;
private String type = "";
private Integer evaluateContent = 0;
private Integer evaluateTeacher = 0;
private Integer canEvaluate = 0;
private Integer isAccomplished = 0;
private Integer isBlocked = 0;
private Integer hvVideo = 0;
private Video videoObj = null;
private String bannerUrl = "";
private String blockName = "";
//default constructor, for video or other who extends of Activity
public Activity(Integer id) { this.setId(id); }
public Activity(Integer id, String titlePref, String title, String teacher, Integer isAccomplished, Integer isBlocked, Integer hvVideo, String bannerUrl, String blockName)
{
this.setId(id);
this.setTitlePref(titlePref);
this.setTitle(title);
this.setTeacher(teacher);
this.setIsAccomplished(isAccomplished);
this.setIsBlocked(isBlocked);
this.setHvVideo(hvVideo);
this.setBannerUrl(bannerUrl);
this.setBlockName(blockName);
}
private Activity(Parcel in)
{
id = in.readInt();
titlePref = in.readString();
title = in.readString();
teacher = in.readString();
canEvaluate = in.readInt();
evaluateContent = in.readInt();
evaluateTeacher = in.readInt();
isAccomplished = in.readInt();
isBlocked = in.readInt();
hvVideo = in.readInt();
bannerUrl = in.readString();
blockName = in.readString();
}
public static final Parcelable.Creator<Activity> CREATOR = new Parcelable.Creator<Activity>()
{
@Override
public Activity createFromParcel(Parcel in) {
return new Activity(in);
}
@Override
public Activity[] newArray(int size) {
return new Activity[size];
}
};
public int describeContents() {
return 0;
}
public void writeToParcel(Parcel dest, int flags)
{
dest.writeInt(id);
dest.writeString(titlePref);
dest.writeString(title);
dest.writeString(teacher);
dest.writeInt(canEvaluate);
dest.writeInt(evaluateContent);
dest.writeInt(evaluateTeacher);
dest.writeInt(isAccomplished);
dest.writeInt(isBlocked);
dest.writeInt(hvVideo);
dest.writeString(bannerUrl);
dest.writeString(blockName);
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getTitlePref() {
return titlePref;
}
public void setTitlePref(String titlePref) {
this.titlePref = titlePref;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getTeacher() {
return teacher;
}
public void setTeacher(String teacher) {
this.teacher = teacher;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Integer getEvaluateContent() {
return evaluateContent;
}
public void setEvaluateContent(Integer evaluateContent) {
this.evaluateContent = evaluateContent;
}
public Integer getEvaluateTeacher() {
return evaluateTeacher;
}
public void setEvaluateTeacher(Integer evaluateTeacher) {
this.evaluateTeacher = evaluateTeacher;
}
public Integer getCanEvaluate() {
return canEvaluate;
}
public void setCanEvaluate(Integer canEvaluate) {
this.canEvaluate = canEvaluate;
}
public Integer getIsAccomplished() {
return isAccomplished;
}
public void setIsAccomplished(Integer isAccomplished) {
this.isAccomplished = isAccomplished;
}
public Integer getIsBlocked() {
return isBlocked;
}
public void setIsBlocked(Integer isBlocked) {
this.isBlocked = isBlocked;
}
public Integer getHvVideo() {
return hvVideo;
}
public void setHvVideo(Integer hvVideo) {
this.hvVideo = hvVideo;
}
public Video getVideoObj() {
return videoObj;
}
public void setVideoObj(Video videoObj) {
this.videoObj = videoObj;
}
public String getBannerUrl() {
return bannerUrl;
}
public void setBannerUrl(String bannerUrl) {
this.bannerUrl = bannerUrl;
}
public String getBlockName() {
return blockName;
}
public void setBlockName(String blockName) {
this.blockName = blockName;
}
public Video getVideo()
{
return videoObj;
}
public Video makeVideo(String video){ return videoObj = new Video(this.getId(), video);}
Así paso el objeto a la otra actividad android (2):
listViewMyCoursesBlocks.setOnChildClickListener(new ExpandableListView.OnChildClickListener()
{
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id)
{
myActivity = (Activity)parent.getExpandableListAdapter().getChild(groupPosition,childPosition);
if( myActivity.getIsBlocked() == 0 )
{
gPosition = groupPosition;
cPosition = childPosition;
Intent i = new Intent(getApplicationContext(), MyClassActivity.class);
i.putExtra("myActivity", myActivity);
startActivity(i);
return true;
}
return false;
};
});
Lo recibo así:
Intent i = getIntent();
myActivity = i.getExtras().getParcelable("myActivity");
Hago el set así:
myActivity.setEvaluateTeacher(3);
Al volver a la actividad (1):
En mi onResume quería actualizar una imagen del ExpandableListView que indica que esa actividad del curso esta "evaluada".
pero al hacer
myActivity.getEvaluateTeacher();
Devuelve como valor 0
Estuve leyendo y al parecer en JAVA no funciona pasar un valor por referencia, sino por valor. Entonces cada objeto debiera tener valor en su propia "Actividad android", si no entendi mal.
Como puedo setear un valor en mi actividad (2) y al volver a la actividad (1) pueda recibir el valor que le di .... y hacer algo como:
listAdapter.notifyDataSetChanged();
Para que actualice la imagen del listado.
Gracias