Help with myListAdapter

8 replies [Last post]
shaka
User offline. Last seen 1 year 50 weeks ago. Offline
Joined: 02/14/2010

Hello,


I have a problem to list data from my query. 
screen appears in black. 





my query:


public static Cursor fetchProduct(String dRecogido) throws SQLException {

Cursor cursor =

mDb.query(DATABASE_TABLE, new String[] { KEY_ROWID, KEY_CODE,

KEY_NOME, KEY_PRICE }, KEY_NAME + "=" + "'"+ dRecogido +"'", null, null, null,

null, null);

if (cursor != null) {

cursor.moveToFirst();

}

return cursor;

}

and my SimpleCursorAdapter

private void showData() {

mCursor = ProductsDdAdapter.fetchProduct(dRecogido);

startManagingCursor(mCursor);

String[] from = new String[] { ProductsDdAdapter.KEY_CODE,

ProductsDdAdapter.KEY_NAME, ProductsDdAdapter.KEY_PRICE };

int[] to = new int[] { R.id.textCODIGO, R.id.textNOMBRE,

R.id.textPRECIO };

SimpleCursorAdapter la = new SimpleCursorAdapter(this, R.layout.listodatos, mCursor, from, to);

setListAdapter(la);

}

Did I do wrong? 
Or I needed to do?


thanks


best regards


1xuntong
User offline. Last seen 5 weeks 5 days ago. Offline
Joined: 12/25/2011
miu miu

Banyan/today a discount prada bags gold and silver silk tired

pandorauk
User offline. Last seen 1 year 8 weeks ago. Offline
Joined: 12/07/2010
Way back in Pandora I was

Way back in Pandora I was approached by Sid’s mother to do a book about Sid Vicious, obviously. With Pandora Bracelets crystal ball in one hand

mattbonner
User offline. Last seen 1 year 38 weeks ago. Offline
Joined: 05/12/2010
I don't see a black screen -

I don't see a black screen - just nothing happened?

Matthew Lawrence Bonner
Data Recovery Services

Tristan
User offline. Last seen 1 year 41 weeks ago. Offline
Joined: 04/15/2010
Similar Issue

Thank you for this code, I'd also need! I can now move forward!

Thank you,
New Moon

Domina
User offline. Last seen 1 year 32 weeks ago. Offline
Joined: 04/15/2010
I have not seen this query

I have not seen this query before, but I am new to the Droid as well. I am working on some applications for it, but I am still learning a lot also. I will look around for some more info for you to see what I can find. Multivariate Testing

gabor
User offline. Last seen 16 hours 10 min ago. Offline
Joined: 02/17/2010
Hi! I can not find specific

Hi!

I can not find specific errors in youor code, are you sure there is a (visible) ListView for the setListAdapter command, and there are records in the database?

shaka
User offline. Last seen 1 year 50 weeks ago. Offline
Joined: 02/14/2010
Thanks for your help


Hi,


Thanks for your help,


I want that when users type a title, displayed on screen titles that match.


Now I have another project following this tutorial, but now I have some problems when I change the ROWID for the variable that contains the text that the user types.


I put the code:


MainActivity.java






package com.miproyecto;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
    private View boton1;
private EditText caja1;
/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        boton1 = (Button)findViewById(R.id.Button01);
        caja1 = (EditText)findViewById(R.id.EditText01);
        
        boton1.setOnClickListener(BotonPulsado); 
    }
    
 private OnClickListener BotonPulsado = new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent();
intent.setClass(MainActivity.this, MuestraDatos.class);
intent.putExtra("Caja1", caja1.getText().toString());
startActivity(intent);
finish();
}
};
}

2 MuestraDatos.java


package com.miproyecto;
import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.Toast;
public class MuestraDatos extends Activity {
    
/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
     // Recoge el dato de MainActivity
Bundle bundle = getIntent().getExtras();
if(bundle!=null){
String textCaja1 = bundle.getString("Caja1");
        super.onCreate(savedInstanceState);
        
        
        DBAdapter db = new DBAdapter(this);
        
        // ---añadir 2 títulos---
        db.open();
        long id;
        id = db.insertTitle(
         "08745145", 
         "Programar en Android 2010", 
         "Anaya");
        id = db.insertTitle(
         "08745146", 
         "Programar en Java", 
         "McGraw Hill");
        db.close();  
        
        
        // ---mostrar todos los títulos---
        db.open();
        Cursor c = db.getNombre(textCaja1);
        if (c.moveToFirst())        
            DisplayTitle(c);
        else
            Toast.makeText(this, "Título no encontrado", 
             Toast.LENGTH_LONG).show();
        db.close();  
        }        
        
    }
    
private void DisplayTitle(Cursor c) {
Toast.makeText(this, 
"id: " + c.getString(0) + "\n" +
"ISBN: " + c.getString(1) + "\n" +
"TITULO: " + c.getString(2) + "\n" +
"EDITORIAL: " + c.getString(3),
Toast.LENGTH_LONG).show();
}
}
DBAdapter.java

package com.miproyecto;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class DBAdapter {
    public static final String KEY_ROWID = "_id";
    public static final String KEY_CODIGO = "codigo";
    public static final String KEY_NOMBRE = "nombre";
    public static final String KEY_EANS = "eans";    
    private static final String TAG = "DBAdapter";
    
    private static final String DATABASE_NAME = "pruebita";
    private static final String DATABASE_TABLE = "articulos";
    private static final int DATABASE_VERSION = 1;
    
    private static final String DATABASE_CREATE =
        "create table articulos (_id integer primary key autoincrement, "
        + "codigo integer not null, nombre text not null, " 
        + "eans integer not null);";
        
    private final Context context; 
    
    private DatabaseHelper DBHelper;
    private SQLiteDatabase db;
    public DBAdapter(Context ctx) 
    {
        this.context = ctx;
        DBHelper = new DatabaseHelper(context);
        ctx.deleteDatabase("pruebita");
    }
        
    private static class DatabaseHelper extends SQLiteOpenHelper 
    {
        DatabaseHelper(Context context) 
        {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }
        @Override
        public void onCreate(SQLiteDatabase db) 
        {
            db.execSQL(DATABASE_CREATE);
        }
        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, 
        int newVersion) 
        {
            Log.w(TAG, "Upgrading database from version " + oldVersion 
                    + " to "
                    + newVersion + ", which will destroy all old data");
            db.execSQL("DROP TABLE IF EXISTS titles");
            onCreate(db);
        }
    }    
    
    //---opens the database---
    public DBAdapter open() throws SQLException 
    {
        db = DBHelper.getWritableDatabase();
        return this;
    }
    //---closes the database---    
    public void close() 
    {
        DBHelper.close();
    }
    
    //---insert a title into the database---
    public long insertTitle(String codigo, String nombre, String eans) 
    {
        ContentValues initialValues = new ContentValues();
        initialValues.put(KEY_CODIGO, codigo);
        initialValues.put(KEY_NOMBRE, nombre);
        initialValues.put(KEY_EANS, eans);
        return db.insert(DATABASE_TABLE, null, initialValues);
    }
    //---deletes a particular title---
    public boolean deleteTitle(long rowId) 
    {
        return db.delete(DATABASE_TABLE, KEY_ROWID + 
         "=" + rowId, null) > 0;
    }
    //---retrieves all the titles---
    public Cursor getAllTitles() 
    {
        return db.query(DATABASE_TABLE, new String[] {
         KEY_ROWID, 
         KEY_CODIGO,
         KEY_NOMBRE,
                KEY_EANS}, 
                null, 
                null, 
                null, 
                null, 
                null);
    }
    //---retrieves a particular title---
    public Cursor getNombre(String textCaja1) throws SQLException 
    {
        Cursor mCursor =
                db.query(true, DATABASE_TABLE, new String[] {
                 KEY_ROWID,
                 KEY_CODIGO, 
                 KEY_NOMBRE,
                 KEY_EANS
                 }, 
                 KEY_NOMBRE + "=" + "'" + textCaja1 + "'" , 
                 null,
                 null, 
                 null, 
                 null, 
                 null);
        if (mCursor != null) {
            mCursor.moveToFirst();
        }
        return mCursor;
    }
    //---updates a title---
    public boolean updateTitle(long rowId, String codigo, 
    String nombre, String eans) 
    {
        ContentValues args = new ContentValues();
        args.put(KEY_CODIGO, codigo);
        args.put(KEY_NOMBRE, nombre);
        args.put(KEY_EANS, eans);
        return db.update(DATABASE_TABLE, args, 
                         KEY_ROWID + "=" + rowId, null) > 0;
    }
}
Thanks,
Best regards.
Javier




shaka
User offline. Last seen 1 year 50 weeks ago. Offline
Joined: 02/14/2010
yes, the data are records in

yes, the data are records in the database. I checked with the adb shell

thanks