我正在使用PreferenceActivity让用户设置一些值.我正在使用定义的首选项为xml文件提供它.
我android:defaultValue=""为他们设置了全部.
当我启动我的应用程序时,我需要首选项,或者如果它们尚未手动设置,我想要默认值:
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean value = prefs.getBoolean("key"), false);
Run Code Online (Sandbox Code Playgroud)
但是,当android:defaultValue="true"我还是得到的时候false.因此,看起来XML中设置的defaultValues不会在初始化首选项屏幕时使用.
我不想硬编码方法中的默认值getBoolean().那么,有没有办法获得默认值,只在一个地方定义这些?
我想知道,在创建新Activity类然后重写onCreate()方法时,在eclipse中我总是自动添加:super.onCreate().这是怎么发生的?抽象或父类中是否有一个强制执行此操作的java关键字?
我不知道调用超类是否违法,但我记得在某些方法中我因为没有这样做而抛出异常.这也是内置到java中的吗?你可以使用一些关键字来做到这一点吗?或者它是如何完成的?
我想做这个:
public Name
{
get;
set
{
dosomething();
??? = value
}
}
Run Code Online (Sandbox Code Playgroud)
是否可以使用自动生成的私有字段?
或者我需要以这种方式实现它:
private string name;
public string Name
{
get
{
return name;
}
set
{
dosomething();
name = value
}
}
Run Code Online (Sandbox Code Playgroud) 我想在Code中生成一个WPF Path对象.
在XAML中,我可以这样做:
<Path Data="M 100,200 C 100,25 400,350 400,175 H 280">
Run Code Online (Sandbox Code Playgroud)
我怎样才能在Code中做同样的事情?
Path path = new Path();
Path.Data = "foo"; //This won't accept a string as path data.
Run Code Online (Sandbox Code Playgroud)
是否有可用将PathData转换为PathGeometry或类似字符串的类/方法?
当然不知何故XAML被解析并且数据字符串被转换了?
我想要一组按钮,用户可以选择其中一个作为选项.它必须是像行为一样的无线电组,但我不希望无线电圈存在.我只希望用户只能切换其中一个按钮.
我想我需要像togglegroup一样.
Android中是否存在类似的内容?
我有一个对象,其属性的计算成本很高,因此它们仅在首次访问时计算,然后进行缓存.
private List<Note> notes;
public List<Note> Notes
{
get
{
if (this.notes == null)
{
this.notes = CalcNotes();
}
return this.notes;
}
}
Run Code Online (Sandbox Code Playgroud)
我想知道,有更好的方法吗?是否有可能在C#中创建一个Cached属性或类似的东西?
我想知道,在C#中构造新对象的首选方法是什么?
参加一个Person课程:
public class Person
{
private string name;
private int age;
//Omitted..
}
Run Code Online (Sandbox Code Playgroud)
我应该创建它来使用:
New Person("name", 24);
Run Code Online (Sandbox Code Playgroud)
要么
New Person() { Name = "name", Age = 24 };
Run Code Online (Sandbox Code Playgroud)
这只是一个品味的问题,还是有充分的理由使用一个而不是另一个?
我可以想象一个人应该只使用构造函数中的必需字段和可选字段而不是构造函数参数,而是使用属性.
我是对的吗?
我有一个使用ActiveAndroid的应用程序,它是一个依赖于注释的数据库ORM库.
@Table(name="test")
public class DatabaseItem extends ActiveRecordBase<DatabaseItem> {
public DatabaseItem(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
@Column(name="counter")
public int counter;
}
Run Code Online (Sandbox Code Playgroud)
我如何让Proguard与之合作得很好?目前,我在使用Proguard时遇到ActiveAndroid没有找到列名的错误.我想它以某种方式破坏了注释.
我的相关Proguard配置:
#ActiveAndroid
-keep public class com.activeandroid.**
-keep public class * extends com.activeandroid.ActiveRecordBase
-keepattributes Column
-keepattributes Table
Run Code Online (Sandbox Code Playgroud) 我面临一个奇怪的错误,只在iOS 10上发生.
我有几个画面的应用程序,每个屏幕的颜色navigationBar在viewWillAppear.因此,当您进入下一个屏幕时,它将被正确着色.
但是,在iOS 10上进行测试时,我会在返回上一个屏幕时突然看到以下行为:当前一个屏幕出现时,navigationBar仍然具有上一个屏幕的颜色,然后闪烁到正确的颜色.它几乎看起来像viewWillAppear某种行为viewDidAppear.
相关代码:
视图控制器:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[ViewControllerPainter paint:self withBackground:[UIColor whiteColor] andForeground:[UIColor blackColor] andIsLight:true];
}
Run Code Online (Sandbox Code Playgroud)
画家:
+ (void)paint:(UIViewController *)controller withBackground:(UIColor *)backgroundColor andForeground:(UIColor *)foregroundColor andIsLight:(bool)isLight
{
controller.navigationController.navigationBar.opaque = true;
controller.navigationController.navigationBar.translucent = false;
controller.navigationController.navigationBar.tintColor = foregroundColor;
controller.navigationController.navigationBar.barTintColor = backgroundColor;
controller.navigationController.navigationBar.backgroundColor = backgroundColor;
controller.navigationController.navigationBar.barStyle = isLight ? UIBarStyleDefault : UIBarStyleBlack;
controller.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: foregroundColor};
}
Run Code Online (Sandbox Code Playgroud)
这是一个错误吗?我能解决这个问题吗?这非常令人沮丧.
我想知道,size()你可以调用现有ArrayList<T>缓存的方法吗?或者在性能关键代码中,我只是将其存储size()在本地int中?
当你不在调用之间添加/删除项目时,我希望它确实被缓存size().
我对吗?
更新
我不是在谈论内联或类似的事情.我只是想知道方法size()本身是否在内部缓存值,或者它是否每次调用时都会动态计算.
c# ×4
android ×3
java ×3
properties ×3
caching ×2
annotations ×1
arraylist ×1
constructor ×1
default ×1
ios10 ×1
oop ×1
overriding ×1
path ×1
preferences ×1
proguard ×1
super ×1
wpf ×1