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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:52:21+00:00 2026-05-25T21:52:21+00:00

I am trying to make a program that has 2 views. The first view

  • 0

I am trying to make a program that has 2 views. The first view is a list populated from a database. What i want is, when i click an item of the list then i want the program to open the secound view and fill some textviews with data from the database according to the item i clicked. What i have done for now is looking like this:

The first view:

public class MainActivity extends ListActivity {


private static final int ACTIVITY_VIEW = 1;
private DbAdapter mDbHelper;


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

      mDbHelper = new DbAdapter(this);
      mDbHelper.open();
      fillData();      

}

private void fillData() 
{
     Cursor contactCursor = mDbHelper.fetchAllContact();
     startManagingCursor(contactCursor);

     String[] from = new String[]{DbAdapter.KEY_FIRST};

     int[] to = new int[]{R.id.contactlist};

     SimpleCursorAdapter contactsfirst = new SimpleCursorAdapter(this, R.layout.list, contactCursor, from, to);

     setListAdapter(contactsfirst);


}


@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    Intent i = new Intent(this, PersonPage.class);
    i.putExtra(DbAdapter.KEY_ROWID, id);
    startActivityForResult(i, ACTIVITY_VIEW);
}

That should open this view, but it doesent:

public class PersonPage extends Activity
{   

private EditText mFirstText;
private EditText mLastText;
private EditText mPhoneText;
private EditText mMPhoneText;
private EditText mRoomText;
private EditText mInitialText;
private Button mBackButton;

private Long mRowId;

String back = new String("Back");
String na = new String("N/A");

private DbAdapter mDbHelper;


    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
    super.onCreate(savedInstanceState);

            mDbHelper = new DbAdapter(this);
            mDbHelper.open();

            setContentView(R.layout.personpage);

            mFirstText = (EditText) findViewById(R.id.first);
            mLastText = (EditText) findViewById(R.id.last);
            mPhoneText = (EditText) findViewById(R.id.phone);
            mMPhoneText = (EditText) findViewById(R.id.mphone);
            mRoomText = (EditText) findViewById(R.id.room);
            mInitialText = (EditText) findViewById(R.id.initial);
            mBackButton = (Button) findViewById(R.id.back);

            mRowId = (savedInstanceState == null) ? null :
                (Long) savedInstanceState.getSerializable(DbAdapter.KEY_ROWID);
            if (mRowId == null) {
                Bundle extras = getIntent().getExtras();
                mRowId = extras != null ? extras.getLong(DbAdapter.KEY_ROWID)
                                        : null;


            populateFields();

            mBackButton.setOnClickListener(new TextView.OnClickListener() {
                public void onClick(View arg0) {
                    Intent i = new Intent(PersonPage.this, MainActivity.class);
                    PersonPage.this.startActivity(i);
                }
            });

            }           
    }


    private void populateFields() {
        if (mRowId != null) {
            Cursor note = mDbHelper.fetchContact(mRowId);
            startManagingCursor(note);
            mFirstText.setText(note.getString(
                    note.getColumnIndexOrThrow(DbAdapter.KEY_FIRST)));
            mLastText.setText(note.getString(
                    note.getColumnIndexOrThrow(DbAdapter.KEY_LAST)));
            mPhoneText.setText(note.getString(
                    note.getColumnIndexOrThrow(DbAdapter.KEY_PHONE)));
            mMPhoneText.setText(note.getString(
                    note.getColumnIndexOrThrow(DbAdapter.KEY_MPHONE)));
            mRoomText.setText(note.getString(
                    note.getColumnIndexOrThrow(DbAdapter.KEY_ROOM)));
            mInitialText.setText(note.getString(
                    note.getColumnIndexOrThrow(DbAdapter.KEY_INITIAL)));

            }
    }

Can anyone of you help me find the problem?

  • 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-25T21:52:22+00:00Added an answer on May 25, 2026 at 9:52 pm

    Your onListItemClick() should look like this..

        @Override
    public void onListItemClick(ListView list, View view, int position, long id){
        Intent i = new Intent(meeting_list.this, ACTIVITY.class);
    
    
        i.putExtra(ID_EXTRA, String.valueOf(id));
    
    
        startActivity(i);
    }
    

    In the next activity just retrieve the ID.

    Also put a log message to log the ID to insure it is being passed

    Here to the passing activity retrieve it.

    ID = getIntent().getStringExtra(ACTIVITY.ID_EXTRA);
    

    //USe this to load the data with a cursor

    public void load(){
        Cursor c = helper.getByID(meetingId);
    

    There should be a method in your database to getById(). Like this..

    public Cursor getByID(String id){
        String [] args={id};
    
        return(getReadableDatabase().rawQuery("SELECT _id, meetingTitle, meetingDescrip, meetingAdress, meetingDateTime, lat, lon, type FROM meetings WHERE _ID=?", args));
    

    Just substitute your return arg’s for mine.

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

Sidebar

Related Questions

I'm trying to make a program in Visual C# that has my one created
HI all. I am trying to make little program that reads data from file
im trying to make a simple program that has one BITMAP that is the
I am trying to make a program that automatically corrects the perspective of a
I'm trying to make a program that reads the value at a certain address.
Hey, I am trying to make a program that minimises any program to the
I'm trying to make a small program that could intercept the open process of
I am trying to make a program in Java that checks for three specific
Okay so I'm trying to make a little gag program that will run away
Ok, I'm trying to make a program that finds the position of a colored

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.