我是android新手,我想用SQLite创建一种CRUD.
我有一个public class DataBaseHelper有构造函数:
public DataBaseHelper(Context context)
{
this.context = context;
}
Run Code Online (Sandbox Code Playgroud)
和datebase的getter:
public SQLiteDatabase getDataBase() {
if (dataBase == null) {
try {
dataBase = context.openOrCreateDatabase(DataBaseHelper.dbName,
Context.MODE_PRIVATE, null);
dataBase.execSQL("CREATE TABLE " + DataBaseHelper.accountTblName + " " +
"(ID integer PRIMARY KEY AUTOINCREMENT" +
",name TEXT" +
",address TEXT" +
",password TEXT)");
}
catch(Exception e) {
Log.e(context.toString(), e.getMessage());
if (dataBase != null) {
dataBase.close();
}
}
}
return dataBase;
}
Run Code Online (Sandbox Code Playgroud)
如果我是第一次启动程序 - 一切似乎都没问题.数据库为null,我创建它(使用表).但是当我重新启动我的app数据库时,它再次为null并且无法创建表.
我决定编写一个checkDB函数,它试图打开一个数据库.但是我在哪里可以找到它的路径?我不希望它被"硬编码".
或者我可能正在做某种反模式?
我有一个构造函数
private Double mA;
private Double mB;
Foo(Double a) {
mA = a;
mB = a + 10;
}
Foo(Double a, Double b) {
mA = a;
mB = b;
// some logic here
}
Run Code Online (Sandbox Code Playgroud)
如果我这样调用第二个构造函数:
Foo(Double a) {
Double b = a + 10;
this(a, b);
}
Run Code Online (Sandbox Code Playgroud)
比编译器告诉我的那样,那个构造函数应该是第一个语句.那么我需要将所有逻辑从第二个构造函数复制到第一个构造函数吗?
我是linux驱动程序dev的新手.
我正在写helloworld的驱动程序.
这是代码:
#define MODULE
#define __KERNEL__
#include <module.h>
int init_module()
{
return 0;
}
void cleanup_module()
{
return;
}
Run Code Online (Sandbox Code Playgroud)
这是makefile:
CC=gcc
MODFLAGS:= -O3 -Wall -DLINUX
module.o: module.c
$(CC) $(MODFLAGS) -c module.c
Run Code Online (Sandbox Code Playgroud)
但是当我运行make命令时,我有以下内容:makefile:3:* "命令在第一个目标之前开始"错误
怎么了?
与ScrollView相同的问题.scrollTo无法正常工作?在旋转时保存ScrollView位置
我在onCreate中动态添加项目到scrollView.添加完所有项目后,我会尝试以下操作:
// no effect
ScrollView mainScroll = (ScrollView) findViewById(R.id.average_scroll_mainScroll);
// no effect
ScrollView mainScroll = (ScrollView) findViewById(R.id.average_scroll_mainScroll);
mainScroll.post(new Runnable() {
public void run(){
ScrollView mainScroll = (ScrollView) findViewById(R.id.average_scroll_mainScroll);
mainScroll.scrollTo(0, 0);
}
});
// works like a charm
ScrollView mainScroll = (ScrollView) findViewById(R.id.average_scroll_mainScroll);
mainScroll.postDelayed(new Runnable() {
public void run(){
ScrollView mainScroll = (ScrollView) findViewById(R.id.average_scroll_mainScroll);
mainScroll.scrollTo(0, 0);
}
}, 30);
Run Code Online (Sandbox Code Playgroud)
我得出结论,有一些事件像'DOM-ready'?有没有回调?
我有一个 4 秒视频 ( NSTimeInterval duration = CMTimeGetSeconds(self.playerItem.asset.duration)= 4)的 AVPlayer 。
我想通过更改更新用户界面:
self.periodicTimeObserver = [self.player addPeriodicTimeObserverForInterval:CMTimeMake(1, 1) queue:dispatch_get_main_queue() usingBlock:^(CMTime time) {
[weakSelf currentTimeDidChange:CMTimeGetSeconds(time)];
}];
Run Code Online (Sandbox Code Playgroud)
但由于某些原因,我收到了对 UI 的额外调用:
- (void)currentTimeDidChange:(NSTimeInterval)currentTime {
NSLog(@"timePassed %f, total: %f", currentTime, self.duration);
}
Run Code Online (Sandbox Code Playgroud)
日志:
2015-07-23 13:47:07.412 timePassed 0.000000, total: 4.000000
2015-07-23 13:47:07.448 timePassed 0.002814, total: 4.000000
2015-07-23 13:47:07.450 timePassed 0.005481, total: 4.000000
2015-07-23 13:47:08.447 timePassed 1.001473, total: 4.000000
2015-07-23 13:47:09.446 timePassed 2.001612, total: 4.000000
2015-07-23 13:47:10.446 timePassed 3.002021, total: 4.000000
2015-07-23 13:47:11.446 timePassed 4.002139, total: …Run Code Online (Sandbox Code Playgroud) 我无法理解为什么这个有效:
var arr = [4,5,6,7]
arr.map() {
x in
return x + 2
}
Run Code Online (Sandbox Code Playgroud)
虽然这不是
arr.map() {
x in
var y = x + 2
return y
}
Run Code Online (Sandbox Code Playgroud)
有错误
Playground执行失败:MyPlayground.playground:13:5:错误:无法使用类型'((_) - > _)'arr.map(){的参数列表调用'map'
假设我有以下解析器与joda-time lib for android
DateTimeFormat.forPattern("dd.MM.yyyy").parseDateTime(maybeDate);
Run Code Online (Sandbox Code Playgroud)
我的目标是使用TextWatcher过滤某些editText中的输入,并尝试解析输入并检查它是否为Date.
尽管有4个"y"字母,但以下时间通过了这种模式!
06.12.1(当我试图把2008年12月6日)
格式化程序的PS appendYear(4,4)也失败了.
我将其他布局添加到我当前的布局,如下所示:
LinearLayout parent = (LinearLayout)findViewById(R.id.average_layout_salaryListContainer);
for (String month : mVacation.getMonthNameList()) {
LinearLayout childElement = (LinearLayout) LayoutInflater.from(getApplicationContext()).inflate(R.layout.salary_list_element, null);
TextView monthTextView = (TextView) childElement.findViewById(R.id.salary_list_element_textView_month);
monthTextView.setText(month);
parent.addView(childElement);
}
Run Code Online (Sandbox Code Playgroud)
虽然我有很多月份(12个或更多),但一些添加的元素是不可见的,但我无法向下滚动.怎么避免这个?