我想在SD卡上创建一个sqlite数据库(不想用尽用户的内部存储).我熟悉OpenHelper模式:
public DatabaseFoo(Context context) {
OpenHelper openHelper = new OpenHelper(context);
mDb = openHelper.getWritableDatabase();
}
private static class OpenHelper extends SQLiteOpenHelper {
public OpenHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
...
Run Code Online (Sandbox Code Playgroud)
所以,如果我们想在SD卡上创建,我认为我们必须使用:
public static SQLiteDatabase openOrCreateDatabase (String path,
SQLiteDatabase.CursorFactory factory);
Run Code Online (Sandbox Code Playgroud)
但是什么是"工厂"的说法,应该使用什么工厂?
还有点担心如果用户在我的应用程序正在使用时删除SD卡会发生什么.
谢谢
我在本教程中将图像显示在GridView中.我希望能够点击单个图像并执行其他事件,我需要知道点击了什么图像.
我是否必须在ImageAdapter类中添加imageView.onKeyDown(keyCode,event)?这是当前存在的代码:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) {
// if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
//does this need imageView.onKeyDown(keyCode, event)?
}
else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
Run Code Online (Sandbox Code Playgroud)
它将如何显示点击的图像?如何创建正确的处理程序?
我在选项菜单上有这个代码
Dialog dialog = new Dialog(ScheduleActivity.this);
dialog.setTitle("Add Event");
dialog.setContentView(R.layout.add_even_on);
Button datePicker = (Button) dialog.findViewById(R.id.datePicker);
final DialogFragment dateFrag = new MyDatePicker();
datePicker.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dateFrag.show(getSupportFragmentManager(), "datePicker");
}
});
dialog.show();
Run Code Online (Sandbox Code Playgroud)
时说,选择菜单中的"添加事件"被点击时,会出现一个对话框,有一个按钮,显示DatePickerDialog和它旁边是一个TextView的,反映在选定的日期DatePickerDialog,这里是我的机器人会开发上了班如何使用DatePickerDialog.
class MyDatePicker extends DialogFragment implements DatePickerDialog.OnDateSetListener {
int pYear;
int pDay;
int pMonth;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR); …Run Code Online (Sandbox Code Playgroud) 我在Android中使用ccr4j API,所以当我运行我的项目时,它会抛出一个错误:
安装应用程序时出错(INSTALL_FAILED_DEXOPT)
我也从net和同一站点找到了,做了所有尝试,
1.从设备上卸载了相同的应用程序.
2.使用擦除用户数据运行仿真器.
但仍然会出现同样的错误.
所以任何人都知道为什么会抛出这种错误?
我想知道什么时候Context.bindService()回来false?
我已经尝试进行onBind()返回null,但是true在bindService调用时它仍然会返回并且onServiceConnected不会执行.我也在Google网上论坛上看到了此消息,但没有回复
https://groups.google.com/forum/#!topic/android-developers/ZLl56Mz1jYg
我也找不到bindService的实现,因为它在Context.java中是抽象的,并且搜索"public boolean bindService"也不会产生任何有用的结果(最接近的是ApplicationContext,它似乎不存在于当前的API级别中).
我有一个自定义DialogPreference子类,我希望有一个RadioGroup带有三个单选按钮.前两个是RadioButton带有标题的vanilla 组件,但是对于第三个我想EditText直接放在它的右侧,所以我可以在选择该按钮时输入自定义值.
我已经尝试将第三个按钮放入水平线LinearLayout,EditText然后第三个按钮不再参与父节点RadioGroup.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RadioGroup
android:id="@+id/lactate_radio"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/lactate_default_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/lactate_default_value"/>
<RadioButton
android:id="@+id/lactate_calibrated_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/lactate_calibrated_value" />
<LinearLayout android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/lactate_custom_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/lactate_custom_value"/>
<EditText
android:id="@+id/lactate_custom_value_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</RadioGroup>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

我也试过以LinearLayout编程方式添加它,但仍然有相同的行为.有没有办法做到这一点,也许是通过明确告诉父母RadioGroup关于第三个按钮或通过某种方式EditText适当地定位,而不使用水平LinearLayout?否则,我想我必须编写一个RadioButton应该是真正的派对的子类!
我知道不应该使用system.exit(0).我已经阅读了很多教程,并说明为什么不建议退出应用程序和finish()是一个更好的选择,但在非常罕见的情况下使用这个脏的解决方法比我的主要问题是 它会损害Android设备或任何方面设备如果使用?
我找不到很多FB + Android SDK的例子,样本不够简单(其中一些不推荐使用).我的简单目标是使用我的Android应用程序在FB上分享一些内容.当我开发iOS应用程序时,它很简单
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate facebookLogin];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"pikSpeak", @"name",
shareURL, @"link",
@"pikSpeak for iPhone !", @"caption",
@"Record audio at the moment of the image taken using pikSpeak and feel the moment come alive", @"description",
@"shared an audible pic using pikSpeak cam", @"message",
imageURL,@"picture",
nil];
[[appDelegate facebook] requestWithGraphPath:@"feed" andParams:params andHttpMethod:@"POST" andDelegate:self];
Run Code Online (Sandbox Code Playgroud)
此代码处理会话并在应用程序重新启动时保存会话详细信息.
1)如何在Android中简单地分享一些东西.
2)我看到Facebook(String app_id)已被弃用.如果是这样,那么它的替代品是什么?
PS:使用Facebook 3.0 SDK
android facebook facebook-wall facebook-graph-api facebook-android-sdk
我一直在努力学习文本测量和缩放画布.
当画布未缩放时,getTextBounds和measureText可以提供准确的结果.但是,当缩放画布时,两种方法都不会提供与打印文本的实际大小相匹配的结果.
为了测试,我使用以下onDraw方法创建了View的子类:
final float scaling = 0.51f;
final int fontSize = 50;
canvas.scale(scaling, scaling);
font = Typeface.create("Arial", Typeface.NORMAL);
Paint paint = new Paint();
paint.setColor(0xff4444ff);
paint.setTypeface(font);
paint.setTextSize(fontSize);
paint.setAntiAlias(true);
int x = 10;
int y = 100;
final String text = "Lorem ipsum dolor sit amet, consectetur adipisici elit...";
canvas.drawText(text, x, y, paint);
// draw border using getTextBounds
paint.setColor(0xffff0000);
paint.setStyle(Paint.Style.STROKE);
paint.setTypeface(font);
paint.setTextSize(fontSize);
Rect bounds = new Rect();
paint.getTextBounds(text, 0, text.length(), bounds);
bounds.offset(x, y);
paint.setColor(0x80ffff00);
canvas.drawRect(bounds, paint);
// draw border using measureText …Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中使用Facebook SDK 3.0 for Android在人们的墙上发布更新.在我的facebook的Insights区域,它表示我的API调用中约有25%导致API错误.根据"最常见的API错误",它说auth.extendSSOAccessToken.在"API错误细分"下,它表示没有API错误.
我auth.extendSSOAccessToken在Facebook开发者网站上看到引用的唯一一次是一个已修复的旧bug.我已经检查了令牌到期日期,并且它们将在2个月后设置为过期,因此生成的任何令牌都没有机会到期.
我假设某个会话正在请求扩展访问令牌上的单点登录,但我不知道为什么.我也不知道这个错误是否限制了人们登录.我无法在我自己的测试设备上复制此错误,因此我留下了Facebook洞察页面上提供的有限信息.
有谁熟悉这个错误并知道如何预防它?