我正在尝试将ImageView添加到首选项片段,以显示颜色设置的预览.我正在通过onCreateView方法访问imageview的实例来设置测试颜色,它将显示.但是它只有在我没有在onCreate方法中调用addPreferencesFromResource时才有效 - 这是一个问题,因为必须添加首选项.此外,如果我将调用留给addPreferencesFromResource,但删除整个onCreateView方法,程序将运行(没有可更新的imageview的albiet).
两种情况下的错误都是"内容具有id属性的视图'android.R.id.list',而不是ListView类"
我试图从onCreate访问imageview,但到那时布局项目被夸大了,我似乎无法访问显示的实际实例.
LogCat出错:
04-11 00:42:43.619: E/AndroidRuntime(5362): FATAL EXCEPTION: main
04-11 00:42:43.619: E/AndroidRuntime(5362): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.signalwidget/com.example.android.signalwidget.SignalWidgetConfigure}: java.lang.RuntimeException: Content has view with id attribute 'android.R.id.list' that is not a ListView class
Run Code Online (Sandbox Code Playgroud)
这里是带有内联片段的PreferenceActivity:
public class SigConfigure extends PreferenceActivity {
private static int prefs=R.xml.pref_widget_colors;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//getFragmentManager().beginTransaction().replace(android.R.id.content, new ColorsFragment()).commit();
}
@Override
public void onBuildHeaders(List<Header> target) {
loadHeadersFromResource(R.xml.pref_headers, target);
}
public static class ColorsFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); …Run Code Online (Sandbox Code Playgroud) 蓝牙FTP规范说我需要使用ACTION操作,这是一个页面 http://i47.tinypic.com/2425t2v.png
但是ClentSession只提供GET和PUT操作,而javadocs中没有提到任何内容.
这是创建文件操作的外观,非常简单
public void create() throws IOException {
HeaderSet hs = cs.createHeaderSet();
hs.setHeader(HeaderSet.NAME, file);
op = cs.put(hs);
OutputStream os = op.openOutputStream();
os.close();
op.close();
}
Run Code Online (Sandbox Code Playgroud)
问题1:如何使用自定义标头实施ACTION操作以执行移动/重命名和设置权限?没有JSR82 OBEX API就应该可以.请帮我这样做.
问题2:我是否了解如何设置权限?根据OBEX_Errata Compiled For 1.3.pdf(感谢alanjmcf!)
1 http://i45.tinypic.com/2h84led.jpg
2 http://i49.tinypic.com/2wgysmx.png
因此,要设置只读,我应该执行以下操作:
int a = 0;
//byte 0 //zero
//byte 1 //user
//byte 2 //group
//byte 3 //other
//set read for user
a |= (1 << 7); //8th bit - byte 1, bit 0 -> set to 1
// a = 10000000 …Run Code Online (Sandbox Code Playgroud) 我希望即使在无法选择的项目上也显示首选项ListView分隔符。
情况1:项目是不可选择的(我需要),并且没有分隔符(我不需要):
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory
android:title="@string/storage_usage">
<Preference
android:key="pref_available_space"
android:title="@string/available_space"
android:selectable="false"
android:shouldDisableView="false"
android:enabled="false" />
<Preference
android:key="pref_used_by_library"
android:title="@string/used_by_library"
android:selectable="false"
android:shouldDisableView="false"
android:enabled="false" />
<Preference
android:key="pref_available_time"
android:title="@string/available_time"
android:selectable="false"
android:shouldDisableView="false"
android:enabled="false" />
</PreferenceCategory>
</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)
如果您想知道为什么,则需要密钥来设置代码中的值。它除了显示信息外什么也不做。
情况2:
如果我设置
selectable="true"
Run Code Online (Sandbox Code Playgroud)
这些项目是可选的(我不需要),并且显示了分隔符(我需要)。
让我们假设我们有三个(或更多)类
公共课A {}
公共B级扩展A {}
公共类C扩展B实现G {}
假设每个类都有自己的20个(或更多)方法.
铸造到C与铸造到A对性能有更大的影响吗?Java编译如何在幕后工作?
在向下投射时,是否必须通过反射检查所有方法和字段是否存在?
编辑: 类的大小(字段和方法的数量)是否会在投射时影响性能?我对OpenJRE和Dalvik感兴趣.
作为参考,我知道可以毫无问题地完成向上转换.
玩这个三个小时,无法弄清楚是什么问题.
private static Notification buildNotification(Context context) {
NotificationCompat.Builder b = new NotificationCompat.Builder(context);
b.setContentIntent(PendingIntent.getActivity(
context, 0, new Intent(context, MyActivity.class),
PendingIntent.FLAG_UPDATE_CURRENT));
b.setTicker(context.getString(R.string.update_notification_title));
b.setContentTitle(context.getString(R.string.update_notification_title));
b.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.icon));
b.setSmallIcon(R.drawable.icon);
b.setOngoing(true);
b.setAutoCancel(false);
b.setProgress(100, 0, true);
Intent cancel = new Intent(context, Updater.class);
cancel.putExtra(EXTRA_CANCEL, true);
b.addAction(
R.drawable.discard_holo_dark,
context.getString(R.string.ui_cancel),
PendingIntent.getService(context, 0, cancel, PendingIntent.FLAG_UPDATE_CURRENT));
return b.build();
}
Run Code Online (Sandbox Code Playgroud)
我也在JellyBean上尝试了默认的NotificationBuilder.也试图将PendingIntent更改为getActivity并尝试替换图标和文本.尝试setOngoing(false),没有进展和autoCancel.仍然没有按钮的运气.试过四种不同的设备.
private static int changedFocus;
private static boolean focusGranted;
private static AudioManager audioManager;
public static int getChangedFocus() {
return changedFocus;
}
public static boolean isFocusGranted() {
return focusGranted;
}
public static void requestFocus(final Context context) {
if (audioManager == null) {
audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
}
switch (audioManager.requestAudioFocus(OnFocusChangeListener.getInstance(),
AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN)) {
case AudioManager.AUDIOFOCUS_REQUEST_GRANTED:
focusGranted = true;
break;
case AudioManager.AUDIOFOCUS_REQUEST_FAILED:
focusGranted = false;
break;
}
}
private static final class OnFocusChangeListener implements AudioManager.OnAudioFocusChangeListener {
private static OnFocusChangeListener instance;
protected static OnFocusChangeListener getInstance() …Run Code Online (Sandbox Code Playgroud) 我收到Gradle关于弃用动态属性的警告.
不建议按需创建属性(也称为动态属性),并计划在Gradle 2.0中删除它们.有关替换动态属性的信息,请阅读http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html.不推荐使用的动态属性:"source set aild"上的"srcDirs",值:"[src]".在多个位置创建的不推荐使用的动态属性"srcDirs".
不幸的是,我不擅长Gradle语法,所以在阅读上面的文章后,我无法理解应该更改哪些值以迁移到新标准.
该项目仍然可以在Eclipse中构建,因此配置就像
apply plugin: 'android'
android {
buildToolsVersion "19.0.3"
compileSdkVersion 19
buildTypes {
...
}
productFlavors {
...
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java {
srcDirs = ['src']
}
resources.srcDirs = ['src']
aild.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
lib.srcDirs = ['libs']
jniLibs.srcDirs=['libs']
}
full {
java {
srcDirs = ['flavors/full/src']
}
}
light {
java {
srcDirs = ['flavors/light/src']
}
res {
srcDirs 'flavors/light/res'
} …Run Code Online (Sandbox Code Playgroud)