所以,我有这个用于 PreferenceScreen 的 xml。
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<EditTextPreference
android:dialogMessage="@string/w_common_display_name_desc"
android:key="display_name"
android:summary="@string/w_common_display_name_desc"
android:title="@string/w_common_display_name" />
<EditTextPreference
android:dialogMessage="@string/w_basic_username_desc"
android:inputType="textVisiblePassword"
android:key="username"
android:summary="@string/w_basic_username_desc"
android:title="@string/w_basic_username" />
<EditTextPreference
android:dialogMessage="@string/w_common_server_desc"
android:inputType="textVisiblePassword"
android:key="server"
android:summary="@string/w_common_server_desc"
android:title="@string/w_common_server" />
<com.csipsimple.widgets.PasswordPreference
android:dialogMessage="@string/w_basic_password_desc"
android:key="password"
android:password="true"
android:summary="@string/w_basic_password_desc"
android:title="@string/w_basic_password" />
</PreferenceScreen>
由此 PreferenceActivity 调用。
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
import android.text.TextUtils;
import com.actionbarsherlock.view.Menu;
import com.csipsimple.R;
import com.csipsimple.utils.Log;
public abstract class GenericPrefs extends PreferenceActivity implements
OnSharedPreferenceChangeListener, IPreferenceHelper {
private static final String THIS_FILE = "GenericPrefs";
private static String TAG = "ricky";
public abstract boolean onCreateOptionsMenu(Menu menu);
/**
* Get the xml preference resource for this screen
*
* @return the resource reference
*/
protected abstract int getXmlPreferences();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
beforeBuildPrefs();
addPreferencesFromResource(getXmlPreferences());
afterBuildPrefs();
Log.d(TAG, "GenericPrefs");
}
@Override
public void onResume() {
super.onResume();
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
updateDescriptions();
}
@Override
public void onPause() {
super.onPause();
getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
updateDescriptions();
}
/**
* Process update of description of each preference field
*/
protected abstract void updateDescriptions();
/**
* Optional hook for doing stuff before preference xml is loaded
*/
protected void beforeBuildPrefs() {
// By default, nothing to do
}
/**
* Optional hook for doing stuff just after preference xml is loaded
*/
protected void afterBuildPrefs() {
// By default, nothing to do
}
// Utilities for update Descriptions
/**
* Get field summary if nothing set. By default it will try to add _summary
* to name of the current field
*
* @param field_name Name of the current field
* @return Translated summary for this field
*/
protected String getDefaultFieldSummary(String field_name) {
try {
String keyid = R.string.class.getField(field_name + "_summary").get(null).toString();
return getString(Integer.parseInt(keyid));
} catch (SecurityException e) {
// Nothing to do : desc is null
} catch (NoSuchFieldException e) {
// Nothing to do : desc is null
} catch (IllegalArgumentException e) {
// Nothing to do : desc is null
} catch (IllegalAccessException e) {
// Nothing to do : desc is null
}
return "";
}
/**
* Set summary of a standard string field If empty will display the default
* summary Else it displays the preference value
*
* @param fieldName the preference key name
*/
public void setStringFieldSummary(String fieldName) {
PreferenceScreen pfs = getPreferenceScreen();
SharedPreferences sp = pfs.getSharedPreferences();
Preference pref = pfs.findPreference(fieldName);
String val = sp.getString(fieldName, null);
if (TextUtils.isEmpty(val)) {
val = getDefaultFieldSummary(fieldName);
Log.d(TAG, "genericPrefs field summary: "+val);
}
setPreferenceSummary(pref, val);
}
/**
* Set summary of a password field If empty will display default summary If
* password will display a * char for each letter of password
*
* @param fieldName the preference key name
*/
public void setPasswordFieldSummary(String fieldName) {
PreferenceScreen pfs = getPreferenceScreen();
SharedPreferences sp = pfs.getSharedPreferences();
Preference pref = pfs.findPreference(fieldName);
String val = sp.getString(fieldName, null);
if (TextUtils.isEmpty(val)) {
val = getDefaultFieldSummary(fieldName);
} else {
val = val.replaceAll(".", "*");
}
setPreferenceSummary(pref, val);
}
/**
* Set summary of a list field If empty will display default summary If one
* item selected will display item name
*
* @param fieldName the preference key name
*/
public void setListFieldSummary(String fieldName) {
PreferenceScreen pfs = getPreferenceScreen();
ListPreference pref = (ListPreference) pfs.findPreference(fieldName);
if (pref == null) {
Log.w(THIS_FILE, "Unable to find preference " + fieldName);
return;
}
CharSequence val = pref.getEntry();
if (TextUtils.isEmpty(val)) {
val = getDefaultFieldSummary(fieldName);
}
setPreferenceSummary(pref, val);
}
/**
* Safe setSummary on a Preference object that make sure that the preference
* exists before doing anything
*
* @param pref the preference to change summary of
* @param val the string to set as preference summary
*/
protected void setPreferenceSummary(Preference pref, CharSequence val) {
if (pref != null) {
pref.setSummary(val);
}
}
/**
* Hide a preference from the screen so that user can't see and modify it
*
* @param parent the parent group preference if any, leave null if
* preference is a root pref
* @param fieldName the preference key name to hide
*/
public void hidePreference(String parent, String fieldName) {
PreferenceScreen pfs = getPreferenceScreen();
PreferenceGroup parentPref = pfs;
if (parent != null) {
parentPref = (PreferenceGroup) pfs.findPreference(parent);
}
Preference toRemovePref = pfs.findPreference(fieldName);
if (toRemovePref != null && parentPref != null) {
parentPref.removePreference(toRemovePref);
} else {
Log.w("Generic prefs", "Not able to find" + parent + " " + fieldName);
}
}
@Override
public void setPreferenceScreenType(String key, int type) {
setPreferenceScreenType(getClass(), key, type);
}
@Override
public void setPreferenceScreenSub(String key, Class<?> activityClass, Class<?> fragmentClass, int type) {
setPreferenceScreenType(activityClass, key, type);
}
private void setPreferenceScreenType(Class<?> classObj, String key, int type) {
Preference pf = findPreference(key);
Intent it = new Intent(this, classObj);
it.putExtra(PrefsLogic.EXTRA_PREFERENCE_TYPE, type);
pf.setIntent(it);
}
/* (non-Javadoc)
* @see android.preference.PreferenceActivity#isValidFragment(java.lang.String)
*/
public boolean isValidFragment(String fragmentName) {
// This pref activity does not include any fragment
return false;
}
}
我看了很多关于 PreferenceScreen 的教程,xml 看起来不错。这是之前使用 SherlockFragment 的项目的一部分,我目前正在升级它的部分代码。当我编译应用程序时,summary 由于某种原因没有显示。 dialogMessage 显示得很好。
我已经在我的 AndroidManifest 中添加了它。
implementation 'com.android.support:preference-v7:28.0.0'
我今天发现代码使用的 ListView 即使在布局编辑器中也没有显示任何内容。我尝试用 RecyclerView 替换它,但它抛出错误 Caused by: java.lang.ClassCastException: android.support.v7.widget.RecyclerView cannot be cast to android.widget.ListView。我寻找任何类似 findViewById 的东西,但找不到任何东西。我宁愿处理不显示任何错误,因为我觉得它比前者更复杂。
这是用于显示 PreferenceScreen 的 xml。
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2010 Regis Montoya (aka r3gis - www.r3gis.fr)
This file is part of CSipSimple.
CSipSimple is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
If you own a pjsip commercial license you can also redistribute it
and/or modify it under the terms of the GNU Lesser General Public License
as an android library.
CSipSimple is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CSipSimple. If not, see <http://www.gnu.org/licenses/>.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/settings_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/validation_bar"
android:orientation="vertical">
<LinearLayout
android:id="@+id/custom_wizard_row"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:id="@+id/custom_wizard_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/white" />
<ImageView
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:drawable/divider_horizontal_dark"
android:contentDescription="@string/empty_description" />
</LinearLayout>
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false"
tools:listitem="@layout/adptr_simple"
android:layoutAnimation="@anim/layout_slide_right"
android:persistentDrawingCache="animation|scrolling" />
</LinearLayout>
<LinearLayout
android:id="@+id/validation_bar"
style="@style/ButtonBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<Button
android:id="@+id/cancel_bt"
style="@style/ButtonBarButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="@string/cancel" />
<Button
android:id="@+id/save_bt"
style="@style/ButtonBarButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="@string/save" />
</LinearLayout>
</RelativeLayout>
我尝试更改 Theme 但它仍然不显示文本。我尝试删除 android:layoutAnimation 和 android:persistentDrawingCache 但它仍然没有显示 summary。
这是 adptr_simple.xml 因为有人要求它。
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:text="TextView"
android:textColor="#FFFFFF"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="16dp"
android:text="TextView"
android:textColor="#FFFFFF"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/textView"
app:layout_constraintHorizontal_bias="0.507"
app:layout_constraintStart_toStartOf="@+id/textView"
app:layout_constraintTop_toBottomOf="@+id/textView" />
</android.support.constraint.ConstraintLayout>
最佳答案
猜测这些线路有问题:
String keyid = R.string.class.getField(field_name + "_summary").get(null).toString();
return getString(Integer.parseInt(keyid));
关于android - 更新应用程序后 PreferenceScreen 不显示摘要,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57230978/
我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0
给定这段代码defcreate@upgrades=User.update_all(["role=?","upgraded"],:id=>params[:upgrade])redirect_toadmin_upgrades_path,:notice=>"Successfullyupgradeduser."end我如何在该操作中实际验证它们是否已保存或未重定向到适当的页面和消息? 最佳答案 在Rails3中,update_all不返回任何有意义的信息,除了已更新的记录数(这可能取决于您的DBMS是否返回该信息)。http://ar.ru
对于具有离线功能的智能手机应用程序,我正在为Xml文件创建单向文本同步。我希望我的服务器将增量/差异(例如GNU差异补丁)发送到目标设备。这是计划:Time=0Server:hasversion_1ofXmlfile(~800kiB)Client:hasversion_1ofXmlfile(~800kiB)Time=1Server:hasversion_1andversion_2ofXmlfile(each~800kiB)computesdeltaoftheseversions(=patch)(~10kiB)sendspatchtoClient(~10kiBtransferred)Cl
我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格:Editingkategori{:action=>'update',:id=>@konkurrancer.id})do|f|%>'Trackingurl',:style=>'width:500;'%>'Editkonkurrence'%>|我的konkurrencer模型:has_one:link我的链接模型:classLink我的konkurrancer编辑操作:defedit@konkurrancer=Konkurrancer.find(params[:id])@konkurrancer.link_attrib
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
Rackup通过Rack的默认处理程序成功运行任何Rack应用程序。例如:classRackAppdefcall(environment)['200',{'Content-Type'=>'text/html'},["Helloworld"]]endendrunRackApp.new但是当最后一行更改为使用Rack的内置CGI处理程序时,rackup给出“NoMethodErrorat/undefinedmethod`call'fornil:NilClass”:Rack::Handler::CGI.runRackApp.newRack的其他内置处理程序也提出了同样的反对意见。例如Rack
我想用ruby编写一个小的命令行实用程序并将其作为gem分发。我知道安装后,Guard、Sass和Thor等某些gem可以从命令行自行运行。为了让gem像二进制文件一样可用,我需要在我的gemspec中指定什么。 最佳答案 Gem::Specification.newdo|s|...s.executable='name_of_executable'...endhttp://docs.rubygems.org/read/chapter/20 关于ruby-在Ruby中编写命令行实用程序
我构建了两个需要相互通信和发送文件的Rails应用程序。例如,一个Rails应用程序会发送请求以查看其他应用程序数据库中的表。然后另一个应用程序将呈现该表的json并将其发回。我还希望一个应用程序将存储在其公共(public)目录中的文本文件发送到另一个应用程序的公共(public)目录。我从来没有做过这样的事情,所以我什至不知道从哪里开始。任何帮助,将不胜感激。谢谢! 最佳答案 无论Rails是什么,几乎所有Web应用程序都有您的要求,大多数现代Web应用程序都需要相互通信。但是有一个小小的理解需要你坚持下去,网站不应直接访问彼此
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
刚入门rails,开始慢慢理解。有人可以解释或给我一些关于在application_controller中编码的好处或时间和原因的想法吗?有哪些用例。您如何为Rails应用程序使用应用程序Controller?我不想在那里放太多代码,因为据我了解,每个请求都会调用此Controller。这是真的? 最佳答案 ApplicationController实际上是您应用程序中的每个其他Controller都将从中继承的类(尽管这不是强制性的)。我同意不要用太多代码弄乱它并保持干净整洁的态度,尽管在某些情况下ApplicationContr