1

Guys at this time i want to ask HOW TO GET SPECIFIC DATA FROM DATABASE SQLITE THEN SHOW IT IN A TEXTVIEW in SEARCH ACTIVITY

public ArrayList<Sma> getPoint(String name)
{
    ArrayList <Sma> point = new ArrayList<Sma>(); 

    String selectQuery = "SELECT latitude_sma, longtitude_sma FROM sma WHERE nama_sma ='" + name + "'"; >> FROM HERE I JUST WANT TO SHOW latitude_sma, and longtitude_sma IN A TEXTVIEW
    open();
    Cursor c = database.rawQuery(selectQuery, null);

    if (c.moveToFirst()) {
        do {
            Sma sekolah = new Sma();
            sekolah.setLatitude(c.getString(c.getColumnIndex(latitude_sma)));
            sekolah.setLongitude(c.getString(c.getColumnIndex(longtitude_sma)));
            point.add(sekolah);
        } 
        while (c.moveToNext());
    }
    return point;

PLEASE HELP ME!, thx B4 :)

5
  • what is wrong query not working? Commented Mar 15, 2014 at 16:24
  • no, i think the query is okay, but how to show in a textView? cause i don't know how.. Commented Mar 15, 2014 at 16:28
  • You need to call this function in a activity. This returns a list. You can display the data from list based on index Commented Mar 15, 2014 at 16:29
  • can u give me some example, display a data from a list based on index, cause i don't know how :D Commented Mar 15, 2014 at 16:31
  • i just did post a code snippet. should give an idea Commented Mar 15, 2014 at 16:34

1 Answer 1

1

I don't know what you mean by specific data.

You need to call the function that returns a list and display data in textview based on index position

In Activity

Database db = new Database(this);
ArrayList<Sma> list = db.getPoint("your name");
TextView tv = (TextView) findViewById(R.id.textView1);
tv.setText(list.get(0).getLatitude().toString());
Sign up to request clarification or add additional context in comments.

5 Comments

okey, i want to ask, list.get(0) > is this the index from database? cause when i tried, it's error IndexOutOfBoundsExecption. :D
@ndr_sd that is not the index from the database. List in index based. index starts from 0. so if you get a exception check if the list is populated
hei, i'm sorry do u know how to put this tv.setText(list.get(0).getLatitude().toString()); into a double variable?
@ndr_sd double variable? double var= Double.parseDouble(list.get(0).getLatitude().toString())
okayyyy, once again i said thanks to u, and thank u it's really helping ;D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.