1

我需要在可扩展的列表视图中实现字母分隔符。我已经尝试过以下事情。我将文本视图保持为不可见。仅当可扩展列表的组视图中的项目以新字母开头时才应显示。以下代码在意外位置显示分隔符。请帮忙。

mAdapter = new SimpleExpandableListAdapter(this, groupDataCat,
                    R.layout.word_list_item, new String[] { WORD },
                    new int[] { R.id.tvWord }, childDataCat,
                    R.layout.meaning_list_item, new String[] { MEANING },
                    new int[] { R.id.tvMeaning }){



            @Override
            public View getChildView(int groupPosition,
                    int childPosition, boolean isLastChild,
                    View convertView, ViewGroup parent) {
                TextView tv =  (TextView) super.getChildView(groupPosition, childPosition, isLastChild,convertView, parent);
                tv.setTypeface(Typeface.createFromAsset(WordListActivity.this.getAssets(), "roboto_regular.ttf"));
                return tv;
            }

            @Override
                    public View getGroupView(int groupPosition,
                            boolean isExpanded, View convertView,
                            ViewGroup parent) {
                        RelativeLayout rl = (RelativeLayout) super.getGroupView(groupPosition, isExpanded, convertView, parent);
                        TextView tv=(TextView) rl.findViewById(R.id.tvWord);
                        TextView sep=(TextView) rl.findViewById(R.id.separator);
                        Log.d("amitgroup",""+tv.getText().toString().charAt(0));
                        if (tv.getText().toString().charAt(0) != lastChar){
                            sep.setVisibility(View.VISIBLE);
                        }
                        lastChar = tv.getText().toString().charAt(0);
                        tv.setTypeface(Typeface.createFromAsset(WordListActivity.this.getAssets(), "roboto_regular.ttf"));
                        return rl;
                    }

        };
4

0 回答 0