- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
从数据库中获取数据后,我实现了一个 expandableListview。数据在列表中正常显示,子项详细信息页面上的 onClicking() 正在打开,用户可以在其中删除数据并编辑数据。但是在返回到 MainActivity 之后,我必须再次调用 OnResume 中的 Adpater 类来重新加载我不需要的数据。我只想删除 或显示更新的 数据。我已经尝试使用 notifyDataSetChanged() 但它没有用,可能是我在错误的地方使用了它。请稍微指导一下...
适配器类..
public class TransExpAdapter extends BaseExpandableListAdapter {
private Context context;
List<ExcelDataModel> list_shareofshelf;
public TransExpAdapter(Context context, List<ExcelDataModel> list_shareofshelf) {
this.context = context;
this.list_shareofshelf = list_shareofshelf;
}
@Override
public Object getChild(int listPosition, int expandedListPosition) {
return this.list_shareofshelf.get(listPosition);
}
@Override
public long getChildId(int listPosition, int expandedListPosition) {
return expandedListPosition;
}
@Override
public View getChildView(final int listPosition, final int expandedListPosition, boolean isLastChild, View convertView, ViewGroup parent) {
LayoutInflater layoutInflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View cview = layoutInflater.inflate(R.layout.list_child_sos, null);
RelativeLayout child_container = cview.findViewById(R.id.child_container);
TextView tv_category = cview.findViewById(R.id.tv_category);
TextView tv_expense = cview.findViewById(R.id.tv_expense);
ImageView iv_icon = cview.findViewById(R.id.iv_icon);
try {
if (list_shareofshelf.get(listPosition).getGroupFocAll().get(expandedListPosition).getIcon_name() != null &&
!list_shareofshelf.get(listPosition).getGroupFocAll().get(expandedListPosition).getIcon_name().isEmpty()) {
int imageid = context.getResources().getIdentifier(list_shareofshelf.get(listPosition).getGroupFocAll().get(expandedListPosition).getIcon_name(), "drawable", context.getPackageName());
iv_icon.setImageResource(imageid);
} else {
iv_icon.setImageResource(R.drawable.ic_gray_no_img);
}
} catch (Exception e) {
iv_icon.setImageResource(R.drawable.ic_gray_no_img);
}
if (list_shareofshelf.get(listPosition).getGroupFocAll().get(expandedListPosition).getIncome_Expenses().equalsIgnoreCase("Expenses")) {
tv_expense.setText("-" + list_shareofshelf.get(listPosition).getGroupFocAll().get(expandedListPosition).getAmount());
} else {
tv_expense.setText(list_shareofshelf.get(listPosition).getGroupFocAll().get(expandedListPosition).getAmount());
}
child_container.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!list_shareofshelf.get(listPosition).getGroupFocAll().get(expandedListPosition).getId().isEmpty()) {
Intent i = new Intent(context, ExpenseDetails.class);
i.putExtra("trans_id", list_shareofshelf.get(listPosition).getGroupFocAll().get(expandedListPosition).getId());
context.startActivity(i);
}
}
});
if (!list_shareofshelf.get(listPosition).getGroupFocAll().get(expandedListPosition).getMemo().isEmpty()) {
tv_category.setText(list_shareofshelf.get(listPosition).getGroupFocAll().get(expandedListPosition).getMemo());
} else {
tv_category.setText(list_shareofshelf.get(listPosition).getGroupFocAll().get(expandedListPosition).getCategory());
}
if (expandedListPosition == list_shareofshelf.get(listPosition).getGroupFocAll().size() - 1) {
child_container.setBackgroundResource(R.drawable.card_bottom_round);
}
return cview;
}
@Override
public int getChildrenCount(int listPosition) {
return list_shareofshelf.get(listPosition).getGroupFocAll().size();
}
@Override
public Object getGroup(int listPosition) {
return list_shareofshelf.get(listPosition).getGroupFocAll();
}
@Override
public int getGroupCount() {
return list_shareofshelf.size();
}
@Override
public long getGroupId(int listPosition) {
return listPosition;
}
@Override
public View getGroupView(int listPosition, boolean isExpanded, View convertView, ViewGroup parent) {
LayoutInflater layoutInflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(R.layout.list_parent_sos, null);
ExpandableListView eLV = (ExpandableListView) parent;
eLV.expandGroup(listPosition);
TextView listTitleTextView = view.findViewById(R.id.listTitle);
TextView tv_expenditures = view.findViewById(R.id.tv_expenditures);
listTitleTextView.setText(Utils.getFormattedDate(list_shareofshelf.get(listPosition).getDate()));
tv_expenditures.setText("Expenses: " + list_shareofshelf.get(listPosition).getExp_amt_() + " Income: " + list_shareofshelf.get(listPosition).getInc_amt_());
return view;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int listPosition, int expandedListPosition) {
return true;
}
@Override
public void registerDataSetObserver(DataSetObserver observer) {
super.registerDataSetObserver(observer);
}
}
MainActivity 调用...
private class AsyncTaskGetTransactionData extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... voids) {
list_final_transaction_data = db.getTransactionDetails(current_month);
return null;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
if (list_final_transaction_data.size() > 0) {
expandableListAdapter = new TransExpAdapter(context, list_final_transaction_data);
expandableListView.setAdapter(expandableListAdapter);
expandableListView.setVisibility(View.VISIBLE);
new AsyncTaskSummationExpenses().execute();
} else {
tv_income.setText("0");
tv_expenses.setText("0");
tv_balance.setText("0");
p.dismiss();
expandableListView.setVisibility(View.GONE);
}
}
}
////数据库方法
public List<ExcelDataModel> getTransactionDetails(String current_month) {
List<ExcelDataModel> listProd = new ArrayList<>();
Log.d("CurrentMonthDB", current_month);
SQLiteDatabase db = this.getWritableDatabase();
try {
String selectQuery = "select f.date,(select sum(amount) from tbl_transactions WHERE trans_type='Expenses' and date=f.date)exp, " +
"(select sum(amount) from tbl_transactions where trans_type='Income' and date=f.date)inc from tbl_transactions f where f.date like '%" + current_month + "%' GROUP by f.date ORDER BY strftime('%s', f.date) desc";
Log.d("FirstQuery", selectQuery);
Cursor c = db.rawQuery(selectQuery, null);
if (c.moveToFirst()) {
do {
ExcelDataModel foc_cat = new ExcelDataModel();
String date = c.getString(c.getColumnIndex("date"));
String income = c.getString(c.getColumnIndex("inc"));
String expense = c.getString(c.getColumnIndex("exp"));
String selectQuery1 = "select * from tbl_transactions a LEFT join tbl_category b where a.cat_id=b.cat_id and date='" + date + "' order by memo asc";
Log.d("SecondQuery", selectQuery1);
Cursor cursor2 = db.rawQuery(selectQuery1, null);
if (cursor2.moveToFirst()) {
List<ExcelDataModel> subCat_list = new ArrayList<>();
// ExcelDataModel pp_dummy = new ExcelDataModel();
//pp_dummy.setId("");
// subCat_list.add(pp_dummy);
do {
ExcelDataModel prod_subcat = new ExcelDataModel();
prod_subcat.setDate(cursor2.getString(cursor2.getColumnIndex("date")));
prod_subcat.setIncome_Expenses(cursor2.getString(cursor2.getColumnIndex("trans_type")));
prod_subcat.setCategory(cursor2.getString(cursor2.getColumnIndex("cat_name")));
prod_subcat.setMemo(cursor2.getString(cursor2.getColumnIndex("memo")));
prod_subcat.setAmount(cursor2.getString(cursor2.getColumnIndex("amount")));
prod_subcat.setId(cursor2.getString(cursor2.getColumnIndex("trans_id")));
prod_subcat.setIcon_name(cursor2.getString(cursor2.getColumnIndex("cat_iconname")));
subCat_list.add(prod_subcat);
} while (cursor2.moveToNext());
foc_cat.setDate(date);
if (expense != null) {
foc_cat.setExp_amt_(Double.parseDouble(expense));
} else {
foc_cat.setExp_amt_(0);
}
if (income != null) {
foc_cat.setInc_amt_(Double.parseDouble(income));
} else {
foc_cat.setInc_amt_(0);
}
foc_cat.setDate(date);
foc_cat.setGroupFocAll(subCat_list);
listProd.add(foc_cat);
cursor2.close();
}
} while (c.moveToNext());
}
c.close();
db.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (db != null)
db.close();
}
return listProd;
}
最佳答案
尝试在子项的 OnClick()
上使用回调并在 Activity 中捕获该回调,这样您就可以执行 startActivityForResult()
而不仅仅是 startActivity()
.
这样您就可以知道用户何时删除了详细信息 Activity 中的某些内容,即在该 Activity 被销毁之后。然后,在 onActivityResult
中执行 yourAdapter.notifyDataSetChanged();
像这样,在适配器中:
child_container.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!list_shareofshelf.get(listPosition).getGroupFocAll().get(expandedListPosition).getId().isEmpty()) {
callback.childClicked(list_shareofshelf.get(listPosition).getGroupFocAll().get(expandedListPosition).getId());
}
}
});
然后,在您的 Activity 中,您实现回调
@Override
public void childClicked(int id){
Intent i = new Intent(context, ExpenseDetails.class);
i.putExtra("trans_id", id);
startActivityForResult(i, yourRequestCode);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable
Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == yourRequestCode) {
if (resultCode == RESULT_DELETED) {
adapter.notifyDataSetChanged();
}
}
}
关于android - ExpandableListView- 更新或删除特定行而不调用 Activity 中的适配器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57820181/
我只是想知道Mvvmmcross框架中是否潜藏着ExpandableListViews或与之相似的功能,还是这种控件不适用于多平台要求。 的功能在 http://deapsquatter.blogsp
我想知道是否可以将一个 ExpandableListView 作为另一个 ExpandableListView 的一个元素的一个子元素。谢谢 最佳答案 是的。可以在可扩展 ListView 中创建可扩
现在我想使用 ExpandableListView 来显示我的数据,我想更改项目左侧的图标或让它消失。有人可以给我一个建议吗。 谢谢。 最佳答案 setGroupIndicator(null) 应该让
我在 expandablelistview 子项目中有一个 edittext。然后,我在这个 edittext 中输入了一个文本,但是每当我点击其他 expandablelistview 标题时,我输
我正在尝试弄清楚如何构建包含(许多)的 View : PARENT1(可勾选、可扩展) CHILD1(单选按钮) CHILD2(单选按钮) ... PARENT2(可勾选、可扩展) CHILD1(可检
所以我刚刚进入了 ExpandableListView 领域,并希望在 DrawerLayout 中制作一个只有一组和 3 个 child 的简单列表 这是我的适配器代码: public cl
我是 Android 开发新手。我关注了this显示 ExpandableListView 及其正常工作的教程。如果我按所有组,那么所有组都会展开。 我一次只想扩展一组。一开始,第一个组将自动展开,如
我是 Android 新手。我想创建一个可扩展的 ListView,其中 1 行具有必须在 manin 线程中指定的自定义信息,而不是在布局中进行硬编码。 我想要一个图像和 2 个 TextView
我的应用程序中有一个 ExpandableListView。我想让子布局比组标题窄一点,并保持居中。由于一些视觉效果,我必须从代码中设置布局参数,但是我似乎找不到最好的解决方案,尝试从 xml 更
我正在将 JSON 解析为 ExpandableListView,在每个子项上,用户可以选择他想要拥有的 +/- 按钮的每个子项的数量。 +/- 按钮连接到 TextView,其中显示每个子项的总金额
我希望我的团队能够在第一时间扩大。然后它应该像往常一样运行(单击指示器后折叠/展开) 我找不到解决此问题的任何有效解决方案。 最佳答案 循环遍历所有组并使用expandGroup()您的 Expand
我正在编写一个 Android 应用程序,我决定使用可扩展 ListView 。我拥有所需的一切,列表工作正常,但是当我填充它时,组的顺序似乎与应有的顺序不同,这是一个示例: 如您所见,子值很好,只有
我在组项目的 ExpandableListView 中添加了 EditText,之后当我单击组项目时,不会出现包含子项目的列表。可能是什么问题?在这种情况下,这个列表是否可以扩展?或者禁止在Expan
当我单击组 View 时,可扩展列表的顺序会发生变化 我发现有人有类似的问题 here 顺序似乎是随机的,我不明白发生了什么。 这是我的代码,我知道它很乱,我已经重写了很多次。 public clas
我是 Android 编程的新手,我一直在思考如何做到这一点……我想创建一个 ExpandableListView,其中包含相同的子项 XML(包含添加、编辑和删除按钮)填充在所有组项目中。 有人可以
我在 Android 抽屉导航中使用 ExpandableListsViews 而不是菜单。而 OnExpandlistner 我正在改变背景颜色。前两个项目表现正常,它们的背景颜色发生了变化。但最后
我对 ExpandableListView 有疑问:在我的应用程序中,我使用了 ExpandableListView 并用我的适配器填充它“类 MyExpandableListAdapter 扩展了
我正在使用 Fedor 的适配器和图像加载器将图像延迟加载到可扩展 ListView 中。 ( Lazy load of images in ListView ) 它运行良好,但有一个问题。仅当 Im
关注this教程我能够制作一个大致这样布局的 View : Group1 child1 child2 group2 child1 child2 但是我想要更多的嵌套: grou
Blockquote 我在 android 中使用 ExpandableListView 这是适配器类中getChildView的代码: @Override public View g
我是一名优秀的程序员,十分优秀!