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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:10:10+00:00 2026-05-28T00:10:10+00:00

I have an activity where i write a name which is insert in the

  • 0

I have an activity where i write a name which is insert in the database. In another activity I want to put a ListView which is populated with those names which are in the database or to add the new item directly when i write it in the edittext from the first activity.
I realized the insert into database part but i can’t figure out how to populate that listview.

public class Add extends Activity implements OnClickListener{

Button sqlUpdate;
EditText sqlName;


@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.add);
    sqlUpdate = (Button) findViewById(R.id.bFinishAdd);
    //sqlView = (Button) findViewById(R.id.bSQLopenView);
    sqlName = (EditText) findViewById(R.id.etAdd);
    sqlUpdate.setOnClickListener(new OnClickListener(){

        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            boolean didItWork = true;

            try{
            String name = sqlName.getText().toString();

            DBhelp entry = new DBhelp(Add.this);
            entry.open();
            entry.createEntry(name);
            entry.close();
            Intent i = new Intent(Add.this, Liste.class);
            startActivity(i);

            }catch(Exception i){
                didItWork = false;
            }finally{
        }
        }


    });

}


public void onClick(View arg0) {
    // TODO Auto-generated method stub

}

}

Here is the database helper:

      public class DBhelp {

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



private static final String DATABASE_NAME = "DBhelpdb";
private 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);"


        );
    }

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

}

public DBhelp(Context c){
    ourContext = c;
}
public DBhelp open() throws SQLException{
    ourHelper = new DbHelper(ourContext);
    ourDatabase = ourHelper.getWritableDatabase();
    return this;
}
public void close(){
    ourHelper.close();
}
public void createEntry(String name) {
    // TODO Auto-generated method stub
    ContentValues cv = new ContentValues();
    cv.put(KEY_NAME, name);

    ourDatabase.insert(DATABASE_TABLE, null, cv);
}
public String getData() {
    // TODO Auto-generated method stub
    String[] columns = new String[]{KEY_ROWID, KEY_NAME};
    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);

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

    return result;
}
public String getName(long l) {
    // TODO Auto-generated method stub
    String[] columns = new String[]{KEY_ROWID, KEY_NAME};
    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 void updateEntry(long lRow, String mName) {
    // TODO Auto-generated method stub
    ContentValues cvUpdate = new ContentValues();
    cvUpdate.put(KEY_NAME, mName);
    ourDatabase.update(DATABASE_TABLE, cvUpdate, KEY_ROWID + "=" + lRow, null);
}
public void deteleEntry(long lRow1) {
    // TODO Auto-generated method stub
    ourDatabase.delete(DATABASE_TABLE, KEY_ROWID + "=" + lRow1, null);}
}

And here is the activity where I want to implement the listview with that items :

     public class Liste extends Activity{

Button btnAdd;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.liste);
    btnAdd = (Button) findViewById(R.id.bAdd);
    btnAdd.setOnClickListener(new OnClickListener(){

        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            Intent i = new Intent("com.project.mapshop.ADD");
            startActivity(i);
        }

    });
    TextView tv = (TextView) findViewById(R.id.tvSQLinfo);
    DBhelp info = new DBhelp(this);
    info.open();
    String data = info.getData();
    info.close();
    tv.setText(data);

}}

I would be very grateful if you could explain me how to do it or give me a link with an advice or tutorial which could help me. Thank you very much!

  • 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-28T00:10:10+00:00Added an answer on May 28, 2026 at 12:10 am

    Please follow some simple tutorials first, some good tutorials are:

    1- Simple Example

    2- ListView of Data from SQLiteDatabase

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Activity with ListView inside it and in the onCreate method of the
I have an Activity in Android, with two elements: EditText ListView When my Activity
I have an activity which shows some List entries. When I click on a
I have an activity that launches another activity with startActivityForResult method. I would like
I have an activity which have a method in it. In this method I
I want to write some values from editText of activity in the file string.xml.
I'm trying to write a query that reports the current database activity. The query
I have application A defined as below: <application android:icon=@drawable/icon android:label=@string/app_name> <activity android:name=com.example.MyExampleActivity android:label=@string/app_name> <intent-filter>
I have one activity A, that has one button and one list view which
i have a main Activity called Main which has onActivityResult Method. protected void onActivityResult(int

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.