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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:28:21+00:00 2026-05-26T02:28:21+00:00

I have a database like this: table pepak, table category, table subcategory I just

  • 0

I have a database like this: table pepak, table category, table subcategory
I just want to display category if I click one of the pepak.name
But now if I click one of pepak.name, my app faced an error and stopped.

Here is my code:

Menu.java

public class Menu extends ListActivity{
    protected SQLiteDatabase db;
    protected Cursor cursor;
    protected ListAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        db = (new DatabaseHelper(this)).getWritableDatabase();
        cursor = db.rawQuery("SELECT _id, name FROM pepak", null);
        adapter = new SimpleCursorAdapter(
        this, 
        R.layout.pepaklist,
        cursor, 
        new String[] {"name"}, 
        new int[] {R.id.name});
        setListAdapter(adapter);
}

public void onListItemClick(ListView parent, View view, int position, long id) {
    Intent intent = new Intent(this, PepakCats.class);
    Cursor cursor = (Cursor) adapter.getItem(position);
    intent.putExtra("PEPAK_ID", cursor.getInt(cursor.getColumnIndex("_id")));
    startActivity(intent);
}

@Override
public boolean onCreateOptionsMenu(android.view.Menu menu) {
    // TODO Auto-generated method stub
    super.onCreateOptionsMenu(menu);
    MenuInflater blowUp =  getMenuInflater();
    blowUp.inflate(R.menu.coll_menu, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // TODO Auto-generated method stub
    switch(item.getItemId()){

    case R.id.about:
        Intent i = new Intent("com.pepakbahasajawa.ABOUT");
        startActivity(i);
        break;

    case R.id.exit:
        finish();
        break;
    }
return false;
}

}

PepakCats.java

public class PepakCats extends ListActivity {
    protected Cursor cursor;
    protected ListAdapter adapter;
    protected int pepakId;

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

        pepakId = getIntent().getIntExtra("PEPAK_ID", 0);
        SQLiteDatabase db = (new DatabaseHelper(this)).getWritableDatabase();

        Cursor cursor = db.rawQuery(
            "SELECT _id, pepakId, catname FROM category WHERE pepakId = ?", 
        new String[]{""+pepakId}
        );

        adapter = new SimpleCursorAdapter(
            this, 
            R.layout.category_list,
            cursor, 
            new String[] {"catname"}, 
            new int[] {R.id.catname}
        );

        setListAdapter(adapter);
    }
}

How can I display the listview data from the database after the click?

  • 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-26T02:28:21+00:00Added an answer on May 26, 2026 at 2:28 am

    Try using the id directly:

    public void onListItemClick(ListView parent, View view, int position, long id) {
                Intent intent = new Intent(this, PepakCats.class);
                intent.putExtra("PEPAK_ID", id);
                startActivity(intent);
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database table like this: wagetable name lowhours highhours wage Default 0
I have a SQL 2008 database table like this name score ----------------------- steve 207
I have a database table like this <table> <tr> <th>no</th> <th>name</th> <th>income</th> <th>work</th> <th>score</th>
i have database table like this +-------+--------------+----------+ | id | ip | date |
I have a database table like this: id version_id field1 field2 1 1 texta
I have a database application in which a group is modeled like this: TABLE
I have a database that contains a table that looks a bit like this:
I always forget how to do things like this. I have a database table
I have a table in a MSSQL database that looks like this: Timestamp (datetime)
I have written a function to print database table to an array like this

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.