In my previous article I discussed about how to create user interfaces in Android. Here I’m going to show you how you can add event handler to that UI. To do that, first add these two lines between package and class declaration.
To do that, first add these two lines between package and class declaration.
import android.view.View; import android.widget.Button;
Now replace your onCreate method using following code.
import android.view.View; import android.widget.Button; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.testview); Button ok = (Button)findViewById(R.id.btn_testview_ok); ok.setOnClickListener(new View.OnClickListener() { public void onClick(View v){ moveToMain(); } }); } private void moveToMain() { // TODO Auto-generated method stub setContentView(R.layout.main); }
In the above code "btn_testview_ok" is the id of the "Ok" button in previous article. When you click that button, the moveToMain(); method will be called and content view will changed as "main.xml". I will discuss more about this topic in my next posts.
I'm new one for Android.
ReplyDeleteThanks mate.
These information are very very useful
ReplyDelete(Muhammad Nasir)
Thanks A lot
ReplyDeleteSudhanshu Ranjan
it makes the event handler in java like in visual basic. Thanks it really helpfill
ReplyDelete@ All Anonymous,
ReplyDeleteThank You !
@ Muhammad Nasir,
Thank you very much for the comment.
@ Sudhanshu Ranjan ,
Yes, thanks for the comment.
@ Jack D'silva,
ReplyDeleteThanks for the comment...
your post ha been very useful. thank you very much. i am facing a problem when i am trying to implement the code in a user interface. can u help me out?
ReplyDelete@ Sanghamitra,
ReplyDeletesure, tell me your problem.
Hi Saranga
ReplyDeleteyour post ha been realy very helpful, thank u very much.
can u please help me with geo location finder code and google map integration to tht geo location.
Hey Saranga,
ReplyDeleteYour article is really helpful to beginner. I appreciate your effort.
I am also new to this technology. Can you help me to learn XMLParsing topic. Thanks in advance.
Thanks,
Amrish Patel