Am trying to get the ImageView drawable and use it to create an if else statement, i have tried many solutions including the one below, all are not working they always give me the wrong Toast
if(holder.likeImage.getDrawable()==context.getResources().getDrawable(R.drawable.ic_action_like)){
Toast.makeText(context, "LIKED ALREADY", Toast.LENGTH_SHORT).show();
}
else if(holder.likeImage.getDrawable()!=context.getResources().getDrawable(R.drawable.ic_action_like)){
Toast.makeText(context, "YOU HAVNT LIKED", Toast.LENGTH_SHORT).show();
}
try this.
holder.likeImage.setImageResource(R.drawable.ic_action_like);
holder.likeImage.setTag(R.drawable.ic_action_like);
if(holder.likeImage.getTag().equals(R.drawable.ic_action_like)){
}else{
}
Related
I have an event click BotaoFlutuante_Click but not work to show message and to call my class (work fine to change set image). I don´t know what i´m doing wrong. Can help me?
private void BotaoFlutuante_Click(object sender, System.EventArgs e)
{
botaoFlutuante.SetImageDrawable(GetDrawable(Resource.Drawable.iconeverde));
EnviaSms enviarSms = new EnviaSms();
enviarSms.EnviarSms();
Toast.MakeText(Application.Context, "PAPAPAPAPA", ToastLength.Long);
}
Toast.MakeText(Application.Context, "PAPAPAPAPA", Toast.LENGTH_LONG).show();
You are missing the .show(); syntax and also change the ToastLength.Long into Toast.LENGTH_LONG
I once also spent hours working with that problem.
I want to make the user to fill all the particular edittext and cannot leave it empty. I use .isEmpty code and the or symbol "|". This is what I make:
if(!e_name.getText().toString().isEmpty()|!e_numb.getText().toString().isEmpty()|!e_pangkat.getText().toString().isEmpty()
|!e_tarikh.getText().toString().isEmpty()|!e_masa.getText().toString().isEmpty())
{
Toast.makeText(getApplicationContext(), "Cannot empty", Toast.LENGTH_SHORT).show();
return;
}else {//another code}
when I run the code, even when the edit text is fill, it still toast "cannot empty" what did I do wrong?
Use double pipes for or ||, single pipes are for bitwise operations
Also your if-statement is probably wrong, currently you check if the strings are NOT empty and give an error.
You should remove the ! from the statements so you check if the strings ARE empty, then give the error.
if(e_name.getText().toString().isEmpty()||e_numb.getText().toString().isEmpty()||e_pangkat.getText().toString().isEmpty()||e_tarikh.getText().toString().isEmpty()||e_masa.getText().toString().isEmpty())
{
Toast.makeText(getApplicationContext(), "Cannot empty", Toast.LENGTH_SHORT).show();
return;
}
else {//another code}
Try like this
if(!e_name.getText().toString().isEmpty()||!e_numb.getText().toString().isEmpty()||!e_pangkat.getText().toString().isEmpty()
||!e_tarikh.getText().toString().isEmpty()||!e_masa.getText().toString().isEmpty())
{
Toast.makeText(getApplicationContext(), "Cannot empty", Toast.LENGTH_SHORT).show();
return;
}else {//another code}
I am trying to make a toast display some text given certain conditions inside an onClickListener. The app won´t run in the simulator, and I get the following error: "void cannot be converted to Toast"
I have searched around, and find several similar problems and solutions on this forum, but none of them applies completely to my problem. The others haven´t used the correct context in the statement, but I really mean that I do. (The name of the javafile (context) is: "Case1Activity") Can anyone help me with this?
I have simplified the code a bit:
public void onClick(View view) {
if (button1Pushed == false){
count++;
Toast toast = Toast.makeText(Case1Activity.this, "You are doing this in the right order!", Toast.LENGTH_LONG).show();
}
}
});
do it without assignment statement
Toast.makeText(Case1Activity.this, "You are doing this in the right order!", Toast.LENGTH_LONG).show();
apply it as.
Toast.makeText(Case1Activity.this, "You are doing this in the right order!", Toast.LENGTH_LONG).show();
if you want to use assignment operator then you can use below code
Toast toast = Toast.makeText(context, text, duration);
toast.show();
Dear Friend check below before eating Toast,
Your Toast (Incompatible types error) :
Toast toast = Toast.makeText(Case1Activity.this, "You are doing this in the right order!", Toast.LENGTH_LONG).show();
Normal Case (Standard Use):
Toast.makeText(Case1Activity.this, "You are doing this in the right order!", Toast.LENGTH_LONG).show();`
Special Case (if you need reference of Toast):
View toast = Toast.makeText(MainActivity.this, "You are doing this in the right order!", Toast.LENGTH_LONG).show();
because here ".show()" method is -
public void show () which
shows the view for the specified duration.
Thanks
I'm trying to use a Toast message inside a listener method, but I get an error saying something like: Toast is not applicable for the argument.. I don't understand this and can't solve this problem without some help? Thanks!
// Button 1
button_1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//text_1.setText("New text for first row!"); // Change text
Toast.makeText(this, "You have clicked on number 1", Toast.LENGTH_LONG).show();
if(controlImage_1)
{
image_1.setImageResource(R.drawable.android_1b); // Change image
controlImage_1 = false;
}
else
{
image_1.setImageResource(R.drawable.android_1a); // Change image
controlImage_1 = true;
}
//Toast.makeText(this, "Your download has resumed.", Toast.LENGTH_LONG).show();
}
});
Try it:
Toast.makeText(**YourClassName.this**, "You have clicked on number 1", Toast.LENGTH_LONG).show();
Without * =)
Toast.makeText(this, "You have clicked on number 1", Toast.LENGTH_LONG).show();
Your this in this statement refers to the View.OnClickListener you created. Read more on anonymous inner classes.
Use MyActivity.this instead
You need to pass in the Context of the current Activity as the first argument. You can't just say this in this case because it is not referring to the application context. You can either create a variable in your on create and use that context or just do this...
Toast.makeText([CLASS_NAME].this, "You have clicked on number 1", Toast.LENGTH_LONG).show();
Replace [CLASS_NAME] with the class that is extending Activity
Try getApplicationContext() as first argument for Toast.makeText or MyActivity.this
here in your code , this refers to the View
Also, if button_1 needs to have onclick listener by default and you are using API > 7,its nice to define onclick="myclickfunction" in the layout itself. Cleans up your code and easy to modify...
Because you are using it in the onClick Listener method, you cannot use only this as the first parameter.
Toast.makeText(ClassName.this, "You have clicked on number 1", Toast.LENGTH_LONG).show();
Use your classname.this as the first parameter.
The thing is like this. I have a zip file with images that uncompressing in the background (using a Thread) I start a new Activity from my main one to show these images. To show the first image I call this function on onResume:
public boolean showImage(String validFile){
File page = new File(validFile);
System.err.println("Attempting to show " + validFile);
boolean found = false;
if (page.exists()){
System.err.println("Page exist");
found = true;
}
else{
System.err.println("Page does not exist");
long start = System.currentTimeMillis();
//ProgressDialog loading = ProgressDialog.show(this, "", "Loading....",true);
Toast.makeText(this, "Loading...", Toast.LENGTH_LONG);
while (((System.currentTimeMillis() - start) < 5000) && (!found)){
if (page.exists()){
found = true;
//t.cancel();
System.err.println("Page found");
}
else{
System.err.println("Page does not exist");
}
}
}
if (!found){
return false;
}
else{
System.err.println("Setting up image");
ims.setImageDrawable(new BitmapDrawable(BitmapFactory.decodeFile(validFile)));
return true;
}
}
All I want to do is to show a Toast a progress dialog or something that says Loading... while the first image uncompresses. However neither the toast or the image are shown. Now I know the image is there for two reasons: 1 the Setting up Image and File found messages appear and I can use fling to move through the images and work just fine.
This is what happens. My activity starts and enters the code above but the first image is never shown. I fling and see the second image and the third and so forth.
So what am I doing wrong?
Thanks for any help!
There might be another issue besides this, but the toast will not appear if you don't call the show() method:
Toast.makeText(this, "Loading...", Toast.LENGTH_LONG).show();