• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps EventHandling

renegadeandy

Newbie
Jun 6, 2009
16
0
Hey!

Right i am starting to make my app and am happily moving through the tutorials on the android developer site.

Gota question.

Lets say I have an EditText box:

Code:
<EditText android:text="Insert Team Name"
                	 android:id="@+id/teamInput" 
                	 android:layout_width="fill_parent"
                	 android:layout_height="wrap_content"
                	 android:layout_weight="1">
                </EditText>

How do I get it to call some code once a user has finished inputting it - or is the idea that you have a search button, which retrieves the text on click - either way - can you please paste a bit of code, or a class, where I can create a new object be it a button or a EditText item where I can retrieve the contents to do something with!

Cheers

Andy
 
Assuming this bit of XML as your layout...

Code:
<EditText android:text="Insert Team Name"
                	 android:id="@+id/teamInput" 
                	 android:layout_width="fill_parent"
                	 android:layout_height="wrap_content"
                	 android:layout_weight="1">
                </EditText>

Code:
EditText teamInput = (EditText) findViewById(R.id.teamInput);
String tiVal = teamInput.getText().toString();
 
Upvote 0
Alright cool - trying to get something to work - do standard System.out.println("wowow"); debug statements work - because I am finding it hard to see where my code is dieing :

Ok so I have this :

Code:
 OnClickListener searchTeamListener = new OnClickListener() {
    	           public void onClick(View v) {
    	             TextView txt = (TextView) v.findViewById(R.id.textview3);
    	             EditText search = (EditText) findViewById(R.id.searchTeam);
    	             System.out.println("woof");
    	             txt.setText(search.getText());
    	           }
    	       };
    	       
    	           // Capture our button from layout
    	           Button button = (Button)findViewById(R.id.searchTeam);
    	           // Register the onClick listener with the implementation above
    	           button.setOnClickListener(searchTeamListener);

However I cannot detect if it gets run - when I hit the button, it crashes the app on the emulator! AAAAAAAAAAAAAAAAA!:eek:
 
Upvote 0
Alright cool - trying to get something to work - do standard System.out.println("wowow"); debug statements work - because I am finding it hard to see where my code is dieing :

Ok so I have this :

Code:
 OnClickListener searchTeamListener = new OnClickListener() {
                   public void onClick(View v) {
                     TextView txt = (TextView) v.findViewById(R.id.textview3);
                     EditText search = (EditText) findViewById(R.id.searchTeam);
                     System.out.println("woof");
                     txt.setText(search.getText());
                   }
               };
               
                   // Capture our button from layout
                   Button button = (Button)findViewById(R.id.searchTeam);
                   // Register the onClick listener with the implementation above
                   button.setOnClickListener(searchTeamListener);
However I cannot detect if it gets run - when I hit the button, it crashes the app on the emulator! AAAAAAAAAAAAAAAAA!:eek:
I don't know if this will help but try putting
Code:
TextView txt = (TextView) v.findViewById(R.id.textview3);
EditText search = (EditText) findViewById(R.id.searchTeam);
as method level fields and giving them the final modifier so that the onClick can grab them.
And System.out.println won't work. Use Log.d instead.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones