Gallery 的 Demo(11)
来源:未知 责任编辑:责任编辑 发表时间:2013-12-18 11:34 点击:次
import android.view.View;
import android.view.ViewGroup;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.AbsListView;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
// ExpandableList - 可展开/收缩列表
// 继承 ExpandableListActivity 以实现列表的可展开/收缩的功能
public class _ExpandableList extends ExpandableListActivity {
private ExpandableListAdapter mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setTitle("ExpandableList");
mAdapter = new MyExpandableListAdapter();
setListAdapter(mAdapter);
registerForContextMenu(this.getExpandableListView());
}
// 为列表的每一项创建上下文菜单(即长按后呼出的菜单)
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
menu.setHeaderTitle("ContextMenu");
menu.add(0, 0, 0, "ContextMenu");
}
// 单击上下文菜单后的逻辑
@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);
相关新闻>>
- 发表评论
-
- 最新评论 更多>>