gpt4 book ai didi

android - 如何根据位置查询以根据位置显示编辑 View

转载 作者:行者123 更新时间:2023-11-29 22:55:06 25 4
gpt4 key购买 nike

我正在尝试构建一个具有基本 CRUD 操作的应用程序。我能够显示从 ListView 中选择的项目位置的详细信息 View 。但是,当我尝试从详细 View 显示编辑 View 时,用于显示详细 View 的相同查询会产生异常。因此,我尝试读取所有列并根据位置显示它们。

我正在使用下面所示的查询来显示编辑 View 。但应用程序仅显示表格第一行的内容,无论单击的位置如何:

我的查询是:

db = helper.getReadableDatabase();

String[] columns = { SQLiteHelper.UID,
SQLiteHelper.TASK_NAME, SQLiteHelper.CONTACTS, SQLiteHelper.DESCRIPTION, SQLiteHelper.REMARKS, SQLiteHelper.DATETIME, SQLiteHelper.ESTIMATED_COMPLETION_TIME,
SQLiteHelper.ACTUAL_COMPLETION_TIME, SQLiteHelper.NOTIFY_TIME};
Cursor cursor = db.query(SQLiteHelper.TABLE_NAME,columns , null ,
null, null, null, null, null);

if (cursor != null) {

cursor.moveToFirst();


task = new Task(cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4), cursor.getString(5),
cursor.getString(6), cursor.getString(7), cursor.getString(8));



}


return task;

请帮助我并就如何更新查询以实现我的目标提供建议。

当我单击 ListView 上的任务 5 时,它会显示任务 5 的详细信息,但是当我选择“编辑”按钮时,我将看到第一行任务 1 的“编辑” View 。请帮我。我是安卓新手。请教我。

我的 ADB 日志中提到的错误:

02-26 18:59:51.985    1504-1504/com.ms.t.tms D/AndroidRuntime﹕ Shutting down VM
02-26 18:59:52.000 1504-1504/com.ms.t.tms E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.ms.t.tms, PID: 1504
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ms.t.tms/com.ms.t.tms.EditScreen}: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
at android.database.AbstractCursor.checkPosition(AbstractCursor.java:426)
at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50)
at com.ms.t.tms.SQLiteDataBaseAdapter.getTask1(SQLiteDataBaseAdapter.java:146)
at com.ms.t.tms.EditScreen.onCreate(EditScreen.java:70)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

我的表结构:

public static final String TABLE_NAME = "DataTable";
public static final String UID = "_id";
public static final String TASK_NAME = "Task_name";
public static final String CONTACTS = "Contacts";
public static final String DESCRIPTION = "Description";
public static final String REMARKS = "Remarks";
public static final String DATETIME = "Date";
public static final String ESTIMATED_COMPLETION_TIME = "EstCompTime";
public static final String ACTUAL_COMPLETION_TIME = "ActCompTime";
public static final String NOTIFY_TIME = "NotifyTime";
public static final int DATABASE_VERSION = 2;
public static final String CREATE_TABLE = " CREATE TABLE " + TABLE_NAME +
"(" + UID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + TASK_NAME + " VARCHAR(250)," + CONTACTS + " VARCHAR(250)," + DESCRIPTION + " VARCHAR(250), " + REMARKS + " VARCHAR(250),"
+ DATETIME + " VARCHAR(250)," + ESTIMATED_COMPLETION_TIME + " VARCHAR(250), "
+ ACTUAL_COMPLETION_TIME + " VARCHAR(250), " + NOTIFY_TIME + " VARCHAR(250));";

最佳答案

您可以使用原始查询!Cursor c =db.rawQuery("SELECT * FROM SOMETHING WHERE name = ?", args);

阅读更多内容 http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html

关于android - 如何根据位置查询以根据位置显示编辑 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28743396/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com