2

常に最後の子の位置に静的な EditText を動的に追加するのに問題があります。私のアダプターはタイプの JSON オブジェクトを使用します。ExpandableListView グループの子を初めて展開すると、EditText の正しい位置を見つけることができますが、子を反対方向にスクロールすると、EditText の位置が絶えず変化します。これは私のEditextレイアウトです:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_height="wrap_content" 
 android:layout_width="fill_parent" 
 android:orientation="vertical" 
 android:paddingLeft="10dip"
 android:paddingRight="10dip"
 android:background="@color/lgray">
<RelativeLayout android:id="@+id/feedcell_addcomment" android:paddingLeft="10dip" android:paddingRight="10dip" android:paddingTop="5dip" android:paddingBottom="5dip" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="1dip" android:background="@color/mlgray" >


    </RelativeLayout>
</LinearLayout>

これは私のchildLayout.xmlです

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layoutchildren" android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="vertical" android:paddingLeft="10dip" android:paddingRight="10dip" android:background="@color/lgray">
    <RelativeLayout   android:paddingLeft="10dip" android:paddingRight="10dip" android:background="@color/white" android:layout_height="45dip" android:layout_width="fill_parent" android:layout_marginBottom="2dip">
        <ImageView android:id="@+id/feedcommentcell_profileimg" android:layout_width="32dip" android:layout_height="32dip" android:layout_centerVertical="true" android:scaleType="fitXY"/>
        <TextView android:id="@+id/feedcommentcell_username" android:textStyle="bold" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="13sp" android:textColor="@color/black" android:layout_toRightOf="@+id/feedcommentcell_profileimg" android:layout_marginLeft="10dip" android:layout_alignTop="@+id/feedcommentcell_profileimg"/>
        <TextView android:id="@+id/feedcommentcell_comment" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="11sp" android:textColor="@color/black" android:layout_toRightOf="@+id/feedcommentcell_profileimg" android:layout_marginLeft="10dip" android:layout_below="@+id/feedcommentcell_username"/>
        <TextView android:id="@+id/feedcommentcell_scanhour" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="10sp" android:textColor="@color/dgray" android:layout_alignParentRight="true" android:layout_alignBottom="@+id/feedcommentcell_username"/>
        </RelativeLayout>
</LinearLayout>

これは私のアダプタの getChildView です

 @Override
        public View getChildView(int groupPosition, int childPosition, boolean isLastChild,View convertView, ViewGroup parent)
        {

            int type=getItemViewType(groupPosition,childPosition);
            View v = convertView;
            LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            if (v == null)
            {

                switch(type)
                {

                    case TYPE_CHILD:

                        v = vi.inflate(R.layout.feedcommentcell, null);

                        break;

                    case TYPE_EDIT:

                        v = vi.inflate(R.layout.edittextcommentlist, null);
                        break;
                }

            }

            try
            { 
                if(type == TYPE_CHILD)
                {
                    JSONObject o = getChild(groupPosition,childPosition);
                        //JSONObject o = itemsChildren.get(childPosition);
                    if(o!=null)
                    {
                        TextView commentUser=(TextView)v.findViewById(R.id.feedcommentcell_username);
                        commentUser.setText(o.getString("username"));

                        String shareMessageId= o.getString("ShareMessageId");
                        o.put("ShareMessageId", shareMessageId);

                        TextView commentText=(TextView)v.findViewById(R.id.feedcommentcell_comment);
                        commentText.setText(o.getString("Message"));

                        TextView commentScanHour=(TextView)v.findViewById(R.id.feedcommentcell_scanhour);
                        commentScanHour.setText(o.getString("timestamp"));

                        ImageView commentImg=(ImageView)v.findViewById(R.id.feedcommentcell_profileimg);
                        String imgurl=o.getString("userimage");
                        if(imgurl!=null && imgurl!="")
                        imageLoader.DisplayImage(imgurl, context, commentImg);

                    }

                }
                else if(type==TYPE_EDIT)
                {
                    //JSONObject o = getChild(groupPosition,childPosition);
                    JSONObject o = itemsChildren.get(childPosition);


                        o.put("edit", "false");
                        v = vi.inflate(R.layout.edittextcommentlist, null);

                    //EditText edit = (EditText) v.findViewById(R.id.feedcell_edittxt);


                }




            }
            catch(Exception e)
            {}


            return v;
        }

そして、これらは他のオーバーライド メソッドです。getGroupView とそのレイアウトは表示されません。適切に機能するためです。

    @Override
         public JSONObject getChild(int groupPosition, int childPosition) {
                return itemsChildren.get(childPosition);
            }

        @Override
        public long getChildId(int groupPosition, int childPosition) {
                return childPosition;
            }

        @Override
        public boolean areAllItemsEnabled()
        {
            return true;
        }
        @Override
        public int getChildrenCount(int groupPosition) {

            return itemsChildren.size();
        }

        @Override
        public JSONObject getGroup(int groupPosition) {
            return itemsGroup.get(groupPosition);
        }

        @Override
        public int getGroupCount() {
            return itemsGroup.size();
        }

        @Override
        public long getGroupId(int groupPosition) {
            return groupPosition;
        }
        @Override
        public boolean hasStableIds() {
            return true;
        }

        @Override
        public boolean isChildSelectable(int arg0, int arg1) {
            return true;
        }

        public boolean isTextView(int groupPosition,int childPosition)
        {
            JSONObject jo=new JSONObject();
            jo = getChild(groupPosition,childPosition);
            boolean result =false;
            try
            {
                String isEdit=jo.getString("edit");
                if(isEdit.equalsIgnoreCase("true"))
                    result=true;

            }
            catch(Exception e){}
            return result;

        }

        public int getItemViewType(int groupPosition,int childPosition) 
        {
            //JSONObject jo=getChild(groupPosition,childPosition);


            if(isTextView(groupPosition,childPosition))
                return TYPE_EDIT;
            else
                return TYPE_CHILD;
        }

すべてが良いようですが、editText は毎回位置を変更します...誰かがいくつかの解決策を持っていますか?ありがとう

4

2 に答える 2

0

isLastChildは正しく動作しないため、次の操作を実行できます。

@Override
public View getChildView(int groupPosition, int childPosition, 
      boolean isLastChild, View convertView, ViewGroup parent)
{
      ...

      if (childPosition == itemsGroup.get(groupPosition).size() - 1) {
           // This gives you confirmation that is the last child in the group
      }
}
于 2013-03-17T23:36:34.050 に答える
0

I have the same problem with my ExpandableList... The main problem here is with lastChild property. You see, on creation, the last child of the group list is the one we think it is, but on scroll opposite, your list is refreshing so next last child is next which you can't see on opposite, or if you go back down, last one you can't see. This is pretty much stupid if you ask me but there is no right solution for this...

于 2013-01-17T01:16:16.767 に答える