我使用的ExpandableListView是每个小组都是a TextView,每个小孩都是a CheckBox.我试图实现类似于这个链接的东西:
http://www.vogella.de/articles/AndroidListView/article.html#listadvanced_interactive
但用一个ExpandableListView而不是ListView.在运行时,它ClassCastException在设置Tag复选框时给出一个奇怪的东西setTag().这是代码:
public class ExpandableActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ArrayList<String> groups = new ArrayList<String>();
List<List<OptionItem>> children = new ArrayList<List<OptionItem>>();
for (int i = 0; i < 10; i++) {
String groupName = "Group " + i;
groups.add(groupName);
List<OptionItem> temp = new ArrayList<OptionItem>();
for (int j = 0; j < 5; j++) {
temp.add(new OptionItem(groupName, "Child " …Run Code Online (Sandbox Code Playgroud) 我有一个自定义适配器的ExpandableListActivity.
如果适配器的自定义行包含imageViewall已完成,但如果我将此视图从imageView更改为imageButton,则可扩展列表视图不会展开.
是否有任何方法可以放置一个可以单击的按钮,并且expandablelist不会丢失扩展功能?
我需要设置填充的TextView的每一行中ListView或ExpandableListView.我尝试使用android:padding和孩子(paddingLeft,...),但没有任何结果.我能怎么做?谢谢
编辑:
这是该项目的代码 ExpandableListView
<?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="fill_parent"
android:orientation="vertical"
android:padding="20dp" >
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:id="@+id/titleScheda"
android:text="TextView"
android:layout_width="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:padding="20dp" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
在两个布局上设置填充并且TextView不起作用,即使填充仅在2个标记中的一个中设置.
编辑:
解决了.问题出在Java代码中,在SimpleExpandableListAdapter声明中.使用标准布局无法自定义,但使用可扩展内容的自定义布局是允许我们自定义任何内容的解决方案.
我怎么能这样做?

导航抽屉内的两个可扩展列表视图.我试着将它添加到我的xml中,但没有运气.我想要的是只有一个滚动条的视图,但我不知道该怎么做..
这是我的导航抽屉布局:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:background="@color/Bianco"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_marginRight="16dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/tvHomeActions"
android:id="@+id/textView" />
<ExpandableListView
android:id="@+id/elvHome"
android:layout_width="match_parent"
android:layout_marginTop="4dp"
android:layout_height="300dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/tvHomeNavigations"
android:layout_marginTop="16dp"
android:id="@+id/textView2" />
<ExpandableListView
android:id="@+id/elvNavigateTo"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="4dp" />
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
编辑: 我想在Gmail应用程序中创建类似抽屉的东西
我有一个使用onclickListener来更改父文本的自定义适配器,我无法弄清楚如何让notifyDataSetChanged方法在适配器中工作.
应该发生的是我有一个可扩展的视图,当你点击子视图中的按钮时,它会更新父视图中的父文件...
这是一个应该发生什么的图片示例.在点击按钮之前使用这个:

然后单击按钮使用此:

"选择一种成分"更改为"米饭,杯子"或点击的任何内容
所以在我显示的代码中,单击按钮后它应该更新它所执行的操作,然后刷新由于某种原因我不能做的视图?
继承我的代码,提前致谢!
package com.example.andrew.mypantry;
import android.content.Context;
import android.graphics.Typeface;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import org.w3c.dom.Text;
import java.util.HashMap;
import java.util.List;
/**
* Created by andrew on 7/1/2015.
*/
public class IngExpandableListAdapter extends BaseExpandableListAdapter {
private Context context;
private List<String> listDataHeader; //header titles
//child data in format of <header title, child title>
private HashMap<String, List<String>> listDataChild;
public IngExpandableListAdapter(Context context, List<String> listDataHeader,
HashMap<String, List<String>> listDataChild) {
this.context …Run Code Online (Sandbox Code Playgroud) android expandablelistview expandablelistadapter onclicklistener
我正在使用ExpandableListView,并且在扩展组时(图像是组视图的一部分)尝试移动图像时未成功.
这是我的代码:
my_list_view.setOnGroupExpandListener(new OnGroupExpandListener()
{
@Override
public void onGroupExpand(int groupPosition)
{
Toast.makeText(getBaseContext(), "Group " + my_list_view.getGroupId(groupPosition), Toast.LENGTH_SHORT).show();
}
});
Run Code Online (Sandbox Code Playgroud)
基本上我的问题是:当我可以使用的唯一变量是groupPosition时,如何访问扩展的Group视图?
任何你应该创建一个类似自定义适配器的响应都不会被接受.我已经尝试过了,它对我的问题不起作用.我需要的是监听onGroupExpand事件.
我不能为我的生活弄清楚为什么我的ExpandableListView不会扩展...我已经在ExpandableListView中找到了几乎每个点击监听器的日志语句,它看起来并不像它们中的任何一个被调用.
我知道有很多关于这个主题的帖子,但是我已经阅读了所有内容并尝试了许多事情并且没有运气,希望我错过了一些很容易被其他人发现的小错误.
主要活动:
public class ForumListActivity extends Activity {
private static ArrayList<Forum> forumList;
private static ArrayList<ArrayList<SubForum>> subForumList;
private ExpandableListView forumListView;
private ForumListAdapter forumListAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.main_page);
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
forumListView = (ExpandableListView) this.findViewById(R.id.main_page_forum_list);
forumList = new ArrayList<Forum>();
subForumList = new ArrayList<ArrayList<SubForum>>();
setUpForums(this);
forumListAdapter = new ForumListAdapter(this, forumList, subForumList);
forumListView.setAdapter(forumListAdapter);
forumListView.setOnGroupExpandListener(new OnGroupExpandListener(){
@Override
public void onGroupExpand(int groupPosition) {
Log.d("onGroupExpand", "this works?");
for(int i=0; i<forumListAdapter.getGroupCount(); i++) {
if(i != groupPosition)
forumListView.collapseGroup(groupPosition);
}
}
});
forumListView.setOnGroupClickListener(new OnGroupClickListener() {
@Override
public …Run Code Online (Sandbox Code Playgroud) android click listener expandablelistview expandablelistadapter
我正在使用ExpandableListView和一个扩展BaseExpandableListAdapter的自定义适配器.现在我想在可扩展列表中添加一个标题,所以不要使用我的apapter来获取元素的视图,而是需要使用标题"自动"创建的元素,所以我没有得到IndexOutOfBoundsExceptions,因为现在标题是0位置的元素.
在我的适配器不可扩展的其他ocassions我只需要调用myList.getAdapter(),一切都很好,但现在我需要得到扩展BaseExpandableListAdapter的适配器,我找不到这样做的方法.
myList = (ExpandableListView)findViewById(R.id.my_list);
myList .setGroupIndicator(null);
myList .setOnGroupClickListener(this);
myList .setOnChildClickListener(this);
//add a header
View addSummaryLayout = View.inflate(this, R.layout.add_summary, null);
groupedMultimediaListView.addHeaderView(addSummaryLayout);
myAdapter = new MyAdapter (this, uploadingMedias);
myList .setAdapter(myAdapter );
Run Code Online (Sandbox Code Playgroud)
在某些时候,我需要为myAdapter调用getChildView方法(扩展BaseExpandableListAdapter),但我不能直接使用myAdapter,因为那个没有标头.我需要通过列表来完成.我试图通过getWrappedAdapter来做到这一点
HeaderViewListAdapter headerAdapter = ((HeaderViewListAdapter) myList .getAdapter());
((MyAdapter ) headerAdapter.getWrappedAdapter()).getChildView(0, i - 1, false, view, myList );
Run Code Online (Sandbox Code Playgroud)
但它给了我一个ClassCastException,android.widget.ExpandableListConnector无法强制转换为MyAdapter
有没有人知道通过列表方法获取原始适配器的方法?
谢谢
我对Android编程很新,并试图实现一个基本的可扩展列表视图,显示一个课程列表,在点击时应该显示一些额外的细节.我觉得问题是非常基本的,因为我没有在任何视图中包含任何奇特的内容,但我仍然无法在线找到解决方案,大多数其他问题都更加具体.
第一部分工作正常(显示课程列表),问题是列表不可点击,这意味着它不会扩展.
我现在确定的是:
1.从不调用getChildView(调试器永远不会在断点处停止)
2.有子数据,因为它与用于组头的工作正常相同.
我还尝试设置一个从未调用的onGroupClickListener,所以我再次将其删除.
我的代码:
组标题布局:
<TextView
android:id="@+id/CourseName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="bottom"
android:text="CourseName"
android:layout_weight="7"
android:layout_marginRight="25dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/CourseDate"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="bottom"
android:layout_weight="3"
android:text="CourseDate" />
<CheckBox
android:id="@+id/checkBox"
style="?android:attr/starStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
child_row布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Button" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/button1"
android:text="Button" />
<TextView
android:id="@+id/phases"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:gravity="center"
android:layout_below="@+id/button1"
android:text="phases:" />
<TextView
android:id="@+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/phases"
android:gravity="center"
android:text="information:" /> …Run Code Online (Sandbox Code Playgroud) 我有以下适配器Activity.我已设置CheckBox的GroupView感动将检查/取消孩子的意见时(也有CheckBox).
状态CheckBox(true or false)存储在DB中,最初设置为true/checked.复选框设置为最初检查.
当我触摸a时会有一些奇怪的行为GroupCheckbox,它也会取消选中不属于触摸的复选框GroupView.
例如,如果我有5个GroupViews,每个GroupView有5个孩子.如果我取消选中第一名GroupView CheckBox,它会取消所有孩子,但也会取消第三名GroupView CheckBox及其子女.
有什么想法吗?
[编辑1]
我已经删除了之前的代码片段,因为我正在开始赏金.代码已经从原来改变了,因为Ankit Kumar帮助我使用Viewholder模式getGroupView方法.当只触摸一个复选框时,它仍会取消选中多个组视图复选框.后备数据库已选中复选框的所有状态,true以便从中开始.
看起来该视图与数据库不同步.我已经注销了语句,证明所有复选框的状态都是真的开始.
有没有办法只使用户触摸的复选框取消选中而不影响其他复选框?
public class ExpList extends ExpandableListActivity {
String arrGroupelements[];
String arrChildelements[][];
private static final String TAG = ExpList.class.getSimpleName();
DisplayMetrics metrics;
int width;
ExpandableListView expList;
RROnCallApplication appObj;
Cursor companies;
Button mainMenu;
ExpAdapter adapter;
int companyCount;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); …Run Code Online (Sandbox Code Playgroud)