我的Activity中有一个ListView,它在onCreateby中设置
MyCursorAdapter adapter = new TaskConditsCursorAdapter(this, conditsCursor, taskID, isNewTask);
setListAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)
然后我做了一些工作MyCursorAdapter.除此之外,我有一个行特定的AlertDialog:
...
builder.setPositiveButton("OK"), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
changeTaskConditBoolValue(taskId, conditId, chosenBoolValue2);
// refresh?
}
});
Run Code Online (Sandbox Code Playgroud)
之后changeTaskConditBoolValue我想重新加载我的List,因为这个方法在数据库中改变了一些东西,但List没有更新.requery()结果列表为空.我怎样才能"再高一级" adapter再次与我合作,那么我该怎么做呢?
非常感谢!
我一直试图通过MediaStore内容提供商查询SD卡上的所有图像,并在GridView上显示它们的缩略图.
但是,如果我在主线程上加载图像缩略图,滚动速度会非常慢......
所以我试图通过asynctasks加载位图:滚动性能变得更好,但现在网格项不断重新加载缩略图,直到它获得正确的位图...
这是我的asynctask,它加载位图:
package x.y;
import java.lang.ref.WeakReference;
import android.content.ContentResolver;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory.Options;
import android.os.AsyncTask;
import android.provider.MediaStore;
import android.widget.ImageView;
public class ImageThumbnailLoader extends AsyncTask<Long, Void, Bitmap> {
private final Options mOptions;
private WeakReference<ImageView> mImageViewWeakReference;
private ContentResolver mContentResolver;
public ImageThumbnailLoader(ImageView imageView,
ContentResolver cr) {
mContentResolver = cr;
mImageViewWeakReference = new WeakReference<ImageView>(imageView);
mOptions = new Options();
mOptions.inSampleSize = 4;
}
@Override
protected Bitmap doInBackground(Long... params) {
Bitmap result;
result = MediaStore.Images.Thumbnails.getThumbnail(
mContentResolver, params[0],
MediaStore.Images.Thumbnails.MINI_KIND, mOptions);
return result;
}
@Override
protected void …Run Code Online (Sandbox Code Playgroud) android bitmap mediastore android-asynctask android-cursoradapter
目前我正在使用getContentResolver().query()/ managedQuery()来获取光标以从图库应用程序中检索图像.因为我正在使用的API部分弃用,所以我想将CursorLoader与LoaderManager一起使用.
/**
* Creates a cursor to access the content defined by the image uri for API
* version 11 and newer.
*
* @return The created cursor.
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private Cursor createCursorHoneycomb() {
String[] projection = {
MediaStore.Images.Media.DATA
};
Cursor cursor = getContentResolver().query(imageUri, projection, null, null, null);
return cursor;
}
/**
* Creates a cursor to access the content defined by the image uri from API
* version 8 to 10.
*
* @return The created cursor.
*/ …Run Code Online (Sandbox Code Playgroud) android android-cursor android-loadermanager android-cursorloader android-cursoradapter
我有一个ListView,其中包含由以下内容组成的项目RelativeLayout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.app.FragmentList">
<ListView
android:id="@+id/ListView01"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_alignParentLeft="false"
android:layout_alignParentTop="true"
android:fastScrollEnabled="true"
android:fastScrollAlwaysVisible="true"
android:smoothScrollbar="false"
android:scrollingCache="true" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
这几项:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="8dp"
android:paddingBottom="8dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Erika Mustermann"
android:id="@+id/textViewName"
android:layout_marginLeft="8dp"
android:layout_marginBottom="-3dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Company Inc."
android:id="@+id/textViewCompany"
android:layout_marginLeft="24dp"
android:textColor="#6b6b6b"
android:textSize="13dp"
android:visibility="gone" />
<RelativeLayout android:id="@+id/RelativeLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:id="@+id/linearLayout_one"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="24dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Work: "
android:id="@+id/NumLabel0"
android:textColor="#6b6b6b" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="+49-1234-1234567" …Run Code Online (Sandbox Code Playgroud) android listview android-layout android-listview android-cursoradapter
我想从手机查询通话记录详细信息,我的查询如下
Cursor groupCur = mcontext.getContentResolver().query(Calls.CONTENT_URI,
CallLogAdapter.PROJECTION, Calls.NUMBER + " = " + number, null,Calls.DEFAULT_SORT_ORDER);
Run Code Online (Sandbox Code Playgroud)
CallLogAdapter.PROJECTION包含调用日志的一些字段(列).
它工作正常,但在下面的条件下它会给力关闭.
条件: - 如果拨号号码以*或#开头(例如:*1234567或#123457),号码以*结尾(例如:1234567*)
**ERROR LOG:**
Run Code Online (Sandbox Code Playgroud)
10-14 14:54:50.425:INFO/Database(26307):sqlite返回:错误代码= 1,msg =接近语法错误10-14 14:54:50.429:ERROR/DatabaseUtils(26307):向包裹10写入异常-14 14:54:50.429:ERROR/DatabaseUtils(26307):android.database.sqlite.SQLiteException:near"*":语法错误:,同时编译:SELECT _id,number,name,date,duration,new,type FROM调用WHERE(number =*674088888)ORDER BY date DESC 10-14 14:54:50.429:ERROR/DatabaseUtils(26307):at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)10-14 14:54:50.429 :ERROR/DatabaseUtils(26307):在android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92)10-14 14:54:50.429:ERROR/DatabaseUtils(26307):在android.database.sqlite.SQLiteCompiledSql. (SQLiteCompiledSql.java:65)10-14 14:54:50.429:ERROR/DatabaseUtils(26307):在android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:83)10-14 14:54:50.429:ERROR/DatabaseUtils(26307):在android.database.sqlite.SQLiteQuery.(SQLiteQuer y.java:49)10-14 14:54:50.429:ERROR/DatabaseUtils(26307):在android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)10-14 14:54:50.429:ERROR/DatabaseUtils(26307):在android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1356)10-14 14:54:50.429:ERROR/DatabaseUtils(26307):at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder) .java:330)10-14 14:54:50.429:ERROR/DatabaseUtils(26307):at com.android.providers.contacts.CallLogProvider.query(CallLogProvider.java:129)10-14 14:54:50.429:ERROR/DatabaseUtils(26307):在android.content.ContentProvider $ Transport.bulkQuery(ContentProvider.java:174)10-14 14:54:50.429:ERROR/DatabaseUtils(26307):在android.content.ContentProviderNative.onTransact(ContentProviderNative. java:111)10-14 14:54:50.429:ERROR/DatabaseUtils(26307):在android.os.Binder.execTransact(Binder.java:320)10-14 14:54:50.429:ERROR/DatabaseUtils(26307) :at dalvik.system.NativeStart.run(Native Method )10-14 14:54:50.429:DEBUG/AndroidRuntime(27470):关闭VM 10-14 14:54:50.429:WARN/dalvikvm(27470):threadid = 1:线程退出未捕获异常(组= 0x40015560) 10-14 14:54:50.433:ERROR/AndroidRuntime(27470):致命异常:主10-14 14:54:50.433:ERROR/AndroidRuntime(27470):android.database.sqlite.SQLiteException:near"*":syntax错误:,同时编译:SELECT _id,number,name,date,duration,new,type FROM calls WHERE(number =*674088888)ORDER BY date DESC …
这是我的数据库帮助程序类的代码,任何人都可以告诉我,我在做什么错误,表中没有添加电子邮件列,每次我收到错误,表没有cloumn名称person_email
package com.example.and;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class AndroidOpenDbHelper {
private static final String TAG = AndroidOpenDbHelper.class.getSimpleName();
// database configuration
// if you want the onUpgrade to run then change the database_version
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "mydatabase.db";
// table configuration
private static final String TABLE_NAME = "person_table"; // Table name
private static final String PERSON_TABLE_COLUMN_ID = "_id"; // a column named "_id" …Run Code Online (Sandbox Code Playgroud) 背景:我正在尝试在我的应用程序中实现一个消息系统,我正在编写一个自定义CursorAdapter来ListView在聊天窗口中显示消息.我想为传入和传出消息使用不同的行布局(保存在游标的SQLite行中的信息).每行中具有相同ID的相同元素,但它们的排列方式不同.
问题:目前,我已经覆盖newView()并且bindView().在当ListView第一填充时,它会创建所有的View小号完美,检查每一行,看它是否是传入或传出,并膨胀正确的XML文件.但是,当我滚动或向窗口添加新消息时,适配器会回收View错误的行.我会覆盖getView(),但它不Cursor作为参数传递,所以我无法知道该行是传入还是传出.
我不是在寻找代码,而是寻找优雅实现的一些建议.提前致谢!
我ListView有SimpleCursorAdapter
我得到的错误: -
java.lang.IllegalStateException:适配器的内容已更改,但ListView未收到通知.确保不从后台线程修改适配器的内容,而只是从UI线程修改.[在ListView(2131361944,类android.widget.ListView)中使用Adapter(类com.pocketpharmacist.adapter.DrugClassesListAdapter)]
什么时候:-
在我的Fragment我已启用过滤器与适配器,并过滤列表我有一个EditText.
现在,1)当我开始输入过滤器的文本时,虚拟键盘变为活动状态,并开始使用列表进行过滤
2)但是,当我隐藏Keybord时,真正的过滤活跃起来.如果我点击listItem与keybord alive它会给我上面的错误,这是显而易见的,因为数据没有反映到UI
深入了解之后,我知道例如我想在列表中搜索ABCDE我已经在Edittext中输入ABC了,当我添加D时它向我显示ABC的过滤器,现在再次如果我添加E它会向我显示过滤器对于ABCD,Buuut Data最初是在后台更改的.这是错误的原因.
但我无法弄清楚如何解决这个问题
notifyDataSetChanged没有效果,请帮助我,任何提示或想法都可以工作
听到我的代码
方法来自 TextWatcher
public void afterTextChanged(Editable s) {
searchAdapter.getFilter().filter(s.toString());
searchAdapter.notifyDataSetChanged();
drugListView.requestLayout();
}
Run Code Online (Sandbox Code Playgroud)
Logcat如下
06-30 18:14:54.299: E/AndroidRuntime(6922): FATAL EXCEPTION: main
06-30 18:14:54.299: E/AndroidRuntime(6922): java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the …Run Code Online (Sandbox Code Playgroud) 我有listview,每行有2个文本框和1个复选框.我想在用户选中复选框时,然后将预定义的drawable设置为该行的背景.
我试图在我的cusotm游标适配器里面的getView方法上的Lisnner上做,但没有成功,请帮助!!!
要点:自定义适配器通过数据库中的文件路径间接获取文件资源.低效/记忆问题.您的意见要求.
对所有搜索,相关链接和有用主题的引用都在后面.
以下代码有效,但有几个因素值得关注.需要一些更有经验的眼睛,请建议改善或潜在的错误,以避免.应用不需要是内容提供商(仅限应用于本地的数据).有问题的ListView将非常轻量级,只有大约5到10个条目.(我遗漏了数据库的东西,因为它有效.)
概述:
文件不在数据库中使得它与普通的SimpleCursorAdapter不同 - 必须拉动图像文件.添加了在填充listview之前将其制作成缩略图的开销.
如上所述,它很轻,但即使只有一两个条目,虚拟机也会出现问题.我怀疑这是与Bitmaps相关的所有内存抖动:
08-27 19:53:14.273: I/dalvikvm-heap(11900): Grow heap (frag case) to 4.075MB for 1228816-byte allocation
08-27 19:53:14.393: D/dalvikvm(11900): GC_CONCURRENT freed <1K, 5% free 4032K/4244K, paused 13ms+3ms, total 116ms
Run Code Online (Sandbox Code Playgroud)
/* myTextAndImageCursorAdapter.java */
import android.widget.SimpleCursorAdapter;
//import android.support.v4.widget.SimpleCursorAdapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.database.Cursor;
import java.io.File;
import android.widget.ImageView;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import static android.media.ThumbnailUtils.extractThumbnail;
public class TextAndImageCursorAdapter extends SimpleCursorAdapter {
private Context context;
private int layout;
public TextAndImageCursorAdapter …Run Code Online (Sandbox Code Playgroud) android ×10
listview ×3
bitmap ×1
contacts ×1
data-binding ×1
image ×1
mediastore ×1
sqlite ×1