我试图使我的应用程序旋转友好,但我在保存光标时遇到一些问题.
光标在a中显示大约13k +行的数据ListView,因此如果每次配置更改时我都会进行重新查询,则需要很长时间.在我onRetainNonConfigurationInstance(),我正在返回我的光标,然后检索它getLastNonConfigurationInstance().
但是,我检索到的光标似乎已经关闭,因此我的适配器无法再渲染列表.根据我的理解,光标已关闭,因为onDestroy()自动关闭所有光标.
我像这样保存Cursor:
@Override
public Object onRetainNonConfigurationInstance() {
return myCursor;
}
Run Code Online (Sandbox Code Playgroud)
并检索它像这样:
myCursor = (Cursor)getLastNonConfigurationInstance();
if (myCursor == null) {
// Do some stuff here (access DB, etc)
} else { // we are returning from configuration change
// Feed the cursor to the adapter
}
Run Code Online (Sandbox Code Playgroud)
如果有人想看它,我会粘贴堆栈跟踪:
01-25 16:57:45.637: ERROR/AndroidRuntime(12976): android.database.StaleDataException: Access closed cursor
01-25 16:57:45.637: ERROR/AndroidRuntime(12976): at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:217)
01-25 16:57:45.637: ERROR/AndroidRuntime(12976): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:41)
01-25 16:57:45.637: ERROR/AndroidRuntime(12976): at com.test.sample.helper.DictionaryAdapter.bindView(DictionaryAdapter.java:35)
[........More …Run Code Online (Sandbox Code Playgroud) 我知道StackOverflow已经多次询问过这个问题,但我还没有找到解决方案.我的应用会发送一封电子邮件,其中包含一个链接,点击后应启动该应用.
根据@hackbod的说法,最好的方法是使用Intent URI(参见本节).这是我设置意图的代码并将其放入电子邮件正文中:
Intent customIntent = new Intent(CUSTOM_ACTION);
customIntent.setPackage(MY_PACKAGE);
customIntent.addCategory(MY_CAT_BROWSABLE);
customIntent.addCategory(MY_CAT_DEFAULT);
String customUri = customIntent.toUri(Intent.URI_INTENT_SCHEME);
String emailBody = getString(R.string.intent_link, customUri);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/html");
intent.putExtra(Intent.EXTRA_SUBJECT, "Recommending vid");
intent.putExtra(Intent.EXTRA_TEXT , Html.fromHtml(emailBody));
try {
startActivity(Intent.createChooser(intent, "Choose email client:"));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
Run Code Online (Sandbox Code Playgroud)
这是我从LogCat得到的:
08-25 17:01:23.333: VERBOSE/Test URI(16987): intent:#Intent;action=com.test.project.action.VIEW_VID_FROM_LINK;category=android.intent.category.DEFAULT;category=android.intent.category.BROWSABLE;package=com.test.project;end
08-25 17:01:23.338: VERBOSE/Test email text(16987): Hi,<br><br>Testing intents from an email.<br><br> A standard website: <a href=http://www.google.com>Go to Google</a>.<br><br> This link should …Run Code Online (Sandbox Code Playgroud) 我试图在a中显示语音符号WebView,但到目前为止我只是得到了正方形.
例如,对于单词"撇号",应显示:
əpåstrəfi
但我在显示屏上看到的是:
□□påstr□网络
如果它会有帮助,我从SQLite数据库中获取字符串.我检索的字符串中有一些HTML标记,所以我用它:
webView.loadDataWithBaseURL("file:///android_asset/",
article, "text/html", Encoding.UTF_8.toString(), null);
Run Code Online (Sandbox Code Playgroud)
在哪里我有我的CSS文件/assets.并且article变量包含HTML标记中包含的一些文本.
我正在尝试创建一个ListView,它将填充数组中的条目.
所以这是我的项目布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="60dip" >
<ImageView android:id="@+id/list_item_image"
android:layout_height="wrap_content"
android:padding="2dip"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_width="50dip"/>
<TextView android:id="@+id/list_item"
android:layout_height="fill_parent"
android:textSize="25sp"
android:layout_width="fill_parent"
android:ellipsize="marquee"
android:gravity="center_vertical"
android:padding="5dip" >
</TextView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我试图改变layout_height的LinearLayout,但我遇到了一些问题.如果我保持高度wrap_content,我的列表将显示正确的条目 - 项目1,项目2,项目3,依此类推,直到项目12.但是如果我将高度更改为60dip,则条目在第六个条目后重复(I得到第1项,第2项,第3项,第4项,第5项,第6项,第1项,第2项,第3项......).如果我继续增大,则条目会更频繁地重复.
这是ListAdapter我设置列表条目的片段:
public View getView(int position, View convertView, ViewGroup parent) {
LinearLayout layout;
if (convertView == null){
layout = (LinearLayout) LayoutInflater.from(mContext).inflate(R.layout.items_list_item, parent, false);
TextView title = (TextView) layout.findViewById(R.id.list_item);
title.setText(menuItems[position]);
ImageView icon = (ImageView) layout.findViewById(R.id.list_item_image);
int logo = getResources().getIdentifier(menuIcons[position], "drawable", getPackageName());
icon.setImageResource(logo); …Run Code Online (Sandbox Code Playgroud)