2011-05-04 86 views
0

任何人都可以帮助我创建一个可扩展的视图像android市场中的更多按钮吗? 当我们点击更多按钮将扩大约在Android Market的地方应用的详细信息视图..如何在android中创建Expandable布局?

任何帮助将不胜感激..

感谢

Sathish所在

回答

0

也许最好的实现方法是使用ArrayAdapter。当您点击更多按钮获取更多数据并使用addAll()方法将所有新提取的数据添加到适配器。 addAll()会自动将更改传播到ListView,因此不用费力地通知它。

+0

感谢观看快速回复,但我想创建一个不仅有文本,一些按钮和链接以及其他edittext字段的视图。那么我怎么能做到这一点? – sathish 2011-05-04 14:09:08

1

我一直在做类似的事情。

在它看起来像这样在多/少栏模式的时刻:more/less view layout

它仍然是一个进展中的工作,但该项目,源可以here

0
public class ModifiedExpandableList extends Activity { 

    ExpandableListAdapter mAdapter; 
    private ExpandableListView mExpandableListView; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main_copy); 
     // set our list 
     mExpandableListView = (ExpandableListView)findViewById(R.id.list); 
     // Set up our adapter 
     mAdapter = new MyExpandableListAdapter(this); 
     mExpandableListView.setAdapter(mAdapter); 
     // Need no icon as of now 
     mExpandableListView.setGroupIndicator(null); 
     registerForContextMenu(mExpandableListView); 
    } 

    @Override 
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { 
     menu.setHeaderTitle("Sample menu"); 
     menu.add(0, 0, 0,"dd"); 
    } 

    @Override 
    public boolean onContextItemSelected(MenuItem item) { 
     ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item.getMenuInfo(); 

     String title = ((TextView) info.targetView).getText().toString(); 

     int type = ExpandableListView.getPackedPositionType(info.packedPosition); 
     if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) { 
      int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition); 
      int childPos = ExpandableListView.getPackedPositionChild(info.packedPosition); 
      Toast.makeText(this, title + ": Child " + childPos + " clicked in group " + groupPos, 
        Toast.LENGTH_SHORT).show(); 
      return true; 
     } else if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) { 
      int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition); 
      Toast.makeText(this, title + ": Group " + groupPos + " clicked", Toast.LENGTH_SHORT).show(); 
      return true; 
     } 

     return false; 
    } 

    /** 
    * A simple adapter which maintains an ArrayList of photo resource Ids. 
    * Each photo is displayed as an image. This adapter supports clearing the 
    * list of photos and adding a new photo. 
    * 
    */ 
    public class MyExpandableListAdapter extends BaseExpandableListAdapter { 

     Context mContext; 
     public MyExpandableListAdapter(Context context){ 
      this.mContext = context; 
     } 

     // Sample data set. children[i] contains the children (String[]) for groups[i]. 
     private String[] groups = { "People Names", "Dog Names", "Cat Names", "Fish Names" }; 
     private String[][] children = { 
       { "Arnold", "Barry", "Chuck", "David" }, 
       { "Ace", "Bandit", "Cha-Cha", "Deuce" }, 
       { "Fluffy", "Snuggles","ddef","afadsfasf" }, 
       { "Goldy", "Bubbles","sfef","dafs" } 
     }; 

     public Object getChild(int groupPosition, int childPosition) { 
      return children[groupPosition][childPosition]; 
     } 

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

     public int getChildrenCount(int groupPosition) { 
      int result=4; 

      return result; 
     } 

     public View getChildView(int groupPosition, int childPosition, boolean isLastChild, 
       View convertView, ViewGroup parent) { 
      View v = null; 
      // changed here 
       LayoutInflater li = ModifiedExpandableList.this.getLayoutInflater(); 
       v = li.inflate(R.layout.child_view,null); 
       TextView tv = (TextView)v.findViewById(R.id.TextView01); 
       tv.setText(getChild(groupPosition, childPosition).toString()); 
       ImageView im = (ImageView)v.findViewById(R.id.ImageView01); 
       im.setBackgroundDrawable(ModifiedExpandableList.this.getResources().getDrawable(R.drawable.closearrow)); 
      return v; 
     } 

     public Object getGroup(int groupPosition) { 
      return groups[groupPosition]; 
     } 

     public int getGroupCount() { 
      return groups.length; 
     } 

     public long getGroupId(int groupPosition) { 
      return groupPosition; 
     } 

     public View getGroupView(int groupPosition, boolean isExpanded, View convertView, 
       ViewGroup parent) { 
      // change here to modify parent group layout 
      View v = null; 
      LayoutInflater li = ModifiedExpandableList.this.getLayoutInflater(); 
      v = li.inflate(R.layout.parent_view,null); 
      TextView tv = (TextView)v.findViewById(R.id.TextView01); 
      tv.setText(getGroup(groupPosition).toString()); 
      ImageView im = (ImageView)v.findViewById(R.id.ImageView01); 
      im.setBackgroundDrawable(ModifiedExpandableList.this.getResources().getDrawable(R.drawable.closearrow)); 
      if(isExpanded){ 
       im.setBackgroundDrawable(ModifiedExpandableList.this.getResources().getDrawable(R.drawable.closearrow_b)); 
      } 
      return v; 
     } 

     public boolean isChildSelectable(int groupPosition, int childPosition) { 
      return true; 
     } 

     public boolean hasStableIds() { 
      return true; 
     } 

    } 
}