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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:11:37+00:00 2026-06-04T19:11:37+00:00

I’m trying to make a notecard application. Basically, the user enters in a term

  • 0

I’m trying to make a notecard application. Basically, the user enters in a term and definition, and is allowed to view the data from a selection displayed in my Main activity. I’m having trouble sending the information through an intent and displaying the sent information. Since the user controls the amount of information, I’ve attempted to set up an arraylist and arrayadapter to maintain it. Here’s my Main Activity code:

import java.util.ArrayList;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;

public class Main extends ListActivity {

ArrayList<String> cards;
ArrayAdapter<String> adapter;   

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

  //This will hold the new items
    cards = new ArrayList<String>();
    adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, cards);


    Button b = (Button) findViewById(R.id.button1);
    View footerView = ((LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.listfooter, null, false);
    this.getListView().addFooterView(footerView);

    //Set the adapter
    this.setListAdapter(adapter);

    b.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Main.this, NewNote.class);
            startActivityForResult(intent,0);


        }

    });


}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

 if (requestCode == 0) {

 }
        if (resultCode == RESULT_OK) {

    String s1 =(String) getIntent().getCharSequenceExtra("term");
    String s2 = (String) getIntent().getCharSequenceExtra("definition");
     cards.add(s1);
     cards.add(s2);

     if(cards != null && cards.size() > 0){
           for(int i=0;i<cards.size();i++)
            adapter.add(cards.get(i));
     }
     adapter.notifyDataSetChanged();
}
}
}

And here’s my second activity that retrieves the information from the user:

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class NewNote extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.dialog);

    final EditText et1 = (EditText) findViewById(R.id.editText1);
    final EditText et2 = (EditText) findViewById(R.id.editText2);
    Button b = (Button) findViewById(R.id.button1);

    b.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.putExtra("term", et1.getText());
            intent.putExtra("definition", et2.getText());
            setResult(0, intent);
            finish();
        }
    });


}
}

This code does not work in sending the information through the intent back to my Main activity and adding it my my arraylist, which should be displayed. I also have no idea how to connect a listview on the layout xml files to my arraylist in the java file. I am not sure how to proceed or if I am even on the right track. Can anyone help?

  • 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-04T19:11:39+00:00Added an answer on June 4, 2026 at 7:11 pm

    You have a simple mistake, in NewNote class you call setResult(0, intent);
    where 0 is RESULT_CANCELED and in Main class’es onActivityResult you try to handle RESULT_OK case.

    call setResult(RESULT_OK, intent); and all will be ok 🙂

    As to your comment, what kind of problem?? but try this patches anyway

    in Note:

    public class NewNote extends Activity {
    
        public static final String EXTRA_TERM = "com.yourpackage.EXTRA_NOTE_TERM";
        public static final String EXTRA_DEFINITION = "com.yourpackage.EXTRA_NOTE_DEFINITION";
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.dialog);
            final EditText et1 = (EditText) findViewById(R.id.editText1);
            final EditText et2 = (EditText) findViewById(R.id.editText2);
            findViewById(R.id.button1).setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent();
                    intent.putExtra(EXTRA_TERM, et1.getText().toString());
                    intent.putExtra(EXTRA_DEFINITION, et2.getText().toString());
                    setResult(RESULT_OK, intent);
                    finish();
                }
            });
        }
    }
    

    in Main:

        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            if (requestCode == 0) {
                if (resultCode == RESULT_OK) {
                    final Intent intent = getIntent();
                    String s;
                    if((s = (String) intent.getStringExtra(NewNote.EXTRA_TERM)) != null) {
                        adapter.add(s);
                    }
                    if((s = (String) intent.getStringExtra(NewNote.EXTRA_DEFINITION)) != null) {
                        adapter.add(s);
                    }
                    if(s != null) {
                        adapter.notifyDataSetChanged();
                    }
                }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I have a text area in my form which accepts all possible characters from

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.