3 Replies - 22718 Views - Last Post: 09 April 2011 - 05:49 AM

#1 jess2705  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 20-November 10

How to retrieve data from database to listview

Posted 09 April 2011 - 03:08 AM

i am trying to add the data from the database to listview but the error is dispaly.
My code at a database site is
Cursor getAllLoginInfo()
		 {
			 SQLiteDatabase db=this.getReadableDatabase();
			 Cursor cur=db.rawQuery("SELECT * from Login",new String [] {});		 
			 return cur;
		 }


and the code for adding data in the listview:-
package com.database.login;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

public class temp extends Activity{
	
	public ListView lv1=(ListView)findViewById(R.id.List_data);
	@Override
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.temp_logininfo);
        
        DatabaseHelper dbHelper = null;        
        ArrayList<String> results = new ArrayList<String>();
        
     
        
        Cursor cs=dbHelper.getAllLoginInfo();
        
        if(cs.moveToFirst()){
            
        	SimpleCursorAdapter cs1=new SimpleCursorAdapter(this,R.layout.subjectspinnerrow, cs, new String [] {DatabaseHelper.rBranchId,"_id"}, new int []{R.id.txtDeptName});		
        	lv1.setAdapter(cs1);
            cs.moveToNext();
            //cursor.moveToPosition(1);
        }   

     
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
	    MenuInflater inflater = getMenuInflater();
	    inflater.inflate(R.menu.loginmenu, menu);
	    return true;
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
	    // Handle item selection
	    switch (item.getItemId()) {
	    case R.id.item01:
	        newuser();
	        return true;
	    
	    default:
	        return super.onOptionsItemSelected(item);
	    }
	}
	
	void newuser()
	{
		
		try
		{
			startActivity(new Intent("com.database.login.dbLogin"));
			//startActivity(new Intent("com.database.login.scrolling"));
		}
		catch(Exception ex)
		{
			Log.e("Error",null);
		}
	}
}




Is This A Good Question/Topic? 0
  • +

Replies To: How to retrieve data from database to listview

#2 mi14chal  Icon User is offline

  • D.I.C Head

Reputation: 81
  • View blog
  • Posts: 202
  • Joined: 11-December 10

Re: How to retrieve data from database to listview

Posted 09 April 2011 - 04:25 AM

What errors are you getting?
Was This Post Helpful? 0
  • +
  • -

#3 jess2705  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 20-November 10

Re: How to retrieve data from database to listview

Posted 09 April 2011 - 04:59 AM

View Postmi14chal, on 09 April 2011 - 04:55 PM, said:

What errors are you getting?

Actually no particular error is there, as it starts terminate automatically.
And, the data should be fetched from database but didn't workout. I tried so many things like ArrayList, ListView, TextView to fetch the data but no output. :(
Was This Post Helpful? 0
  • +
  • -

#4 mi14chal  Icon User is offline

  • D.I.C Head

Reputation: 81
  • View blog
  • Posts: 202
  • Joined: 11-December 10

Re: How to retrieve data from database to listview

Posted 09 April 2011 - 05:49 AM

Well, you will have to debug your application.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1