我正在制作一个包含自定义 ExpandableListView 适配器的菜单。尽管试图使我的代码尽可能接近 API 示例和我在网上看到的任何其他示例(包括多个密切相关的 SO 问题),但我仍然无法让它工作。
我知道正在使用适配器,因为正在显示组 View (由 xml 制作)。单击组项也会调用“getGroupView”,但代码永远不会运行“getChildView”、“getChild”或“getChildId”。
我什至查看了 Android-15 源代码以找出我可能做错了什么,但没有发现任何奇怪的地方。
= 基本 Activity
public class SettingsM extends FragmentActivity
{
static Context context;
ViewPager mViewPager;
CollectionPagerAdapter mDemoCollectionPagerAdapter;
//ColorPicker picker;
SharedPreferences preferences;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
context = this;
// Set up action bar.
final ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setTitle("Particle emitter settings");
// get the preferences for this screen
preferences = this.getSharedPreferences("base_world", 0);
// tab holder
setContentView(R.layout.tabmenu_holder);
mViewPager = (ViewPager) findViewById(R.id.pager);
mDemoCollectionPagerAdapter = new CollectionPagerAdapter(getSupportFragmentManager());
mViewPager.setAdapter(mDemoCollectionPagerAdapter);
}
public class CollectionPagerAdapter extends FragmentStatePagerAdapter
{
public CollectionPagerAdapter(FragmentManager fm)
{
super(fm);
}
@Override
public Fragment getItem(int i)
{
Fragment fragment = new TabFragment();
Bundle args = new Bundle();
if(preferences != null)
{
if(i == 0)
{// world
args.putBoolean("world", true);
} else
{// emitter
args.putBoolean("world", false);
args.putInt("emitter", i-1);
}
}
fragment.setArguments(args);
return fragment;
}
@Override
public int getCount()
{
return 100;
}
@Override
public CharSequence getPageTitle(int position)
{
if(position == 0)
{
return "World";
} else
{
return "Emitter #" + position;
}
}
}
public static class TabFragment extends Fragment
{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
Bundle args = getArguments();
View rootView = new TextView(context);// use a textview as the default
if(args.getBoolean("world"))
{
rootView = inflater.inflate(R.layout.m_backdrop, container, false);
// add face drop-down
ExpandableListView face_list = (ExpandableListView) rootView.findViewById(R.id.FaceList);
if(face_list != null)
{
face_list.setAdapter(new ExpandableFaceList(context));
face_list.setOnGroupClickListener(new OnGroupClickListener()
{
@Override
public boolean onGroupClick(ExpandableListView parent,
View v, int groupPosition, long id)
{
Log.i("FaceList", "Clicked:" + groupPosition);
return false;
}
});
}
} else
{
return rootView;
}
return rootView;
}
}
}
= 可扩展 ListView 适配器
public class ExpandableFaceList extends BaseExpandableListAdapter implements ExpandableListAdapter
{
public Context context;
private LayoutInflater inflator;
private float mDensity = 1f;
private boolean bShowSw = true;
private ColorPickerMenuView cp;
private Switch sw;
public ExpandableFaceList(Context context)
{
this.context = context;
this.inflator = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mDensity = context.getResources().getDisplayMetrics().density;
}
@Override
public int getGroupCount()
{
return 1;
}
@Override
public int getChildrenCount(int groupPosition)
{
return 6;// because there are 6 faces to a cube
}
// list views
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent)
{
View v = convertView;
TextView tv;
if(v == null)
{
v = inflator.inflate(R.layout.exlist_head, parent, false);
tv = (TextView) v.findViewById(R.id.exList_Title);
if(tv != null)
tv.setText("Face Colors");
tv = (TextView) v.findViewById(R.id.exList_Summary);
String s_text = "The color for each face, click to ";
s_text += ((isExpanded)? "collaspe": "expand");
if(tv != null)
tv.setText(s_text);
} else
{
tv = (TextView) v.findViewById(R.id.exList_Summary);
String s_text = "The color for each face, click to ";
s_text += ((isExpanded)? "collaspe": "expand");
if(tv != null)
tv.setText(s_text);
parent.invalidate();
}
return v;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent)
{
View v = convertView;
if(v == null)
{
if(bShowSw)
{
v = (LinearLayout) inflator.inflate(R.layout.face_info_sw, parent, false);
} else
{
v = (LinearLayout) inflator.inflate(R.layout.face_info, parent, false);
}
}
switch(childPosition)
{
case 0:
v.setTag("Front");
break;
case 1:
v.setTag("Back");
break;
case 2:
v.setTag("Left");
break;
case 3:
v.setTag("Right");
break;
case 4:
v.setTag("Top");
break;
case 5:
v.setTag("Bottom");
break;
}
Log.i("ELV", "Pos:" + childPosition);
cp = (ColorPickerMenuView) v.findViewById(R.id.face_color);
cp.setTitle((String) v.getTag());
cp.setOnClickListener(new OnClickListener() {
public void onClick(View v) { UpdateData(v); }
});
if(bShowSw)
{
sw = (Switch) v.findViewById(R.id.face_sw);
sw.setOnClickListener(new OnClickListener() {
public void onClick(View v) { UpdateData(v); }
});
}
return v;
}
private void UpdateData(View v) { }
@Override
public Object getGroup(int groupPosition)
{
return groupPosition;
}
@Override
public Object getChild(int groupPosition, int childPosition)
{
return "Child:" + groupPosition + "." + childPosition;
}
@Override
public long getGroupId(int groupPosition)
{
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition)
{
return childPosition;
}
@Override
public boolean hasStableIds()
{
return true;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition)
{
return true;
}
}
= Activity 的 xml View
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.PagerTitleStrip android:id="@+id/pager_title_strip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#33b5e5"
android:textColor="#fff"
android:paddingTop="4dp"
android:paddingBottom="4dp" />
</android.support.v4.view.ViewPager>
= m_backdrop.xml(背景设置菜单)
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:app="http://schemas.android.com/apk/res/com.zyphronics.aquafinger">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/Title_GeneralSettings_text"
style="?android:attr/listSeparatorTextViewStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:text="General Settings" />
<ExpandableListView
android:id="@+id/FaceList"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="@id/Title_GeneralSettings_text" >
</ExpandableListView>
</RelativeLayout>
</ScrollView>
= face_info.sw.xml(face_info.xml是一样的,只是没有switch)
<?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:orientation="vertical" >
<Switch
android:id="@+id/face_sw"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:tag="face_sw"
android:text="Enabled?"
android:textOff="No"
android:textOn="Yes" />
<com.zyphronics.AF.Controls.colorpicker.ColorPickerMenuView
android:id="@+id/face_color"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:tag="face_color" />
</LinearLayout>
即使没有 face_info_sw.xml 中的“ColorPickerMenuView”部分, subview 仍未被调用。我也尝试过单独使用相对布局,而不是在 ScrollView 中,但这会阻止进一步添加的项目滚动到(并且还使自定义控件具有奇怪的大小)。
任何解决这个问题的帮助都会很棒。如果有人需要这个的打包源(兼容 eclipse),如评论中所示,我会回复一个链接。
最佳答案
问题是,您的 ExpandableListView 在 ScrollView 中。大多数情况下这是不良布局的结果,您应该尽量避免这种情况。
但有时它是唯一的解决方案(这实际上不是真的,但其他解决方案可能超出了一个范围)。您的解决方案也有效,但有点复杂。而是像这样编写一个自定义的 ExpandableListView:
public class ExpandExpandableListView extends ExpandableListView{
boolean expanded = true;
public ExpandExpandableListView(Context context) {
super(context);
}
public ExpandExpandableListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ExpandExpandableListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public boolean isExpanded()
{
return expanded;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (isExpanded())
{
// Calculate entire height by providing a very large height hint.
// View.MEASURED_SIZE_MASK represents the largest height possible.
int expandSpec = MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
ViewGroup.LayoutParams params = getLayoutParams();
params.height = getMeasuredHeight();
}else{
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
public void setExpanded(boolean expanded)
{
this.expanded = expanded;
}
}
在您的 m_backdrop.xml 中:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
...
<RelativeLayout
...
<com.package.name.to.class.ExpandExpandableListView
android:id="@+id/FaceList"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="@id/Title_GeneralSettings_text" >
</ExpandableListView>
</RelativeLayout>
</ScrollView>
已经是这样了。它应该按预期工作。
关于android - getChildView 未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15651288/
我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file
如何在ruby中调用C#dll? 最佳答案 我能想到几种可能性:为您的DLL编写(或找人编写)一个COM包装器,如果它还没有,则使用Ruby的WIN32OLE库来调用它;看看RubyCLR,其中一位作者是JohnLam,他继续在Microsoft从事IronRuby方面的工作。(估计不会再维护了,可能不支持.Net2.0以上的版本);正如其他地方已经提到的,看看使用IronRuby,如果这是您的技术选择。有一个主题是here.请注意,最后一篇文章实际上来自JohnLam(看起来像是2009年3月),他似乎很自在地断言RubyCL
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www
我需要一些关于TDD概念的帮助。假设我有以下代码defexecute(command)casecommandwhen"c"create_new_characterwhen"i"display_inventoryendenddefcreate_new_character#dostufftocreatenewcharacterenddefdisplay_inventory#dostufftodisplayinventoryend现在我不确定要为什么编写单元测试。如果我为execute方法编写单元测试,那不是几乎涵盖了我对create_new_character和display_invent
在应用开发中,有时候我们需要获取系统的设备信息,用于数据上报和行为分析。那在鸿蒙系统中,我们应该怎么去获取设备的系统信息呢,比如说获取手机的系统版本号、手机的制造商、手机型号等数据。1、获取方式这里分为两种情况,一种是设备信息的获取,一种是系统信息的获取。1.1、获取设备信息获取设备信息,鸿蒙的SDK包为我们提供了DeviceInfo类,通过该类的一些静态方法,可以获取设备信息,DeviceInfo类的包路径为:ohos.system.DeviceInfo.具体的方法如下:ModifierandTypeMethodDescriptionstatic StringgetAbiList()Obt
说在前面这部分我本来是合为一篇来写的,因为目的是一样的,都是通过独立按键来控制LED闪灭本质上是起到开关的作用,即调用函数和中断函数。但是写一篇太累了,我还是决定分为两篇写,这篇是调用函数篇。在本篇中你主要看到这些东西!!!1.调用函数的方法(主要讲语法和格式)2.独立按键如何控制LED亮灭3.程序中的一些细节(软件消抖等)1.调用函数的方法思路还是比较清晰地,就是通过按下按键来控制LED闪灭,即每按下一次,LED取反一次。重要的是,把按键与LED联系在一起。我打算用K1来作为开关,看了一下开发板原理图,K1连接的是单片机的P31口,当按下K1时,P31是与GND相连的,也就是说,当我按下去时
最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路
如何找到调用此方法的位置?defto_xml(options={})binding.pryoptions=options.to_hifoptions&&options.respond_to?(:to_h)serializable_hash(options).to_xml(options)end 最佳答案 键入caller。这将返回当前调用堆栈。文档:Kernel#caller.例子[0]%rspecspec10/16|===================================================62=====
Rails相对较新。我正在尝试调用一个API,它应该向我返回一个唯一的URL。我的应用程序中捆绑了HTTParty。我已经创建了一个UniqueNumberController,并且我已经阅读了几个HTTParty指南,直到我想要什么,但也许我只是有点迷路,真的不知道该怎么做。基本上,我需要做的就是调用API,获取它返回的URL,然后将该URL插入到用户的数据库中。谁能给我指出正确的方向或与我分享一些代码? 最佳答案 假设API为JSON格式并返回如下数据:{"url":"http://example.com/unique-url"
我正在写一篇关于在Ruby中几乎一切都是对象的博客文章,我试图通过以下示例来展示这一点:classCoolBeansattr_accessor:beansdefinitialize@bean=[]enddefcount_beans@beans.countendend所以从类中我们可以看出它有4个方法(当然,除非我错了):它可以在创建新实例时初始化一个默认的空bean数组它可以计算它有多少个bean它可以读取它有多少个bean(通过attr_accessor)它可以向空数组写入(或添加)更多bean(也通过attr_accessor)但是,当我询问类本身它有哪些实例方法时,我没有看到默认