ExpandableListActivity
来源:互联网 发布:mac toast and butter 编辑:程序博客网 时间:2024/06/05 21:13
package com.cardroid.apk;
import android.app.ExpandableListActivity;
import android.content.ContentUris;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnCreateContextMenuListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.CursorTreeAdapter;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.TextView;
import android.widget.Toast;
public class ApkActivity extends ExpandableListActivity {
private final String TAG = "Expandable1";
ExpandableListView mExpandableList;
ExpandableListAdapter mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the expandable list view object
mExpandableList = getExpandableListView();
// Set our expandable list adapter
String[] projection = new String[] { MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.DISPLAY_NAME,
MediaStore.Audio.Media.DISPLAY_NAME };
Cursor contactData = managedQuery(
// Phone.CONTENT_URI,
Uri.parse("content://media/external/audio/media"), projection,
null, null, null);
// 注意这里也只设置了一级项的数据
mAdapter = new CursorTreeAdapterExample(contactData, this);
setListAdapter(mAdapter);
init();
Toast.makeText(this, "Total contacts: " + contactData.getCount(),
Toast.LENGTH_LONG);
Log.d("EXPANDABLE", "Total contacts: " + contactData.getCount());
}
private void init()
{
mExpandableList.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
@Override
public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo info) {
// TODO Auto-generated method stub
menu.setHeaderTitle("aaaa");
menu.add(0, 1, 0, "open");
menu.add(0, 2, 6,"properties");
}
});
mExpandableList.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView ada, View view,int index, long longIndex) {
mExpandableList.showContextMenu();
return true;
}
});
}
/**
* Adapter implementation
*
* @author wk.kho
*
*/
public class CursorTreeAdapterExample extends CursorTreeAdapter {
private int mGroupIdColumnIndex;
private LayoutInflater mInflater;
// 注意这里的游标是一级项的
public CursorTreeAdapterExample(Cursor cursor, Context context) {
super(cursor, context);
mGroupIdColumnIndex = cursor
.getColumnIndexOrThrow(MediaStore.Audio.Media._ID);
mInflater = (LayoutInflater) context
.getSystemService(LAYOUT_INFLATER_SERVICE);
}
// 注意这里的游标是二级项的
@Override
protected void bindChildView(View view, Context context, Cursor cursor,
boolean isExpanded) {
// Bind the related data with this child view
((TextView) view).setText(cursor.getString(cursor
.getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME)));
}
@Override
protected void bindGroupView(View view, Context context, Cursor cursor,
boolean isExpanded) {
// Bind the related data with this group view
((TextView) view).setText(cursor.getString(cursor
.getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME)));
}
// 注意这里通过一次数据库查询才得到了二级项的数据
@Override
protected Cursor getChildrenCursor(Cursor groupCursor) {
Uri.Builder builder = Uri.parse(
"content://media/external/audio/media").buildUpon();
ContentUris.appendId(builder,
groupCursor.getLong(mGroupIdColumnIndex));
Uri phoneNumbersUri = builder.build();
// The returned Cursor MUST be managed by us, so we use Activity's
// helper
// functionality to manage it for us.
return managedQuery(phoneNumbersUri, new String[] {
MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.DISPLAY_NAME }, null, null, null);
}
@Override
protected View newChildView(Context context, Cursor cursor,
boolean isExpanded, ViewGroup parent) {
Log.d(TAG, "newChildView");
TextView view = (TextView) mInflater.inflate(
android.R.layout.simple_expandable_list_item_1, parent,
false);
view.setText(" ("
+ cursor.getPosition()
+ ") "
+ cursor.getString(cursor
.getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME)));
return view;
}
@Override
protected View newGroupView(Context context, Cursor cursor,
boolean isExpanded, ViewGroup parent) {
Log.d(TAG, "newGroupView");
TextView view = (TextView) mInflater.inflate(
android.R.layout.simple_expandable_list_item_1, parent,
false);
view.setText(" ("
+ cursor.getPosition()
+ ") "
+ cursor.getString(cursor
.getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME)));
return view;
}
}
}
import android.app.ExpandableListActivity;
import android.content.ContentUris;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnCreateContextMenuListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.CursorTreeAdapter;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.TextView;
import android.widget.Toast;
public class ApkActivity extends ExpandableListActivity {
private final String TAG = "Expandable1";
ExpandableListView mExpandableList;
ExpandableListAdapter mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the expandable list view object
mExpandableList = getExpandableListView();
// Set our expandable list adapter
String[] projection = new String[] { MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.DISPLAY_NAME,
MediaStore.Audio.Media.DISPLAY_NAME };
Cursor contactData = managedQuery(
// Phone.CONTENT_URI,
Uri.parse("content://media/external/audio/media"), projection,
null, null, null);
// 注意这里也只设置了一级项的数据
mAdapter = new CursorTreeAdapterExample(contactData, this);
setListAdapter(mAdapter);
init();
Toast.makeText(this, "Total contacts: " + contactData.getCount(),
Toast.LENGTH_LONG);
Log.d("EXPANDABLE", "Total contacts: " + contactData.getCount());
}
private void init()
{
mExpandableList.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
@Override
public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo info) {
// TODO Auto-generated method stub
menu.setHeaderTitle("aaaa");
menu.add(0, 1, 0, "open");
menu.add(0, 2, 6,"properties");
}
});
mExpandableList.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView ada, View view,int index, long longIndex) {
mExpandableList.showContextMenu();
return true;
}
});
}
/**
* Adapter implementation
*
* @author wk.kho
*
*/
public class CursorTreeAdapterExample extends CursorTreeAdapter {
private int mGroupIdColumnIndex;
private LayoutInflater mInflater;
// 注意这里的游标是一级项的
public CursorTreeAdapterExample(Cursor cursor, Context context) {
super(cursor, context);
mGroupIdColumnIndex = cursor
.getColumnIndexOrThrow(MediaStore.Audio.Media._ID);
mInflater = (LayoutInflater) context
.getSystemService(LAYOUT_INFLATER_SERVICE);
}
// 注意这里的游标是二级项的
@Override
protected void bindChildView(View view, Context context, Cursor cursor,
boolean isExpanded) {
// Bind the related data with this child view
((TextView) view).setText(cursor.getString(cursor
.getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME)));
}
@Override
protected void bindGroupView(View view, Context context, Cursor cursor,
boolean isExpanded) {
// Bind the related data with this group view
((TextView) view).setText(cursor.getString(cursor
.getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME)));
}
// 注意这里通过一次数据库查询才得到了二级项的数据
@Override
protected Cursor getChildrenCursor(Cursor groupCursor) {
Uri.Builder builder = Uri.parse(
"content://media/external/audio/media").buildUpon();
ContentUris.appendId(builder,
groupCursor.getLong(mGroupIdColumnIndex));
Uri phoneNumbersUri = builder.build();
// The returned Cursor MUST be managed by us, so we use Activity's
// helper
// functionality to manage it for us.
return managedQuery(phoneNumbersUri, new String[] {
MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.DISPLAY_NAME }, null, null, null);
}
@Override
protected View newChildView(Context context, Cursor cursor,
boolean isExpanded, ViewGroup parent) {
Log.d(TAG, "newChildView");
TextView view = (TextView) mInflater.inflate(
android.R.layout.simple_expandable_list_item_1, parent,
false);
view.setText(" ("
+ cursor.getPosition()
+ ") "
+ cursor.getString(cursor
.getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME)));
return view;
}
@Override
protected View newGroupView(Context context, Cursor cursor,
boolean isExpanded, ViewGroup parent) {
Log.d(TAG, "newGroupView");
TextView view = (TextView) mInflater.inflate(
android.R.layout.simple_expandable_list_item_1, parent,
false);
view.setText(" ("
+ cursor.getPosition()
+ ") "
+ cursor.getString(cursor
.getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME)));
return view;
}
}
}
- ExpandableListActivity
- ExpandableListActivity
- ExpandableListActivity
- ExpandableListActivity
- Android-ExpandableListActivity
- [控件]ExpandableListActivity
- android ExpandableListActivity
- ListActivity & ExpandableListActivity
- Android UI ExpandableListActivity与ExpandableListActivity
- Android ExpandableListActivity 学习笔记
- Android ExpandableListActivity 学习笔记
- Android基础之ExpandableListActivity
- Andorid:ExpandableListActivity控件
- Andorid:ExpandableListActivity控件
- ExpandableListActivity用法小结
- [Android] ExpandableListActivity的使用
- ExpandableListActivity的使用
- Android开发--浅谈ExpandableListActivity
- VarIsEmpty与VarIsNull
- 新建网站与新建Asp.net Web应用程序的区别
- 【模拟退火】最小球POJ 2069/codeforces 82 E
- 如何使swt窗口居中显示
- asp.net 自己练习
- ExpandableListActivity
- Java--杨辉三角
- 【盛大连接】_JAVA版本SDK案例(含JSP调用及说明,全)源代码
- 设置MySQL支持远程链接
- 2011 最佳的 Linux 发行版
- 正则表达式使用学习(C++、Qt、Python)
- MySQL性能优化的最佳20+条经验
- OAUTH支持第三方认证方式介绍
- poj 3254