我尝试删除线性布局的所有 subview ,但没有删除任何内容,奇怪的是相同的代码正在另一个应用程序中工作。 Here's the sample code of the method that populate the choiceHolder whenever a tab in it is selected (I remove all view and mark the selected one and populate basing on that:
/** a method to fill the upper bar where we choose the {@link CategoriesMyBox}
* @param category
*/
private void fillNavigationBar( CategoriesGetter category) {
TextView categoryTxt = new TextView(getActivity());
// categoryTxt.setAllCaps(true);
LinearLayout.LayoutParams txtParams;
if (category.isSelected() /*|| (category.getId_categorie()==0 && allselected)*/) {
txtParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
txtParams.gravity = Gravity.CENTER;
categoryTxt.setGravity(Gravity.CENTER);
categoryTxt.setTextSize(categoryTxt.getTextSize());
txtParams.setMargins(10, 0, 10, 0);
categoryTxt.setPadding(5, 5, 5, 5);
if (category.getId_categorie() == 0) {
categoryTxt.setText(getResources().getString(R.string.all_boxs));
}else {
categoryTxt.setText(category.getName_categorie());
}
categoryTxt.setTextColor(Color.GREEN);
categoryTxt.setBackgroundDrawable(getResources().getDrawable(R.drawable.back_categories_selected));
// categoryTxt.setBackgroundColor(Color.parseColor("#E3E8E6"));
categoryTxt.setTag(category);
}else {
txtParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
txtParams.setMargins(10, 0, 10, 0);
categoryTxt.setGravity(Gravity.CENTER);
categoryTxt.setPadding(5, 5, 5, 5);
txtParams.gravity = Gravity.CENTER;
if (category.getId_categorie() == 0) {
categoryTxt.setText(getResources().getString(R.string.all_boxs));
}else {
categoryTxt.setText((category.getName_categorie()));
}
categoryTxt.setTextColor(Color.GRAY);
categoryTxt.setBackgroundDrawable(getResources().getDrawable(R.drawable.back_categories));
// categoryTxt.setBackgroundColor(Color.parseColor("#777777"));
categoryTxt.setTag(category);
}
choiceHolder.addView(categoryTxt, txtParams);
categoryTxt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
CategoriesGetter cat = (CategoriesGetter)v.getTag();
id_cat = cat.getId_categorie();
for (int i = 0; i < categories.size(); i++) {
categories.get(i).setSelected(false);
}
cat.setSelected(true);
// choiceHolder.removeAllViews();
/*for(int i=0; i<((ViewGroup)choiceHolder).getChildCount(); ++i) {
View nextChild = ((ViewGroup)choiceHolder).getChildAt(i);
choiceHolder.removeView(nextChild);
}*/
while (((ViewGroup)choiceHolder).getChildCount() >0) {
View nextChild = ((ViewGroup)choiceHolder).getChildAt(0);
choiceHolder.removeView(nextChild);
}
// choiceHolder.removeAllViewsInLayout();
for (int i = 0; i < categories.size(); i++) {
fillNavigationBar(categories.get(i));
}
callbackCategory.selectCategory(cat.getId_categorie());
}
});
}
choiceHolder 是一个LinearLayout。
这是一张显示问题的图片:
我的所有应用程序都以相同的方式运行,即使在更新内部列表时我仍然可以看到之前的列表。
最佳答案
我为这个问题找到的解决方案是从 AndroidManifest 中的 Activity 中删除 fullScreen 主题标签,它是这样的:
<application
android:name="com.paperpad.mybox.ApplicationInit"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.paperpad.mybox.activities.SplashActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.crashlytics.ApiKey"
android:value="023e7fe8a4a93f93ffe7510201929d081b125313" />
<activity
android:name="com.paperpad.mybox.activities.BoxsMainActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/title_activity_boxs_main"
android:theme="@style/FullscreenTheme" >
</activity>
<activity
android:name="com.paperpad.mybox.LoginActivity"
android:label="@string/title_activity_login"
android:windowSoftInputMode="adjustResize|stateVisible" >
</activity>
</application>
通过从 Activity BoxsMainActivity 中删除 android:theme="@style/FullscreenTheme" 一切正常。希望这对某人有帮助...
关于android - RemoveAllViews 不删除 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21041489/
我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何
我想要做的是有2个不同的Controller,client和test_client。客户端Controller已经构建,我想创建一个test_clientController,我可以使用它来玩弄客户端的UI并根据需要进行调整。我主要是想绕过我在客户端中内置的验证及其对加载数据的管理Controller的依赖。所以我希望test_clientController加载示例数据集,然后呈现客户端Controller的索引View,以便我可以调整客户端UI。就是这样。我在test_clients索引方法中试过这个:classTestClientdefindexrender:template=>
我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为
查看Ruby的CSV库的文档,我非常确定这是可能且简单的。我只需要使用Ruby删除CSV文件的前三列,但我没有成功运行它。 最佳答案 csv_table=CSV.read(file_path_in,:headers=>true)csv_table.delete("header_name")csv_table.to_csv#=>ThenewCSVinstringformat检查CSV::Table文档:http://ruby-doc.org/stdlib-1.9.2/libdoc/csv/rdoc/CSV/Table.html
我发现ActiveRecord::Base.transaction在复杂方法中非常有效。我想知道是否可以在如下事务中从AWSS3上传/删除文件:S3Object.transactiondo#writeintofiles#raiseanexceptionend引发异常后,每个操作都应在S3上回滚。S3Object这可能吗?? 最佳答案 虽然S3API具有批量删除功能,但它不支持事务,因为每个删除操作都可以独立于其他操作成功/失败。该API不提供任何批量上传功能(通过PUT或POST),因此每个上传操作都是通过一个独立的API调用完成的
我是一个Rails初学者,但我想从我的RailsView(html.haml文件)中查看Ruby变量的内容。我试图在ruby中打印出变量(认为它会在终端中出现),但没有得到任何结果。有什么建议吗?我知道Rails调试器,但更喜欢使用inspect来打印我的变量。 最佳答案 您可以在View中使用puts方法将信息输出到服务器控制台。您应该能够在View中的任何位置使用Haml执行以下操作:-puts@my_variable.inspect 关于ruby-on-rails-如何在我的R
我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c
在Ruby中是否有Gem或安全删除文件的方法?我想避免系统上可能不存在的外部程序。“安全删除”指的是覆盖文件内容。 最佳答案 如果您使用的是*nix,一个很好的方法是使用exec/open3/open4调用shred:`shred-fxuz#{filename}`http://www.gnu.org/s/coreutils/manual/html_node/shred-invocation.html检查这个类似的帖子:Writingafileshredderinpythonorruby?
目前,Itembelongs_toCompany和has_manyItemVariants。我正在尝试使用嵌套的fields_for通过Item表单添加ItemVariant字段,但是使用:item_variants不显示该表单。只有当我使用单数时才会显示。我检查了我的关联,它们似乎是正确的,这可能与嵌套在公司下的项目有关,还是我遗漏了其他东西?提前致谢。注意:下面的代码片段中省略了不相关的代码。编辑:不知道这是否相关,但我正在使用CanCan进行身份验证。routes.rbresources:companiesdoresources:itemsenditem.rbclassItemi
我正在尝试找到一种方法来规范化字符串以将其作为文件名传递。到目前为止我有这个:my_string.mb_chars.normalize(:kd).gsub(/[^\x00-\x7F]/n,'').downcase.gsub(/[^a-z]/,'_')但第一个问题:-字符。我猜这个方法还有更多问题。我不控制名称,名称字符串可以有重音符、空格和特殊字符。我想删除所有这些,用相应的字母('é'=>'e')替换重音符号,并将其余的替换为'_'字符。名字是这样的:“Prélèvements-常规”“健康证”...我希望它们像一个没有空格/特殊字符的文件名:“prelevements_routin