Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6896261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:00:49+00:00 2026-05-27T07:00:49+00:00

i m trying to get data from my database and present them to a

  • 0

i m trying to get data from my database and present them to a listView.i m using two classes for my database:
1st class is the DBAdapter and the method i use to get data is:

   public String[] getData()
{
//  String[] columns =new String[]{DBHelper.ROWID, DBHelper.TITLE ,  DBHelper.AUTHOR, DBHelper.ISBN };

    String[] columns =new String[]{DBHelper.TITLE ,  DBHelper.AUTHOR, DBHelper.ISBN };
    Cursor c=ourDatabase.query(DBHelper.DATABASE_TABLE, columns, null, null, null, null, null);
    String result="";
    String sa = null;
    String sb = null;
    String sc = null;


    //int iRow=c.getColumnIndex(DBHelper.ROWID);
    int is1=c.getColumnIndex(DBHelper.TITLE);
        int is2=c.getColumnIndex(DBHelper.AUTHOR);
            int is3=c.getColumnIndex(DBHelper.ISBN);

            for (c.moveToFirst();!c.isAfterLast();c.moveToNext()){
                //result=result+c.getString(is1)+" "+c.getString(is2)+" "+c.getString(is3)+"\n";
                 sa=c.getString(is1);
                 sb=c.getString(is2);
                 sc=c.getString(is3);
            }
              //Toast.makeText(HotOrNot.this, sa, Toast.LENGTH_SHORT).show();

return new String[] {sa,sb,sc};
}

2.The secind class in SQLView and thats the way i m trying to create my list

public class SQLView extends Activity {
    /** Called when the activity is first created. */    

   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.list_layout); 

       HotOrNot entry2=new HotOrNot(this);
       entry2.open();  
          String[] data2=entry2.getData();
          entry2.close();
          Toast.makeText(SQLView.this, data2[1].toString(), Toast.LENGTH_SHORT).show();


       ListView list = (ListView) findViewById(R.id.list);


       ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();


       HashMap<String, String> map = new HashMap<String, String>();

       map = new HashMap<String, String>();
       map.put("name",data2[0].toString());
       map.put("address", data2[1].toString());
       map.put("address2", data2[2].toString());

       mylist.add(map);






       // ...
       ListAdapter mSchedule = new SimpleAdapter(this, mylist, R.layout.row,
                   data2, new int[] {R.id.rtextView1,R.id.rtextView2,R.id.rtextView3});
       list.setAdapter(mSchedule);

What i have to do in order to work?This is my first try to use database in android!

Now i just get an empty background…

EDIT:
With my toast i m getting the last item in position 1 that i added to db

Could anybody help me with the return statement in my DBHelper please?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:00:50+00:00Added an answer on May 27, 2026 at 7:00 am

    Below is the fixed code. Try this out.

    ListAdapter mSchedule = new SimpleAdapter(this, mylist, R.layout.row,
       new String[] { "name", "address", "address2"},
       new int[] {R.id.rtextView1,R.id.rtextView2,R.id.rtextView3});
    list.setAdapter(mSchedule);
    

    Basically you have to specify the columns/key of the map that you added. So it will map key from map to the corresponding view.

    For looping issue, this will do the job:

    for(int i=0; i<data2.length; i+=3) {
       HashMap<String, String> map;
    
       map = new HashMap<String, String>();
       map.put("name",data2[i].toString());
       map.put("address", data2[i+1].toString());
       map.put("address2", data2[i+2].toString());
    
       mylist.add(map);
    }
    

    The getData fix:

    ArrayList<String> arrForData = new ArrayList<String>();
    //int iRow=c.getColumnIndex(DBHelper.ROWID);
    int is1=c.getColumnIndex(DBHelper.TITLE);
        int is2=c.getColumnIndex(DBHelper.AUTHOR);
            int is3=c.getColumnIndex(DBHelper.ISBN);
    
            for (c.moveToFirst();!c.isAfterLast();c.moveToNext()){
                //result=result+c.getString(is1)+" "+c.getString(is2)+" "+c.getString(is3)+"\n";
                 arrForData.add(c.getString(is1));
                 arrForData.add(c.getString(is2));
                 arrForData.add(c.getString(is3));
            }
              //Toast.makeText(HotOrNot.this, sa, Toast.LENGTH_SHORT).show();
    
    return arrForData.toArray();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get data from database, and echo them on the page using
for example I'm trying to get the data from database like: using (ExplorerDataContext context
I've been trying to present my data from my database using PHP. My while
I'm trying to get data from a database using FMDB but having tried with
I'm trying to get data from another database using the OPENDATASOURCE command, but I
I am trying to get the data from database by using the below code.....
I'm trying to get character data from www.wowarmory.com using PHP and cURL. The code
I am trying to get some form data from POST method. Here's the code
Actually i was trying to get data from elgg database based on multiple joins.
I am trying to get some data out from a database stored as text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.