Passing text of an EditText

Put your problem here if it does not fit any of the other categories.

Passing text of an EditText

Postby erbedo » Sat Mar 15, 2008 6:20 pm

Hi
I have two activities. The first simply displays a textView, and editText and a Button. What I want to do is, when a user click the button, I'd to start the second activity, passing the text typed in the EditText box.

What I've done is the following:
this is the first activity
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         protected void onCreate(Bundle icicle) {
  2.  
  3.                 // TODO Auto-generated method stub
  4.  
  5.                 super.onCreate(icicle);
  6.  
  7.                
  8.  
  9.                 this.setContentView(R.layout.selection);
  10.  
  11.                
  12.  
  13.                 Button btn = (Button)this.findViewById(R.id.selectionOk);
  14.  
  15.                 btn.setOnClickListener(new OnClickListener(){
  16.  
  17.  
  18.  
  19.                         public void onClick(View arg0) {
  20.  
  21.                                 // TODO Auto-generated method stub
  22.  
  23.                                 Intent myIntent = new Intent();
  24.  
  25.                                 myIntent.setAction("com.google.android.tvsportfinder.DO_SEARCH");
  26.  
  27.  
  28.  
  29.                                 startActivity(myIntent);
  30.  
  31.                         }              
  32.  
  33.                 });    
  34.  
  35.         }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


Before startActivity, I need to pass the data, but
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. myIntent.setData()
Parsed in 0.029 seconds, using GeSHi 1.0.8.4
picks only a ContentURI, not simple text. So, this is the first question: how to pass a simlpe string via an Intent?

Secondly, the handler of the Intent is my other activity. In the AndroidManifest.xml I've wrote:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.         <activity android:name="SecondActivity">
  2.  
  3.                         <intent-filter>
  4.  
  5.                                 <action android:name="com.google.android.myapp.DO_SEARCH"/>
  6.  
  7.                         </intent-filter>
  8.  
  9.                 </activity>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


but when I click the button on the first activity, I got that there's no activity that can handle this action. So, how to make my second activity able to receive such Intent?

Thank you
Proudly supporting Android :)
erbedo
Junior Developer
Junior Developer
 
Posts: 22
Joined: Thu Mar 13, 2008 9:39 pm

Top

Postby certron » Mon Mar 17, 2008 3:58 am

While I don't have all the answers, I believe it should be possible to pass information between Intents through the use of the bundle / extras functionality.

I would recommend going through the Notepad tutorials that Google provides, even if it is just to see how a whole application is broken into pieces. The bundle feature that I am talking about is covered in the second version (and then removed as the project is improved in the third version): http://code.google.com/android/intro/tutorial-ex2.html

Good luck on your project! This sounds very much like something I will be doing soon, actually, where I am passing back the text entered to another part of the application.
certron
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue Jan 29, 2008 4:42 pm

Postby erbedo » Mon Mar 17, 2008 9:28 am

Hi
I solved that adding a String to the Intent. On the receiver side, I simply used
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. getIntent().getString("pattern");
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


Thank you
Proudly supporting Android :)
erbedo
Junior Developer
Junior Developer
 
Posts: 22
Joined: Thu Mar 13, 2008 9:39 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot] and 17 guests