我正在尝试扩展 BaseExpandableListAdapter,但是当我查看列表并选择要扩展的元素之一时,列表的顺序会反转。例如,如果我有一个包含 4 个元素的列表并选择第 1 个元素,则顺序(从上到下)现在为 4、3、2、1,第 4 个元素(现在位于顶部)展开。如果我展开第 4 个元素,顺序将恢复为 1、2、3、4,没有展开的元素。
这是我的实现:
公共(public)类 SensorExpandableAdapter 扩展 BaseExpandableListAdapter {
private static final int FILTER_POSITION = 0;
private static final int FUNCTION_POSITION = 1;
private static final int NUMBER_OF_CHILDREN = 2;
ArrayList<SensorType> mParentGroups;
private Context mContext;
private LayoutInflater mInflater;
public SensorExpandableAdapter(ArrayList<SensorType> parentGroup, Context context) {
mParentGroups = parentGroup;
mContext = context;
mInflater = LayoutInflater.from(mContext);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
if(childPosition == FILTER_POSITION) return "filter";
else return "function";
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
if(convertView == null)
{
convertView = (RelativeLayout)mInflater.inflate(R.layout.sensor_row_list_item, parent, false);
if(childPosition == FILTER_POSITION) {
((CheckBox)convertView.findViewById(R.id.chkTextAddFilter)).setText("Add Filter");
} else {
((CheckBox)convertView.findViewById(R.id.chkTextAddFilter)).setText("Add Function");
((CheckBox)convertView.findViewById(R.id.chkTextAddFilter)).setEnabled(false);
}
}
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
// TODO Auto-generated method stub
return NUMBER_OF_CHILDREN;
}
@Override
public Object getGroup(int groupPosition) {
return mParentGroups.get(groupPosition);
}
@Override
public int getGroupCount() {
// TODO Auto-generated method stub
return mParentGroups.size();
}
@Override
public long getGroupId(int groupPosition) {
// TODO Auto-generated method stub
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
if(convertView == null)
{
convertView = mInflater.inflate(android.R.layout.simple_expandable_list_item_1, parent, false);
TextView tv = ((TextView)convertView.findViewById(android.R.id.text1));
tv.setText(mParentGroups.get(groupPosition).toString());
}
return convertView;
}
@Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return true;
}
}
`
我只需要采用我自己的 SensorType 类的简单 ArrayList。所有类(class)的 child 都一样,只有两个。
此外,如何让每个组中的父级可点击?我已经尝试在我的 ExpandableListActivity 中使用此 getExpandableListView().setOnLongClickableListener() ... 并在父 TextView 上设置其 OnLongClickableListener 但均无效。
非常感谢对其中任何一个的任何帮助!
最佳答案
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
if(convertView == null)
{
只需注释掉“如果”。这应该有所帮助。
关于Android 扩展 BaseExpandableListAdapter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2527516/
我正在编写一个包含C扩展的gem。通常当我写一个gem时,我会遵循TDD的过程,我会写一个失败的规范,然后处理代码直到它通过,等等......在“ext/mygem/mygem.c”中我的C扩展和在gemspec的“扩展”中配置的有效extconf.rb,如何运行我的规范并仍然加载我的C扩展?当我更改C代码时,我需要采取哪些步骤来重新编译代码?这可能是个愚蠢的问题,但是从我的gem的开发源代码树中输入“bundleinstall”不会构建任何native扩展。当我手动运行rubyext/mygem/extconf.rb时,我确实得到了一个Makefile(在整个项目的根目录中),然后当
我想这样组织C源代码:+/||___+ext||||___+native_extension||||___+lib||||||___(Sourcefilesarekeptinhere-maycontainsub-folders)||||___native_extension.c||___native_extension.h||___extconf.rb||___+lib||||___(Rubysourcecode)||___Rakefile我无法使此设置与mkmf一起正常工作。native_extension/lib中的文件(包含在native_extension.c中)将被完全忽略。
最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路
我有一个要在我的Rails3项目中使用的数组扩展方法。它应该住在哪里?我有一个应用程序/类,我最初把它放在(array_extensions.rb)中,在我的config/application.rb中我加载路径:config.autoload_paths+=%W(#{Rails.root}/应用程序/类)。但是,当我转到railsconsole时,未加载扩展。是否有一个预定义的位置可以放置我的Rails3扩展方法?或者,一种预先定义的方式来添加它们?我知道Rails有自己的数组扩展方法。我应该将我的添加到active_support/core_ext/array/conversion
我想编写一个ruby脚本来递归复制目录结构,但排除某些文件类型。因此,给定以下目录结构:folder1folder2file1.txtfile2.txtfile3.csfile4.htmlfolder2folder3file4.dll我想复制这个结构,但不包含.txt和.cs文件。因此,生成的目录结构应如下所示:folder1folder2file4.htmlfolder2folder3file4.dll 最佳答案 您可以使用查找模块。这是一个代码片段:require"find"ignored_extensions=[".cs"
这个问题有两个部分。在RubyProgrammingLanguage一书中,有一个使用模块扩展字符串对象和类的示例(第8.1.1节)。第一个问题。为什么如果您使用新方法扩展类,然后创建该类的对象/实例,则无法访问该方法?irb(main):001:0>moduleGreeter;defciao;"Ciao!";end;end=>nilirb(main):002:0>String.extend(Greeter)=>Stringirb(main):003:0>String.ciao=>"Ciao!"irb(main):004:0>x="foobar"=>"foobar"irb(main):
假设我们有A、B、C类。Adefself.inherited(sub)#metaprogramminggoeshere#takeclassthathasjustinheritedclassA#andforfooclassesinjectprepare_foo()as#firstlineofmethodthenrunrestofthecodeenddefprepare_foo#=>prepare_foo()neededhere#somecodeendendBprepare_foo()neededhere#somecodeendend如您所见,我正在尝试将foo_prepare()调用注入
显然在Test::Unit中没有assert_false。您将如何通过扩展断言并添加文件config/initializers/assertions_helper.rb来添加它?这是最好的方法吗?我不想修改test/unit/assertions.rb。顺便说一句,我不认为这是多余的。我使用的是assert_equalfalse,something_to_evaluate。这种方法的问题是很容易意外使用assertfalse,something_to_evaluate。这将始终失败,不会引发错误或警告,并且会在测试中引入错误。 最佳答案
这个问题在这里已经有了答案:Unabletoinstallgem-Failedtobuildgemnativeextension-cannotloadsuchfile--mkmf(LoadError)(17个答案)关闭9年前。嘿,我正在尝试在一台新的ubuntu机器上安装rails。我安装了ruby和rvm,但出现“无法构建gemnative扩展”错误。这是什么意思?$sudogeminstallrails-v3.2.9(没有sudo表示我没有权限)然后它会输出很多“获取”命令,最终会出现这个错误:Buildingnativeextensions.Thiscouldtakeawhi
我在引擎样式插件中有一些代码,其中包含一些模型。在我的应用程序中,我想扩展其中一个模型。通过在初始值设定项中包含一个模块,我已经设法将实例和类方法添加到相关模型中。但是我似乎无法添加关联、回调等。我收到“找不到方法”错误。/libs/qwerty/core.rbmoduleQwertymoduleCoremoduleExtensionsmoduleUser#InstanceMethodsGoHere#ClassMethodsmoduleClassMethodshas_many:hits,:uniq=>true#nomethodfoundbefore_validation_on_crea