- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在使用扩展的 MyExpandableListAdapterBaseExpandableListAdapter 并且我在我的适配器中实现了 BaseExpandableListAdapter 的所有方法,我创建了扩展 ExpandableListActivity 的 MyExpadableListActivity。MyExpandableListAdapter 是 MyExpandableListActivity 的内部类。我正在使用 xml View 来添加子项和分组 UI(过去在下面)。当我运行应用程序时,它的显示效果很好。我的问题是,我在 MyExpadableListActivity 中覆盖了 ExpandableListActivity 的 onChildClick (....) 方法。当我运行我的代码时,它无法使用 onChildClick 方法。我如何使用这种情况或其他建议来实现 onChildClick (...) 方法..希望有人指出我做错了什么......如果有人指出我如何实现解决方案,我将不胜感激。 .
public class MyExpadableListActivity extends ExpandableListActivity implements
ExpandableListView.OnChildClickListener {
ExpandableListAdapter mAdapter;
Context mContext;
static final String groups[] = { "Chats", "Contacts (289)",
"Group Chat (7)", "e-Card (137)", "Pending (37)",
"Bookmarks" };
static final String children[][] = {
{ "ListofChats" },
{ "Group", "groupt01", "groupt02", "groupt03" },
{ "Groupd 01", "", "Group 02", "", "Group 03", "" },
{ "E-Card-01", "", "E-Card-02", "",
"Business Card Received", "" },
{ " Req", "", " Req", "", " Req", "" } };
private static final String TAG = "Hookup";
XMPPConnection connection = SignInMainActivity.connection;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mAdapter = new MyExpandableListAdapter(this);
setListAdapter(mAdapter);
registerForContextMenu(getExpandableListView());
}
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
// TODO Auto-generated method stub
System.out.println("Insidded onContextItemSelected");
return super.onChildClick(parent, v, groupPosition, childPosition, id);
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
menu.setHeaderTitle("Hookup Menu");
menu.add(0, 0, 0, R.string.hello);
}
public boolean onContextItemSelected(MenuItem item) {
System.out.println("Insidded onContextItemSelected");
Log.i(TAG, "onContextItemSelected");
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;
}
public class MyExpandableListAdapter extends BaseExpandableListAdapter {
Context mContext;
public MyExpandableListAdapter() {
// TODO Auto-generated constructor stub
}
public MyExpandableListAdapter(Context context) {
mContext = context;
}
public Object getChild(int groupPosition, int childPosition) {
Log.i(TAG, "getChild");
return children[groupPosition][childPosition];
}
public long getChildId(int groupPosition, int childPosition) {
Log.i(TAG, "getChildId");
return childPosition;
}
public int getChildrenCount(int groupPosition) {
Log.i(TAG, "getChildId");
return children[groupPosition].length;
}
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
Log.i(TAG, "getChildView");
LayoutInflater layoutInflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = null;
TextView tt = null;
if (groupPosition == 4) {
v = layoutInflater.inflate(R.layout.button_group, null);
} else {
v = layoutInflater.inflate(R.layout.album_row, null);
tt = (TextView) v.findViewById(R.id.text1);
String myText = this.getChild(groupPosition, childPosition)
.toString();
tt.setText(myText);
CheckBox cb = (CheckBox) v.findViewById(R.id.checkbox);
cb.setVisibility(View.VISIBLE);
if (groupPosition == 0) {
ImageView icon = (ImageView) v.findViewById(R.id.rowicon);
icon.setImageResource(R.drawable.add_picture);
} else {
ImageView icon = (ImageView) v.findViewById(R.id.rowicon);
icon.setImageResource(R.drawable.add_picture);
}
}
return v;
}
public Object getGroup(int groupPosition) {
Log.i(TAG, "getGroup");
return groups[groupPosition];
}
public int getGroupCount() {
Log.i(TAG, "getGroupCount");
return groups.length;
}
public long getGroupId(int groupPosition) {
Log.i(TAG, "getGroupId");
return groupPosition;
}
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
TextView groupTitle = null;
ImageView imgDot;
LayoutInflater layoutInflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = null;
v = layoutInflater.inflate(R.layout.button_group, null);
groupTitle = (TextView) v.findViewById(R.id.TextView01);
String myText = this.getGroup(groupPosition).toString();
groupTitle.setText(myText);
imgDot = (ImageView) v.findViewById(R.id.ImageView01);
imgDot.setVisibility(View.VISIBLE);
return v;
}
public boolean isChildSelectable(int groupPosition, int childPosition) {
Log.i(TAG, "isChildSelectable");
return true;
}
public boolean hasStableIds() {
Log.i(TAG, "hasStableIds");
return true;
}
public void registerDataSetObserver(DataSetObserver observer) {
}
} // closing of MyExpandableListAdapter
} // closing of MyExpadableListActivity
我的xml View 如下
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
android:paddingRight="?android:attr/scrollbarSize"
android:layout_weight="1" android:background="#fafafa">
<ImageView android:id="@+id/rowicon" android:layout_width="wrap_content"
android:layout_height="fill_parent" android:layout_marginRight="6dip" /> <TextView
android:id="@+id/text1"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1"
/>
<CheckBox android:id="@+id/checkbox" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_marginRight="2dip"
android:focusable="true" android:clickable="true" android:gravity="center_vertical"
android:orientation="vertical" android:duplicateParentState="true"
android:visibility="visible"
android:text="myTest"
/> </LinearLayout>
和
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
android:paddingRight="?android:attr/scrollbarSize"
android:layout_weight="1" android:background="#fafafa">
最佳答案
在 BaseExpandableListAdapter
中有一个函数:public boolean isChildSelectable(int groupPosition, int childPosition)
。此函数返回默认 false。改成:返回真。您的 onChildClickListener 将被调用!
关于Android ExpandableListVIew 使用 BaseExpandableListAdapter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5897093/
我只是想知道Mvvmmcross框架中是否潜藏着ExpandableListViews或与之相似的功能,还是这种控件不适用于多平台要求。 的功能在 http://deapsquatter.blogsp
我想知道是否可以将一个 ExpandableListView 作为另一个 ExpandableListView 的一个元素的一个子元素。谢谢 最佳答案 是的。可以在可扩展 ListView 中创建可扩
现在我想使用 ExpandableListView 来显示我的数据,我想更改项目左侧的图标或让它消失。有人可以给我一个建议吗。 谢谢。 最佳答案 setGroupIndicator(null) 应该让
我在 expandablelistview 子项目中有一个 edittext。然后,我在这个 edittext 中输入了一个文本,但是每当我点击其他 expandablelistview 标题时,我输
我正在尝试弄清楚如何构建包含(许多)的 View : PARENT1(可勾选、可扩展) CHILD1(单选按钮) CHILD2(单选按钮) ... PARENT2(可勾选、可扩展) CHILD1(可检
所以我刚刚进入了 ExpandableListView 领域,并希望在 DrawerLayout 中制作一个只有一组和 3 个 child 的简单列表 这是我的适配器代码: public cl
我是 Android 开发新手。我关注了this显示 ExpandableListView 及其正常工作的教程。如果我按所有组,那么所有组都会展开。 我一次只想扩展一组。一开始,第一个组将自动展开,如
我是 Android 新手。我想创建一个可扩展的 ListView,其中 1 行具有必须在 manin 线程中指定的自定义信息,而不是在布局中进行硬编码。 我想要一个图像和 2 个 TextView
我的应用程序中有一个 ExpandableListView。我想让子布局比组标题窄一点,并保持居中。由于一些视觉效果,我必须从代码中设置布局参数,但是我似乎找不到最好的解决方案,尝试从 xml 更
我正在将 JSON 解析为 ExpandableListView,在每个子项上,用户可以选择他想要拥有的 +/- 按钮的每个子项的数量。 +/- 按钮连接到 TextView,其中显示每个子项的总金额
我希望我的团队能够在第一时间扩大。然后它应该像往常一样运行(单击指示器后折叠/展开) 我找不到解决此问题的任何有效解决方案。 最佳答案 循环遍历所有组并使用expandGroup()您的 Expand
我正在编写一个 Android 应用程序,我决定使用可扩展 ListView 。我拥有所需的一切,列表工作正常,但是当我填充它时,组的顺序似乎与应有的顺序不同,这是一个示例: 如您所见,子值很好,只有
我在组项目的 ExpandableListView 中添加了 EditText,之后当我单击组项目时,不会出现包含子项目的列表。可能是什么问题?在这种情况下,这个列表是否可以扩展?或者禁止在Expan
当我单击组 View 时,可扩展列表的顺序会发生变化 我发现有人有类似的问题 here 顺序似乎是随机的,我不明白发生了什么。 这是我的代码,我知道它很乱,我已经重写了很多次。 public clas
我是 Android 编程的新手,我一直在思考如何做到这一点……我想创建一个 ExpandableListView,其中包含相同的子项 XML(包含添加、编辑和删除按钮)填充在所有组项目中。 有人可以
我在 Android 抽屉导航中使用 ExpandableListsViews 而不是菜单。而 OnExpandlistner 我正在改变背景颜色。前两个项目表现正常,它们的背景颜色发生了变化。但最后
我对 ExpandableListView 有疑问:在我的应用程序中,我使用了 ExpandableListView 并用我的适配器填充它“类 MyExpandableListAdapter 扩展了
我正在使用 Fedor 的适配器和图像加载器将图像延迟加载到可扩展 ListView 中。 ( Lazy load of images in ListView ) 它运行良好,但有一个问题。仅当 Im
关注this教程我能够制作一个大致这样布局的 View : Group1 child1 child2 group2 child1 child2 但是我想要更多的嵌套: grou
Blockquote 我在 android 中使用 ExpandableListView 这是适配器类中getChildView的代码: @Override public View g
我是一名优秀的程序员,十分优秀!