繁体   English   中英

如何使用另一列仅获取数据

[英]How to data fetch only one column using the other column

逻辑上错误..我在Android java数据库上是新的..没有错误,但我想你们明白我的意思。

getSearch = searchbar.getText() .toString();
searchquery = "SELECT * FROM words WHERE tagalog LIKE '%"+ getSearch +"%';";
sqLiteDatabase.rawQuery(searchquery,null);
Cursor c = wordsDBHelper.getdata(sqLiteDatabase);
searchRes.setText( c.getString(2).toString());

任何建议都被接受。 按下此代码所在的按钮之后,Button会直接指向mainActivity。

heres the logcat
    01-26 13:28:49.285 32177-32177/? D/dalvikvm: Late-enabling CheckJNI
01-26 13:28:49.305 32177-32177/com.example.leoandroid.translate W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
01-26 13:28:49.305 32177-32177/com.example.leoandroid.translate I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.view.WindowCallbackWrapper.onSearchRequested
01-26 13:28:49.305 32177-32177/com.example.leoandroid.translate W/dalvikvm: VFY: unable to resolve interface method 17980: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
01-26 13:28:49.305 32177-32177/com.example.leoandroid.translate D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
01-26 13:28:49.305 32177-32177/com.example.leoandroid.translate I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode
01-26 13:28:49.305 32177-32177/com.example.leoandroid.translate W/dalvikvm: VFY: unable to resolve interface method 17984: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
01-26 13:28:49.305 32177-32177/com.example.leoandroid.translate D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
01-26 13:28:49.315 32177-32177/com.example.leoandroid.translate D/dalvikvm: GC_FOR_ALLOC freed 125K, 27% free 2723K/3728K, paused 10ms, total 10ms
01-26 13:28:49.315 32177-32177/com.example.leoandroid.translate I/dalvikvm-heap: Grow heap (frag case) to 7.125MB for 4651212-byte allocation
01-26 13:28:49.325 32177-32183/com.example.leoandroid.translate D/dalvikvm: GC_FOR_ALLOC freed <1K, 13% free 7265K/8272K, paused 10ms, total 10ms
01-26 13:28:49.355 32177-32177/com.example.leoandroid.translate I/dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.widget.TintTypedArray.getChangingConfigurations
01-26 13:28:49.355 32177-32177/com.example.leoandroid.translate W/dalvikvm: VFY: unable to resolve virtual method 433: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
01-26 13:28:49.355 32177-32177/com.example.leoandroid.translate D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
01-26 13:28:49.355 32177-32177/com.example.leoandroid.translate I/dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.widget.TintTypedArray.getType
01-26 13:28:49.355 32177-32177/com.example.leoandroid.translate W/dalvikvm: VFY: unable to resolve virtual method 455: Landroid/content/res/TypedArray;.getType (I)I
01-26 13:28:49.355 32177-32177/com.example.leoandroid.translate D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
01-26 13:28:49.435 32177-32177/com.example.leoandroid.translate I/PGA: Attempting to create new SOCKET connectionn pid = 32177, tid = 32177
01-26 13:28:49.445 32177-32177/com.example.leoandroid.translate I/PGA: New SOCKET connection: com.example.leoandroid.translate (pid 32177, tid 32177)

请帮助。 我尝试对其进行分析,并分析了尝试创建新的套接字连接...从而将其重定向到Mainactivity? 我糊涂了。

更好地使用功能。 在DbHelper类中创建函数,例如

     public DataProvider getInformations()
         { 
                  SQLiteDatabase db = this.getReadableDatabase();
                  Cursor res =  db.rawQuery( "select "+your column+" from "+TABLE_NAME, null );
                    res.moveToFirst();
                    DataProvider dataProvider = new DataProvider();
                    while(res.isAfterLast() == false)
                    {
                        dataProvider.setText(res.getString(res.getColumnIndex(Columnname)));
                        res.moveToNext();
                    }
                db.close();
                return dataProvider;
         }

然后你的主要活动

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity);

    userDbHelper =new UserDbHelper(this);
    DataProvider dataProvider=userDbHelper.getInformations();
    text = dataProvider.getText();

    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM