- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我根据要编辑的editText的结果,得到Expandable List里面的editText为childcount的个数。但 editText 位置总是不同或 childcount 出错,我收到此错误:
("java.lang.IndexOutOfBoundsException: Invalid index 3, size is 3")
我的 ExpandableListAdapter:
public class ExpandableListAdapter extends BaseExpandableListAdapter {
public ExpandableListView expandableListView;
private ChildViewHolder childViewHolder;
private GroupViewHolder groupViewHolder;
private Context _context;
private ArrayList<BBQrValidateModel.Campaigns> mDataCampaignModel; //stampcount and totalneed
public ExpandableListAdapter(ArrayList<BBQrValidateModel.Campaigns> mDataCampaignModel,
Context context, ExpandableListView expandableListView) {
this._context = context;
this.mDataCampaignModel = mDataCampaignModel;
this.expandableListView = expandableListView;
}
@Override
public Object getChild(int groupPosition, int childPosititon) {
return campaign.coffeeGiftCount;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
BBQrValidateModel.Campaigns campaign = mDataCampaignModel.get(groupPosition);
if (convertView == null) {
convertView = MainActivity.inflater.inflate(R.layout.row_campaign_buy_or_hide, parent, false);
childViewHolder = new ChildViewHolder();
childViewHolder.txtCoffeeGift = convertView.findViewById(R.id.txtCoffeeGift);
childViewHolder.txtCoffeeHide = convertView.findViewById(R.id.txtCoffeeHide);
childViewHolder.txtCoffeeUse = convertView.findViewById(R.id.txtCoffeeUse);
convertView.setTag(childViewHolder);
} else {
childViewHolder = (ChildViewHolder) convertView.getTag();
}
childViewHolder.txtCoffeeGift.setText(campaign.prize);
//kullan ve sakla tıklanınca modeldekı degısıklıgı buradan yapıcaz
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
BBQrValidateModel.Campaigns campaign = mDataCampaignModel.get(groupPosition);
return campaign.coffeeGiftCount;
}
@Override
public Object getGroup(int groupPosition) {
return mDataCampaignModel.get(groupPosition);
}
@Override
public int getGroupCount() {
return (mDataCampaignModel == null) ? 0 : mDataCampaignModel.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(final int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
final BBQrValidateModel.Campaigns campaign = mDataCampaignModel.get(groupPosition);
if (convertView == null) {
convertView = MainActivity.inflater.inflate(R.layout.row_campaigndetail, parent, false);
groupViewHolder = new GroupViewHolder();
groupViewHolder.txtStampCount = convertView.findViewById(R.id.txtStampCount);
groupViewHolder.txtCampaignName = convertView.findViewById(R.id.txtCampaignName);
groupViewHolder.txtTotalNeeds = convertView.findViewById(R.id.txtTotalNeeds);
groupViewHolder.btnFreepProductNum1 = convertView.findViewById(R.id.btnFreepProductNum1);
groupViewHolder.btnFreepProductNum2 = convertView.findViewById(R.id.btnFreepProductNum2);
groupViewHolder.btnFreepProductNum3 = convertView.findViewById(R.id.btnFreepProductNum3);
groupViewHolder.btnFreepProductNum4 = convertView.findViewById(R.id.btnFreepProductNum4);
groupViewHolder.btnFreepProductNum5 = convertView.findViewById(R.id.btnFreepProductNum5);
groupViewHolder.edtPurchasedCoffeeCount = convertView.findViewById(R.id.edtPurchasedCoffeeCount);
convertView.setTag(groupViewHolder);
} else {
groupViewHolder = (GroupViewHolder) convertView.getTag();
}
groupViewHolder.edtPurchasedCoffeeCount.setId(groupPosition);
groupViewHolder.txtTotalNeeds.setText(String.valueOf(campaign.totalNeeds));
groupViewHolder.txtStampCount.setText(String.valueOf(campaign.stampCount));
groupViewHolder.txtCampaignName.setText(campaign.description);
if (groupViewHolder.edtPurchasedCoffeeCount.getText().toString().isEmpty()) {
campaign.edtPurchasedCoffeeCount = 0;
} else {
campaign.edtPurchasedCoffeeCount = Integer.valueOf(groupViewHolder.edtPurchasedCoffeeCount
.getText().toString());
}
final int totalneeds = campaign.totalNeeds;
final int stampcount = campaign.stampCount;
campaign.coffeeGiftCount = (stampcount + campaign.edtPurchasedCoffeeCount) / totalneeds;
TextWatcher inputTextWatcher = new TextWatcher()
{
public void onTextChanged(CharSequence s, int start, int before, int count)
{
if (stampcount + campaign.coffeeGiftCount > totalneeds)
{
campaign.coffeeGiftCount = (stampcount + campaign.edtPurchasedCoffeeCount) / totalneeds;
}
}
public void beforeTextChanged(CharSequence s, int start, int count, int after)
{
}
public void afterTextChanged(Editable s)
{
notifyDataSetChanged();
}
};
groupViewHolder.edtPurchasedCoffeeCount.addTextChangedListener(inputTextWatcher);
expandableListView.expandGroup(groupPosition);
return convertView;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return false;
}
我的 ViewHolders(适配器中的内部类):
public final class GroupViewHolder {
TextView txtStampCount;
TextView txtCampaignName;
TextView txtTotalNeeds;
EditText edtPurchasedCoffeeCount;
Button btnFreepProductNum1;
Button btnFreepProductNum2;
Button btnFreepProductNum3;
Button btnFreepProductNum4;
Button btnFreepProductNum5;
}
public final class ChildViewHolder {
TextView txtCoffeeGift;
TextView txtCoffeeUse;
TextView txtCoffeeHide;
}
}
最佳答案
在 getChild 方法中你返回 0 意味着你没有那个 child 的任何子对象,你应该返回那个位置的子对象的组数据。
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Context _context;
private List<String> _listDataHeader; // header titles
// child data in format of header title, child title
private HashMap<String, List<String>> _listDataChild;
public ExpandableListAdapter(Context context, List<String> listDataHeader,
HashMap<String, List<String>> listChildData) {
this._context = context;
this._listDataHeader = listDataHeader;
this._listDataChild = listChildData;
}
@Override
public Object getChild(int groupPosition, int childPosititon) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.get(childPosititon);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String childText = (String) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_item, null);
}
EditText edtListChild = (EditText) convertView
.findViewById(R.id.lblListItem);
txtListChild.setText(childText);
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.size();
}
@Override
public Object getGroup(int groupPosition) {
return this._listDataHeader.get(groupPosition);
}
@Override
public int getGroupCount() {
return this._listDataHeader.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_group, null);
}
TextView lblListHeader = (TextView) convertView
.findViewById(R.id.lblListHeader);
lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setText(headerTitle);
return convertView;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
这段代码对你有帮助,对我也有帮助。
关于expandableList 中的 android editText 错误索引和错误计数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46534905/
我正在关注本教程:ExpandableListView 但在我的设备(Samsung Galaxy S i9000)中,文本与可扩展图标重叠,如图所示。 我怎样才能避免这种情况?谢谢 最佳答案 这个例
我希望在长按 ExpandableList 时为每个组创建一个菜单。但目前只有非空组在长按时显示蓝色背景并且可以选择。所有空组都不会对长按使用react。 我使用 registerForContext
我正在尝试显示一个多深度的可扩展列表。也就是说,我们有一个表头 ID |学校 |年级 |姓名 我想展示一个可扩展的列表学校 - 年级 - 姓名 学校是第一个深度,等级是第二个深度,名字是叶节点。我了解
我有一个 expandableList,在子元素中我添加了一些 EditText、复选框和微调器。这些已正确创建和显示。选中复选框后会显示其他 EditText 和微调器,然后用户可以添加文本并从微调
问题很简单,但我做不出来。我有一个带有 3 个标题的可扩展列表,它们可以是填充的也可以是空的。 我希望在您展开一个空的组时显示一个简单的 TextView ,我已经找了一段时间但似乎没有任何效果。我不
每个组 View 我只有 1 个 subview ,它是从布局 .xml 文件扩展而来的。我希望为 subview 设置动画,以便在显示子项时,其下方的列表项向下滑动。我尝试了一些动画,但问题是首先使
我正在尝试个性化 ExpandableLisTview 我创造 Iterator.Xml:带有 ExpandableList View group.xml:具有简单 TextView 和 Button
我正在创建使用可扩展列表 View 的android应用,每个子项都包括图像 View 和扩展了 BaseExpandableAdapter 的文本。 图像在可绘制的forlder中,我使用数组检索它
我一直在使用自定义的 ExpandableList(参见下面的示例图片),其中每个项目始终有一个子项。这个 child 由三部分组成。每个部分都有一个标题(红色条),下面是一个空项目或项目列表。此列表
这个问题可能很菜鸟,但我就是找不到正确的解决方案。 所以这是我的问题: 我想在多个 ExpandableLists(比如说 5 个)中显示数据(一个 java.util.List 和我的 TaskOb
我只想一次展开父列表中的一项,目前我的 onCreate 代码如下。 (按我的意愿工作,但是一次只允许一个父打开的方法不起作用) public void onCreate(Bundle savedIn
我根据要编辑的editText的结果,得到Expandable List里面的editText为childcount的个数。但 editText 位置总是不同或 childcount 出错,我收到此错
这是我的 XML 布局文件,我正在使用 chrisbanes pull 来刷新库 here 出于某种原因,它只会显示可点击项目的可展开列表中的第一
我有关于 onChildClickListener 的代码,如下面的代码 fragment OnChildClickListener occl = new OnChildClickListener()
如何折叠 Expandable List 中的所有 ChildView 组。现在我有两个按钮来控制 Activity 上的全部展开和全部折叠。可扩展按钮没问题,它正在工作,但我不知道如何折叠所有 Ch
我想从 SQLite 数据库获取数据并通过 SimpleCursorTreeAdapter 填充我的 ExpandableListView,但它在某些地方失败了。我真的找不到问题所在,甚至不知道异常发
我是一名优秀的程序员,十分优秀!