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 7600061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:49:06+00:00 2026-05-30T22:49:06+00:00

I’m trying to learn SQLite . I wanted to put the information from the

  • 0

I’m trying to learn SQLite. I wanted to put the information from the database(TextView) to a ListView that is clickable(I still don’t have idea in clickable ListView). Can I get some help on how to get data from my database and put it on a ListView that is clickable? Here is the code from a tutorial site that I wanted to have in a ListView:

Button ViewBack;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub

    super.onCreate(savedInstanceState);
    setContentView(R.layout.sqlview);

    ViewBack=(Button) findViewById(R.id.bVBack);
    TextView tv = (TextView) findViewById(R.id.tvSQLinfo);
    ViewBack.setOnClickListener(this);

    HotOrNot info = new HotOrNot(this);
    info.open();
    String data = info.geData(); 
    info.close();
    tv.setText(data);

}
@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    finish();

}

sqlview.xml:

<ScrollView
      android:layout_width="fill_parent"
      android:layout_height="match_parent" >      
<TextView
    android:id="@+id/tvSQLinfo"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginTop="10dp"
    android:text="get info from db" />
</ScrollView>

At first I tried putting this:

ListView lv = (ListView) findViewById(R.id.listMe);
ListAdapter listAD = new ListAdapter(this,R.id.listMe, tv);
 lv.setAdapter(listAD);

but I get an error that cannot instantiate the data type ListAdapter, so I tried replacing SimpleCursorAdapter on the new ListAdapter(this,R.id.listMe,tv):

ListAdapter listAD = new SimpleCursorAdapter (this,R.id.listMe,tv, null, null);

but it gives me again an error, it suggest that I change the cast to Cursor so, I changed all of it until it didn’t give me any errors. When I tried to run it, it wouldn’t work. Here’s the HotOrNotClass:

public static final String KEY_ROWID= "_id"; 
public static final String KEY_NAME= "persons_name"; 
public static final String KEY_HOTNESS= "presons_hotness"; 

private static final String DATABASE_NAME= "HotOrNotdb";
public static final String DATABASE_TABLE= "peopleTable"; 
private static final int DATABASE_VERSION= 1;

private DbHelper ourHelper;
private final Context ourContext;
private SQLiteDatabase ourDatabase;

private static class DbHelper extends SQLiteOpenHelper{

    public DbHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        // TODO Auto-generated constructor stub
    }


    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub

        db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" +
                KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                KEY_NAME + " TEXT NOT NULL, " +
                KEY_HOTNESS + " TEXT NOT NULL);"
        );  

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
            db.execSQL("DROP TABLE IF EXISTS " +DATABASE_TABLE);
            onCreate(db);
    }

}
public HotOrNot(Context c){
    ourContext=c;
}

public HotOrNot open() throws SQLiteException{
ourHelper = new DbHelper(ourContext);
ourDatabase =ourHelper.getWritableDatabase();

return this;  }

public void close(){
    ourHelper.close();
}

public long createEntry(String name, String hotness) {
    // TODO Auto-generated method stub
    ContentValues cv = new ContentValues();
    cv.put(KEY_NAME, name);
    cv.put(KEY_HOTNESS, hotness);
    return ourDatabase.insert(DATABASE_TABLE, null, cv);

}

public String geData() {
    // TODO Auto-generated method stub
    String[]columns=new String[]{ KEY_ROWID,KEY_NAME, KEY_HOTNESS};
    Cursor c =ourDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null);
    String result ="";
    int iRow=c.getColumnIndex(KEY_ROWID);
    int iName=c.getColumnIndex(KEY_NAME);
    int iHotness=c.getColumnIndex(KEY_HOTNESS);

    for(c.moveToFirst(); !c.isAfterLast();c.moveToNext()){
        result=result + c.getString(iRow)+" "+c.getString(iName)+" "+c.getString(iHotness)+"\n";
    }
    return result;

}
public String getName(long l) throws SQLiteException{
    // TODO Auto-generated method stub
    String[]columns=new String[]{ KEY_ROWID,KEY_NAME, KEY_HOTNESS};
    Cursor c= ourDatabase.query(DATABASE_TABLE, columns,  KEY_ROWID+"="+l, null, null, null, null);
    if (c!=null){
        c.moveToFirst();

        String name=c.getString(1);
        return name;
    }
    return null;
}

public String getHotness(long l)throws SQLiteException {
    // TODO Auto-generated method stub
    String[]columns=new String[]{ KEY_ROWID,KEY_NAME, KEY_HOTNESS};
    Cursor c= ourDatabase.query(DATABASE_TABLE, columns, KEY_ROWID+"="+l, null, null, null, null);
    if (c!=null){
        c.moveToFirst();

        String hotness=c.getString(2);
        return hotness;
    }
    return null;
}
  • 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-30T22:49:07+00:00Added an answer on May 30, 2026 at 10:49 pm

    Your getData() method returns a big String with all the results. I don’t think this is what you want for your list, so modify the getData() method so you can return a list of String representing your database records:

    public ArrayList<String> geData() {
        // TODO Auto-generated method stub
        String[]columns=new String[]{ KEY_ROWID,KEY_NAME, KEY_HOTNESS};
        Cursor c =ourDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null);
        ArrayList<String> result = new ArrayList<String>();
        int iRow=c.getColumnIndex(KEY_ROWID);
        int iName=c.getColumnIndex(KEY_NAME);
        int iHotness=c.getColumnIndex(KEY_HOTNESS);
    
        for(c.moveToFirst(); !c.isAfterLast();c.moveToNext()){
            result.add(c.getString(iRow)+" "+c.getString(iName)+" "+c.getString(iHotness));
        }
        return result;
    }
    

    In order to show a list you’ll have to put a ListView element in your Activity layout(sqlview) so you could make the layout like this:

        <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    
        <Button
            android:id="@+id/bVBack"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Something" />
    
        <ListView
            android:id="@+id/listMe"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
    
    </LinearLayout>
    

    Then in your onCreate() method bind the ListView to an Adapter :

    //...
    ListView lv = (ListView) findViewById(R.id.listMe);
    HotOrNot info = new HotOrNot(this);
    info.open();
    ArrayList<String> data = info.geData(); 
    info.close();
    lv.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item1, data));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.