Results 1 to 2 of 2
  1. #1
    rolledback is offline Member
    Join Date
    Jun 2011
    Posts
    15
    Rep Power
    0

    Default Passing Variable from a New Activity to an Old Activity

    Hi, I'm attempting to pass a variable the following way.

    Activity 1, user clicks on button--->Activity 2, user clicks on list item, activity 2 is closed and position of list item that was clicked is passed back to Activity 1

    I've attempted to use startActivityForResult but I can't seem to get it all figured out. Here's the relevent code.

    Activity 1
    Java Code:
    int density; 
     Button liquid = (Button) findViewById(R.id.chooseliquid);
            liquid.setOnClickListener(new View.OnClickListener() {			
    			public void onClick(View v) {
    				Intent i = new Intent(PressureCalculatorActivity.this, DensityList.class);
    		        startActivityForResult(i, density);			
    			}
    		});
    
    //this method declaration gives an error
    public void onActivityResult(int d) {
            	density = d;         
            }
    Activity 2
    Java Code:
    @Override
        protected void onListItemClick(ListView l, View v, int position, long id) 
        {    	
        	setResult(position);
        	finish();		
    	}
    Thanks in advance for the help.

  2. #2
    rolledback is offline Member
    Join Date
    Jun 2011
    Posts
    15
    Rep Power
    0

    Default Re: Passing Variable from a New Activity to an Old Activity

    Well I figured it out on my own. Now I just need to know how to add subItems to a ListView. Ideas?

Similar Threads

  1. Replies: 4
    Last Post: 01-17-2012, 01:39 AM
  2. applet and system activity
    By rafzio4 in forum New To Java
    Replies: 0
    Last Post: 10-20-2010, 01:58 PM
  3. Help Please Override Activity with Android
    By francojava1 in forum Android
    Replies: 2
    Last Post: 10-12-2010, 07:35 PM
  4. Learning Activity Management System 2.0.3
    By levent in forum Java Software
    Replies: 0
    Last Post: 06-05-2007, 12:44 PM
  5. Learning Activity Management System 2.0
    By levent in forum Java Software
    Replies: 0
    Last Post: 05-16-2007, 06:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •