Showing posts with label import. Show all posts
This is one of my favorites features, it helps you keep track of what is what on your activity, by displaying a popup on you device, this of it as alert on javascript.
1. import the Toast class
2. display any message, anywhere within your code to show on device.
Note: MainActivity is the name of the class we currently on.
1. import the Toast class
import android.widget.Toast;
2. display any message, anywhere within your code to show on device.
Toast.makeText(MainActivity.this, "Hello AppSpaza", Toast.LENGTH_LONG).show();
Note: MainActivity is the name of the class we currently on.
How to create a tip popup (Toast)
This is a nice trick to make your app more interactive. In this article i will show you an ImageView that can change its image resource after it has been clicked.
1. first, make sure you have you imageView class imported and you have an imageView in your layout file.
2. now i will show you the code to change your image resource
This will replace the current image resource of my_image ImageView.
1. first, make sure you have you imageView class imported and you have an imageView in your layout file.
import android.widget.ImageView;
2. now i will show you the code to change your image resource
ImageView my_image = (ImageView) findViewById(R.id.my_image );
my_image.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { my_image.setImageResource(R.drawable.my_image_new); } });
This will replace the current image resource of my_image ImageView.
