資源描述:
《Android支持展開和收縮功能的列表控件》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、最近在做一個(gè)Rss閱讀器,看了下別人做的閱讀器中的列表控件可以展開、收縮,我就在網(wǎng)上搜索了一下。下面就我找到的一個(gè)小例子,給大家分享一下。ActivityMain.java?1234567891011121314151617181920212223packagestudy.com.android;??importandroid.app.ExpandableListActivity;importandroid.os.Bundle;importandroid.view.ContextMenu;importandroid.view.MenuItem;importandroid
2、.view.View;importandroid.view.ContextMenu.ContextMenuInfo;importandroid.widget.ExpandableListAdapter;importandroid.widget.ExpandableListView;importandroid.widget.TextView;importandroid.widget.Toast;importandroid.widget.ExpandableListView.ExpandableListContextMenuInfo;??publicclassActivit
3、yMainextendsExpandableListActivity{??????privateExpandableListAdaptermAdapter;??????@Override????publicvoidonCreate(BundlesavedInstanceState){????????super.onCreate(savedInstanceState);????????this.setTitle("ExpandableList");????????mAdapter=newMyExpandableListAdapter(this);????????setLi
4、stAdapter(mAdapter);????????registerForContextMenu(this.getExpandableListView());????}??????//為列表的每一項(xiàng)創(chuàng)建上下文菜單(即長按后呼出的菜單)????@Override????publicvoidonCreateContextMenu(ContextMenumenu,Viewv,????????????ContextMenuInfomenuInfo){????????menu.setHeaderTitle("ContexMenu");????????menu.add(0,0,
5、0,"ContextMenu");????}??24252627282930313233343536373839404142434445????//單擊上下文菜單后的邏輯????@Override????publicbooleanonContextItemSelected(MenuItemitem){??????????ExpandableListContextMenuInfoinfo=(ExpandableListContextMenuInfo)item????????????????.getMenuInfo();????????Stringtitle=((TextV
6、iew)info.targetView).getText().toString();??????????inttype=ExpandableListView????????????????.getPackedPositionType(info.packedPosition);????????if(type==ExpandableListView.PACKED_POSITION_TYPE_CHILD){??????????????intgroupPos=ExpandableListView????????????????????.getPackedPositionGrou
7、p(info.packedPosition);????????????intchildPos=ExpandableListView????????????????????.getPackedPositionChild(info.packedPosition);????????????Toast.makeText(????????????????????this,????????????????????title+"-GroupIndex"+groupPos+"ChildIndex:"????????????????????????????