Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
218 views
in Technique[技术] by (71.8m points)

android - Delete group in Expandable List

I am trying to delete Group when selected in my Expandable List and having the list refreshed after the delete occurred.

I took the source code from google:

http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/ExpandableList1.html

I tried a couple of ways to delete it, but no success, anyone achieved that already?

Thanks, ray.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Answer for the second question (Add rows to a child & datastructure)

For the Datastructure:

public class GroupItem {
 private String mItemText;
 private List<ChildItem> mChildItems=new ArrayList<ChildItem>();    

 public GroupItem(String itemText) {
  mItemText=itemText;
 }

 public String getItemText() {
  return mItemText;
 }

 public ChildItem getChild(int childPosition) {
  return mChildItems.get(childPosition);
 }

 public void addChild(ChildItem childItem) {
  return mChildItems.add(childItem)
 }

 public void removeChild(int childPosition) {
  return mChildItems.remove(childPosition);
 }

}

public class ChildItem {
 private String mItemText;
 public ChildItem(itemText) {
  mItemText=itemText;
 }

 public String getItemText() {
  return mItemText;
 }
}

Now to set it up you would do something like:

List<GroupItem> items = new ArrayList<GroupItem>();

GroupItem item1 = new GroupItem("This is group 1");
item1.addChild(new ChildItem("This is a child item of group 1"));
item1.addChild(new ChildItem("This is another child item of group 1"));

and so on...

Then, in the Adapter you would need to return the appropriate data.

For your question concerning rows: In your Google example, they return a TextView. You can however make your own Layout with whatever content you like. For example:

<ImageView android:id="@+id/RowIcon" 
  android:layout_width="56px" 
  android:layout_height="56px" 
  android:layout_marginLeft="12px" 
  android:layout_marginTop="2px">
</ImageView>
<TextView android:id="@+id/RowTextView"
     android:paddingLeft="10px"
     android:paddingTop="10px"       
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" android:textColor="#666666" android:textSize="14px"/>


</LinearLayout>

And then use this Layout in your Adapter. Instead of returning, say, a TextView, you'll just return this as a View:

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

LayoutInflater mInflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = mInflater.inflate(YOUR XML FILE FROM ABOVE, null);
    ImageView rowIcon = (ImageView)rowView.findViewById(R.id.RowIcon);
    iconType.setBackgroundResource(AN IMAGE HERE);
    TextView rowText =(TextView)rowView.findViewById(R.id.RowTextView);
    textAddress.setText(items.get(groupPosition).getChild(childPosition));

    return rowView;
 }

So, i think that should get you going.

Also, please accept my answers if they satisfy you.

Cheers.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...