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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:34:27+00:00 2026-06-17T15:34:27+00:00

I have a android application and I use two activitys. The first can create

  • 0

I have a android application and I use two activitys. The first can create a record in the sqlite database and the second show this records in a listview. The Problem is now to show my records in the listview ;(

for connecting with the database i wite a class (DatenbankManager). I show my code.

My DatenbankManager class:

public class DatenbankManager extends SQLiteOpenHelper {

    private static final String DB_Name = "Stundenplanname.db";
    private static final int DB_VERSION = 1;

    public static String STUNDENPLAN_CREATE; 

    private static final String KLASSEN_DROP = "DROP TABLE IF EXIST Stundenplan";

        //Konstruktor
        public DatenbankManager(Context context) {
            super(context, DB_Name, null, DB_VERSION);

        }

        //Methode wenn eine Datenbank erstellt werden muss
        @Override
        public void onCreate(SQLiteDatabase db) {

            db.execSQL(STUNDENPLAN_CREATE);
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

                db.execSQL(KLASSEN_DROP); // Löscht Tabelle wenn nicht vorhanden 
                onCreate(db); //Erstellt Tabelle
        }

}

My first Activity for create a record:

public class NewActivity extends Activity {

    private SQLiteDatabase mDatenbank;
    private DatenbankManager mHelper;


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

        mHelper = new DatenbankManager(this);

        mHelper.STUNDENPLAN_CREATE = "CREATE TABLE Stundenplan(" +
                "_id INTEGER PRIMARY KEY AUTOINCREMENT, "+
                "name TEXT NOT NULL)";

    }

    @Override
    protected void onPause() {
        super.onPause();
        mDatenbank.close();

        Toast.makeText(this, 
                getResources().getString(R.string.db_close),
                Toast.LENGTH_SHORT).show(); 
    }

    @Override
    protected void onResume() {

        super.onResume();
        mDatenbank = mHelper.getReadableDatabase(); 

        Toast.makeText(this, 
                getResources().getString(R.string.db_open),
                Toast.LENGTH_SHORT).show(); 

    }

    public void addNewPlan(View view)
    {
        EditText et = (EditText)findViewById(R.id.schultag_name);

        ContentValues werte = new ContentValues();
        werte.put("name",et.getText().toString());

        mDatenbank.insert("stundenplan", null, werte);

        Toast.makeText(this, 
                getResources().getString(R.string.add),
                Toast.LENGTH_SHORT).show(); 

        et.setText("");
    }

}

My Problem Activity! showActivity:

public class ShowActivity extends ListActivity {

    private SQLiteDatabase mDatenbank;
    private DatenbankManager mHelper;

    private static final String KLASSEN_SELECT_ROW = 
            "SELECT _id, name FROM Stundenplan";


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

        mHelper = new DatenbankManager(this);
        mDatenbank = mHelper.getReadableDatabase(); 

        ladeDaten(); 

    }

    @Override
    protected void onPause() {
        super.onPause();
        mDatenbank.close();

        Toast.makeText(this, 
                getResources().getString(R.string.db_close),
                Toast.LENGTH_SHORT).show(); 
    }

    @Override
    protected void onResume() {     
        super.onResume();
        mDatenbank = mHelper.getReadableDatabase(); 

        Toast.makeText(this, 
                getResources().getString(R.string.db_open),
                Toast.LENGTH_SHORT).show(); 

        ladeDaten();
    }

    private void ladeDaten() {
        Cursor KlassenCursor = mDatenbank.rawQuery(KLASSEN_SELECT_ROW, null); 
        startManagingCursor(KlassenCursor); 

        android.widget.SimpleCursorAdapter KlassenAdapter = new android.widget.SimpleCursorAdapter(this,
                android.R.layout.simple_list_item_1, 
                KlassenCursor, 
                new String[] {"name"},
                new int[] {
                android.R.id.text1
                });

        setListAdapter(KlassenAdapter);
    }


}

here is the Layout xml from my showActivity:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#111111"
    android:baselineAligned="false"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="250dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"
        android:text="Stundenplanname"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#19630F"
        android:textSize="22sp" />

    <ListView
        android:id="@+id/listView1"
        android:layout_width="250dp"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        android:layout_height="wrap_content"
        android:textColor="#19630F"
        android:layout_gravity="center" >

    </ListView>

</LinearLayout>
  • 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-06-17T15:34:28+00:00Added an answer on June 17, 2026 at 3:34 pm

    if you are extending ListActivity in your Activity then your ListView must have android:id="@android:id/list" instead of android:id="@+id/listView1" . change your ListView xml as :

    <ListView
        android:id="@android:id/list"
        android:layout_width="250dp"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        android:layout_height="wrap_content"
        android:textColor="#19630F"
        android:layout_gravity="center" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Android application, backed by an API. To this API users can
In my Android application I have to use common string value for all activities.
I have a big text file (5Mb) that I use in my Android application.
I have an android application and while switching between two activities I want to
I have an Android application with version 1.6 I take the wallpaper and show
I have a android webservice client application. I am trying to use the java
Say I have two Activities in an Android application, EditPerson and EditEmployee . It
I have an Android project. Now I need to create a second edition of
i am beginner at android. I have two class, and first class is public
I have a application which use two layouts in portrait ans landscape. To load

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.