从额外的价值传递给游标 [英] Passing value from extra to cursor

查看:195
本文介绍了从额外的价值传递给游标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图化解过去的一些错误在我的应用程序。随着我的当前设置我有用户通过一系列的ListView(分类 - >源 - >标题)。根据从列表视图的立场我通过所使用的我的光标来过滤结果,并给予属于previously点击项目项INT。通过不同的活动导航几次之后崩溃,因为应用程序失去说整型值(回去,并通过活动转发)。我试图安装一个getextra(),所以它不会失去这个值。我得到了它的设置将和得到这些整数,但有它们链接到我的光标,因为它要访问这些诠释了静态的方式,但我不会让他们在一个静态的方式麻烦。

I'm trying to iron out the last few bugs in my application. With my current setup I have the user go through a series of listview (Category -> source -> title). Based on the position from the listview I pass a int that is used by my cursor to filter the results and give the items that belong to the previously clicked item. After navigating a few times through the different activities it crashes since the application loses the value of said int (going back and forward through the activities). I'm trying to setup a getextra() so it will not lose this value. I've got it setup to put and get these ints but having trouble linking them to my cursor since it wants to access these int in a static way but I'm not getting them in a static way.

public class title extends ListActivity {

    Bundle extras = getIntent().getExtras();
    int categoryClick = extras.getInt("cateClick");
    int sourceClick = extras.getInt("sourceclick");

...

@Override
protected void onListItemClick(ListView list, View v, int position, long id)
{
    super.onListItemClick(list, v, position, id);
    titleClick = position;
    final Intent intent = new Intent(this, inputpage.class);
    intent.putExtra("cateclick", categoryClick);
    intent.putExtra("sourceclick", sourceClick);
    intent.putExtra("titleclick", titleClick);  
    startActivity(intent);
    }

我的光标从我使用的是什么看起来像这样不变

My cursor unchanged from what I was using looks like this

// retrieves all the descriptions for the edittext fields
      public  Cursor getUserWord() 
        {
            return myDataBase.query(USER_WORD_TABLE, new String[] {
                    KEY_ID, 
                    KEY_CATEGORY,
                    KEY_SOURCE, KEY_TITLE, KEY_USERWORD, KEY_QUICK 
                    }, 
                    KEY_CATEGORY+ "=" + categories.categoryClick + " AND " + KEY_SOURCE+ "=" 
                    +source.sourceClick + " AND " + KEY_TITLE+ "=" + title.titleClick, 
                    null, null, null, KEY_ID);

        }

我的数据库有多个表,一个是上面的光标下面的图片。

My database has multiple tables, the one for the above cursor is the image below.

这设置可能不会得到我想要的结果,但作为新到Android的最好的方法,SQLite和Java的是什么,我能得到我需要的东西的工作。

This setup may not be the best method of getting the result I want but being new to android, sqlite and java it was what I was able to get to work for what I needed.

尝试切换到getextra之前,我得到的错误是

The error I was getting before trying to switch to getextra was

03-10 16:06:14.653: E/AndroidRuntime(939): Uncaught handler: thread main exiting due to uncaught exception
03-10 16:06:14.683: E/AndroidRuntime(939): java.lang.NullPointerException
03-10 16:06:14.683: E/AndroidRuntime(939):  at wanted.pro.madlibs.source.onListItemClick(source.java:55)
03-10 16:06:14.683: E/AndroidRuntime(939):  at android.app.ListActivity$2.onItemClick(ListActivity.java:312)
03-10 16:06:14.683: E/AndroidRuntime(939):  at android.widget.AdapterView.performItemClick(AdapterView.java:284)
03-10 16:06:14.683: E/AndroidRuntime(939):  at android.widget.ListView.performItemClick(ListView.java:3285)
03-10 16:06:14.683: E/AndroidRuntime(939):  at android.widget.AbsListView$PerformClick.run(AbsListView.java:1640)
03-10 16:06:14.683: E/AndroidRuntime(939):  at android.os.Handler.handleCallback(Handler.java:587)
03-10 16:06:14.683: E/AndroidRuntime(939):  at android.os.Handler.dispatchMessage(Handler.java:92)
03-10 16:06:14.683: E/AndroidRuntime(939):  at android.os.Looper.loop(Looper.java:123)
03-10 16:06:14.683: E/AndroidRuntime(939):  at android.app.ActivityThread.main(ActivityThread.java:4363)
03-10 16:06:14.683: E/AndroidRuntime(939):  at java.lang.reflect.Method.invokeNative(Native Method)
03-10 16:06:14.683: E/AndroidRuntime(939):  at java.lang.reflect.Method.invoke(Method.java:521)
03-10 16:06:14.683: E/AndroidRuntime(939):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
03-10 16:06:14.683: E/AndroidRuntime(939):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
03-10 16:06:14.683: E/AndroidRuntime(939):  at dalvik.system.NativeStart.main(Native Method)

下面是一个屏幕截图休息这是怎么回事下来。

改变INT静态后

改变额外的静态后

Here is a screen shot break down of what's going on. After changing int to static after changing extra to static

推荐答案

根据截图,你不应该做静态引用到你的包。让他们的实例变量,每一个你的onCreate或onResume方法被调用的时间进行设置。

Based on the screenshots, you shouldn't be making static references to your Bundles. Make them instance variables, and set them every time your onCreate or onResume method gets called.

这篇关于从额外的价值传递给游标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆