این کد Adapter :
package ir.rahgoshafan.mybody.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;import java.util.List;
import ir.rahgoshafan.mybody.R;
import ir.rahgoshafan.mybody.model.Week;
import ir.rahgoshafan.mybody.model.Workout;public class Expandable extends BaseExpandableListAdapter {
private Context context;
private Listweek;
private Listworkout; public Expandable(Context context, List
week, List workout) {
this.context = context;
this.week = week;
this.workout = workout;
}@Override
public int getGroupCount() {
return week.size();
}@Override
public int getChildrenCount(int groupPosition) {
return workout.size();
}@Override
public Object getGroup(int groupPosition) {
return week.get(groupPosition);
}@Override
public Object getChild(int groupPosition, int childPosition) {
return workout.get(childPosition);
}@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}@Override
public boolean hasStableIds() {
return true;
}@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
Week weekName = (Week) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater layoutInflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLA TER_SERVICE);
convertView = layoutInflater.inflate(R.layout.expandable_list_gr oup, null);
}
TextView weekDay = (TextView) convertView.findViewById(R.id.listTitle);
weekDay.setText(weekName.getDayName());
return convertView;
}@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
Workout workName = (Workout) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater layoutInflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLA TER_SERVICE);
convertView = layoutInflater.inflate(R.layout.expandable_list_it em, null);
}
TextView workoutName = (TextView) convertView.findViewById(R.id.expanded_ListItem_ex ercise);
workoutName.setText(workName.getWorkout());
TextView workoutNo = (TextView) convertView.findViewById(R.id.expanded_ListItem_no );
workoutNo.setText(String.valueOf(workName.getWorko utSet()));
return convertView;
}@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
این هم کدهای مربوط به اکتیویتی :
ExpandableListView expandableListView;
Expandable expandableListAdapter;
ListexpandableListTitle;
ListexpandableListDetail;expandableListDetail = DB_HELPER.WORKOUT_LIST(1);
expandableListTitle = DB_HELPER.WEEK_LIST(USER_ID);
expandableListAdapter = new Expandable(this, expandableListTitle, expandableListDetail);
expandableListView.setAdapter(expandableListAdapte r);
و این هم کوئری :
public ListWORKOUT_LIST(int id) { try {
Workout WORKOUT_TABLE = null;
ListWORKOUT = new ArrayList<>();
openDatabase();
db.beginTransaction();
Cursor WORKOUT_CURSOR = db.rawQuery("select * from tblWorkout where userDay =" + id, null);
db.setTransactionSuccessful();
WORKOUT_CURSOR.moveToFirst();
while (!WORKOUT_CURSOR.isAfterLast()) {
WORKOUT_TABLE = new Workout(WORKOUT_CURSOR.getInt(0), WORKOUT_CURSOR.getInt(1), WORKOUT_CURSOR.getString(2), WORKOUT_CURSOR.getInt(3),
WORKOUT_CURSOR.getInt(4), WORKOUT_CURSOR.getString(5));
WORKOUT.add(WORKOUT_TABLE);
WORKOUT_CURSOR.moveToNext();
}
WORKOUT_CURSOR.close();
return WORKOUT;
} catch (Exception e) {
Log.i(LOG_TAG, "VIEW_WORKOUT_LIST Error :" + e.toString());
return null;
} finally {
db.endTransaction();
closeDatabase();
}
}
توی عکس ضمیمه مشخصه ... یک فعالیت تعریف شده که فقط باید در روز شنبه نمایش داده بشه ولی توی دوشنبه هم هست !
برچسب:
نویسنده: محمد رضا جوادیان