首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >getGroupView设置项类似于安卓项目中的Simple_Expandable_List_item

getGroupView设置项类似于安卓项目中的Simple_Expandable_List_item
EN

Stack Overflow用户
提问于 2013-05-17 16:29:53
回答 2查看 362关注 0票数 0

我正在做Android项目。现在我必须创建我自己的可扩展列表。这是我遵循的解决方案:

link to source code of expandable list that I am working on

这是生成TextView的代码(它是列表中的元素)。我想创建的东西,而不是这个项目,像android.R.layout.simple_expandable_list_item TextView。我的意思是把一些图片放在左边,然后是文本。我怎么能做到这一点?

我试过使用Button和but图标on Button,但是没有用。按钮不会展开/折叠我的列表。

代码语言:javascript
复制
 @Override
              public View getGroupView(int groupPosition, boolean isExpanded,
                           View convertView, ViewGroup parent) {
                     TextView tv = new TextView(Vincent_ThreeelevellistActivity.this);
                     tv.setText("->FirstLevel");
                     tv.setTextColor(Color.BLACK);
                     tv.setTextSize(20);
                     tv.setBackgroundColor(Color.BLUE);
                     tv.setPadding(10, 7, 7, 7);
                     return tv;

              }
EN

回答 2

Stack Overflow用户

发布于 2013-05-17 16:48:00

您需要像这样使用。这段代码只是一个例子。请不要更改参数并相应地实现代码。

代码语言:javascript
复制
@Override
       public View getGroupView(int position, View convertView, ViewGroup parent) {   

       ViewHolder holder = null;
       TextView title = null;
       TextView detail = null;
       ImageView i11=null;
       RowData rowData= getItem(position);
       if(null == convertView){
            convertView = mInflater.inflate(R.layout.list, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
 }
             holder = (ViewHolder) convertView.getTag();
             title = holder.gettitle();
             itle.setText(rowData.mTitle);
             detail = holder.getdetail();
             detail.setText(rowData.mDetail);                                                     

             i11=holder.getImage();
             i11.setImageResource(imgid[rowData.mId]);
             return convertView;
}
            private class ViewHolder {
            private View mRow;
            private TextView title = null;
            private TextView detail = null;
            private ImageView i11=null; 

            public ViewHolder(View row) {
            mRow = row;
 }
         public TextView gettitle() {
             if(null == title){
                 title = (TextView) mRow.findViewById(R.id.title);
                }
            return title;
         }     

         public TextView getdetail() {
             if(null == detail){
                  detail = (TextView) mRow.findViewById(R.id.detail);
                    }
           return detail;
         }
        public ImageView getImage() {
             if(null == i11){
                  i11 = (ImageView) mRow.findViewById(R.id.img);
                                      }
                return i11;
        }
     }
票数 0
EN

Stack Overflow用户

发布于 2013-05-17 16:49:39

你的问题不是很清楚。然而,根据我的理解,这是我的解决方案。

Option1 :您可以在xml中创建自定义布局,然后将其膨胀并从getGroupView返回。

Option2 :你可以为你的文本视图项设置一个compoundDrawable,这样它就会在它旁边显示一个图片。

如果您想要自定义向下箭头标记,您可以为可展开的列表视图设置android:groupIndicator。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16604685

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档