Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Android
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Android
The Toast msg doesn't show
sasa anali
Ranch Hand
Posts: 30
posted 9 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hello
I'm trying to show a Toast msg in the page but it's not working .. here it is
package com.ex.ample; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.widget.Button; import android.widget.Toast; import android.view.View; import android.view.View.OnClickListener; public class MainActivity extends Activity { Button dolink; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fishguide); addListenerOnButton(); } @Override public void onClick(View arg0) { // TODO Auto-generated method stub Toast.makeText(getBaseContext(), "Sorted alphabetically inside", Toast.LENGTH_SHORT).show(); } public void addListenerOnButton() { final Context context = this; dolink = (Button) findViewById(R.id.fish); dolink.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent intent = new Intent(context, PageFish.class); startActivity(intent); } }); } }
It works well but to Toas msg doesn't show
Help
Ulf Dittmer
Rancher
Posts: 43081
77
posted 9 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Is the onClick method ever executed? How does the code even compile? Activity does not have an onClick method, and neither do any of its superclasses; so the Override annotation should trigger a compilation error.
sasa anali
Ranch Hand
Posts: 30
posted 9 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I removed the onClick and paste it to you, I tried many things, it didn't work
package com.ex.ample; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.widget.Button; import android.widget.Toast; import android.view.View; import android.view.View.OnClickListener; public class MainActivity extends Activity { Button dolink; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fishguide); addListenerOnButton(); Toast.makeText(getBaseContext(), "Sorted alphabetically inside", Toast.LENGTH_SHORT).show(); } public void addListenerOnButton() { final Context context = this; dolink = (Button) findViewById(R.id.fish); dolink.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent intent = new Intent(context, PageFish.class); startActivity(intent); } }); } }
sasa anali
Ranch Hand
Posts: 30
posted 9 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
It worked
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
How to create a toast via button click
Fourth link
Fetching contacts from phone book
android - intent
activity doesn't wait untill alertdialog completes
More...