1

グループと子ごとにグラフィック、テキスト、progressBar を持つ ExpandableListView があります。タスクとサブタスクの概要です。問題は、グループの 1 つをクリックすると、すべてのプログレスバーが消えることです。シリアル化されたオブジェクトをsavedInstanceStateに入れるなど、いくつか試しましたが、うまくいきませんでした。これを解決する方法があることを願っています。

興味深い事実は、SDK16 ではこのような動作はなく、SDK10 でのみ :(

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.overview);

    appState = ((AutoBauLogApp) getApplicationContext());
    Bundle extras = getIntent().getExtras();
    // get selected field and get data
    final int position = extras.getInt("position");
    Field curField = appState.getModel().getFieldArray().get(position);

    // name of field
    setTextView(curField, position);
    // progressbar
    // TODO remove test data 80
    curField.setTargetProgress(80);
    setProgressBar(curField);
    // list for IVehicles
    setIVehicleList(curField);
    // map button
    // setMapButton(curField, position);

    // Retrive the ExpandableListView from the layout
    ExpandableListView listView = (ExpandableListView) findViewById(R.id.listView);

        }

    adapter = new ExpandableListAdapter(this, new ArrayList<Task>(), new ArrayList<ArrayList<Task>>());

    // Set this blank adapter to the list view
    listView.setAdapter(adapter);
    fillListWithData();

    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = curField.getAllTasks().size() * 70;
    listView.setLayoutParams(params);
    listView.requestLayout();
}

私はすべての答えに感謝しています:)


アダプターコードは次のとおりです。

import java.util.ArrayList;

import kit.edu.AutoBauLog.R;
import kit.edu.AutoBauLog.storage.Task;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

public class ExpandableListAdapter extends BaseExpandableListAdapter{
    @Override
    public boolean areAllItemsEnabled() {
        return true;
    }

    private Context context;
    private ArrayList<Task> groups;
    private ArrayList<ArrayList<Task>> children;

    public ExpandableListAdapter(Context context, ArrayList<Task> groups, Arra    yList<ArrayList<Task>> children) {
        this.context = context;
        this.groups = groups;
        this.children = children;
    }

    /**
     * A general add method, that allows you to add a Vehicle to this list
     * 
     * Depending on if the category opf the vehicle is present or not, the corr    esponding item will either be added to an
     * existing group if it exists, else the group will be created and then the item will     be added
     * 
     * @    param vehicle
     */    
    public void addItem(ArrayList<Task> tasks) {
        for (int i = 0; i < tasks.size(); i++) {
            this.groups.add(tasks.get(i));
            this.children.add(tasks.get(i).getSubtasks());
        }
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return children.get(groupPosition).get(childPosition);
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    // Return a child view. You can load your custom layout here.
    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView,
            ViewGroup parent) {
        Task task = (Task) getChild(groupPosition, childPosition);
        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.child_layout, null);
        }
        setLayout(convertView, task);
        return convertView;
    }


    @Override
    public int getChildrenCount(int groupPosition) {
        return children.get(groupPosition).size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return groups.get(groupPosition);
    }

    @Override
    public int getGroupCount() {
        return groups.size();
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    // Return a group view. You can load your custom layout here.
    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
    Task task = (Task) getGroup(groupPosition);
    if (convertView == null) {
        LayoutInflater infalInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.group_layout, null);
    }
    setLayout(convertView, task);
    return convertView;
}

private void setLayout(View convertView, Task task) {

    convertView.invalidate();
    convertView.requestLayout();
    TextView tv = (TextView) convertView.findViewById(R.id.taskName);
    tv.setText(task.getName() + " - " + task.getDescription());

    ProgressBar pB = (ProgressBar) convertView.findViewById(R.id.adapterProgressBar);
    if (task.getProgressState() != null) {
        Drawable color = null;
        switch (task.getProgressState()) {
        case GOOD:
            color = (Drawable) convertView.getResources().getDrawable(R.drawable.progresscolor_good);
            break;
        case OK:
            color = (Drawable) convertView.getResources().getDrawable(R.drawable.progresscolor_ok);
            break;
        case BAD:
            color = (Drawable) convertView.getResources().getDrawable(R.drawable.progresscolor_bad);
            break;
        }
        pB.setProgressDrawable(color);
    }
    pB.setSecondaryProgress(task.getTargetProgress());
    pB.setProgress(task.getProgress());

    ImageView iV = (ImageView) convertView.findViewById(R.id.iconProgressAdapter);
    // set icons
    if (!task.getWorkingStatus()) {
        iV.setImageResource(R.drawable.sleeping);
    } else {
        iV.setImageResource(R.drawable.gear);
    }
}

@Override
public boolean hasStableIds() {
    return true;
}

@Override
public boolean isChildSelectable(int arg0, int arg1) {
    return true;
}
}
4

0 に答える 0