これは私の展開可能なリストビューです:
public class SnatchView extends ExpandableListView {
public SnatchAdt m_adt;
public FileBrowser fileBrowser;
public SnatchView(Context context) {
super(context);
m_adt = new SnatchAdt(context, this);
}
public SnatchView(Context context, AttributeSet attrs) {
super(context);
m_adt = new SnatchAdt(context, this);
}
public void start() {
setAdapter(m_adt);
m_adt.start();
setBackgroundColor(SnatchAdt.clr_back);
setGroupIndicator(null);// getResources().getDrawable(R.drawable.folder_icon)
}
public void edit() {
m_adt.notifyDataSetChanged();
m_adt.notifyDataSetInvalidated();
}
public String getChildPath(int group, int child) {
return m_adt.getChildPath(group, child);
}
public boolean getChildDelete(int group, int child) {
return m_adt.getChildDelete(group, child);
}
public void close() {
m_adt.close();
}
}
これは私のアダプターのより重要な部分です:
public class SnatchAdt extends BaseExpandableListAdapter implements ExpandableListAdapter {
private final String TAG = SnatchAdt.class.getSimpleName();
protected static int clr_back = 0xff356AA0;// 0xFFCCCCCC;
protected int clr_text = 0xffffffff;// 0xFF000044;
private SnatchView snatchView;
public class SnatchItem {
public String m_path;
public String m_name;
public boolean toDelete = false;
LinearLayout m_view;
}
public class SnatchGroup {
private Vector<SnatchItem> m_items = new Vector<SnatchItem>();
public SnatchItem get(int index) {
return m_items.get(index);
}
public int get_count() {
return m_items.size();
}
public void add_item(String path, String name, boolean toDelete) {
final SnatchItem item = new SnatchItem();
item.m_name = name;
item.m_path = path;
item.toDelete = toDelete;
item.m_view = new LinearLayout(m_context);
Bitmap myBitmap = BitmapFactory.decodeResource(m_context.getResources(), R.drawable.file_icon);
ImageView v = new ImageView(m_context);
v.setImageBitmap(myBitmap);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(50, 0, 0, 0);
v.setLayoutParams(lp);
final CheckBox cb = new CheckBox(m_context);
cb.setPadding(10, 10, 10, 10);
cb.setFocusable(false);
cb.setFocusableInTouchMode(false);
cb.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (cb.isChecked()) {
item.toDelete = true;
snatchView.smoothScrollBy(1, 1);
} else {
item.toDelete = false;
snatchView.smoothScrollBy(1, 1);
}
// snatchView.invalidateViews();
// notifyDataSetChanged();
snatchView.edit();
// snatchView.post(new Runnable() {
// @Override
// public void run() {
// notifyDataSetChanged();
// }
// });
}
});
TextView view = new TextView(m_context);
view.setText(name);
view.setBackgroundColor(clr_back);
view.setTextSize(18);
view.setTextColor(clr_text);
view.setPadding(20, 0, 0, 0);
item.m_view.addView(cb);
item.m_view.addView(v);
item.m_view.addView(view);
item.m_view.setPadding(12, 20, 0, 20);
item.m_view.setBackgroundColor(clr_back);
m_items.add(item);
item.m_view.setId(clr_back);
}
String m_path;
LinearLayout m_view;
}
private Vector<SnatchGroup> m_groups = new Vector<SnatchGroup>();
private DataSetObserver m_obs;
private Context m_context;
private boolean canceling = false;
private Handler m_hand_ui = new Handler() {
@Override
public void handleMessage(Message msg) {
if (m_groups != null) {
m_groups.add((SnatchGroup) msg.obj);
}
if (m_obs != null) {
m_obs.onChanged();
}
super.handleMessage(msg);
}
};
private Thread m_thread = new Thread() {
@Override
public void run() {
set_group_root();
}
};
public SnatchAdt(Context ctx, SnatchView snatchView) {
m_context = ctx;
this.snatchView = snatchView;
}
private synchronized Object get_child(int groupPosition, int childPosition) {
return m_groups.get(groupPosition).get(childPosition);
}
private synchronized String get_child_path(int groupPosition, int childPosition) {
return m_groups.get(groupPosition).get(childPosition).m_path;
}
}
リストビューを移動した後でのみ、無効になりません。また、リストビューを移動しない限り、呼び出すコードは呼び出されsnatchView.edit();
ません。そのコードを機能させる方法を知っている人はいますか? また、invalidate、notifyDataSetChanged、notifyDataSetInvalidated、runOnUIThread での notifyDataSetChange の呼び出し、または別のスレッドを呼び出してみましたが、まだうまくいきません。