Android Studio if I have a conditional question.

Asked 2 years ago, Updated 2 years ago, 80 views

I'm making an app while studying in Android studio. To summarize, turn the mockwalker to get the latitude and longitude and to get a picture that matches the latitude and longitude conditions. So far, latitude and longitude are output. But I'm trying to print out an image using a flicker, but I don't know how to print an image with conditional statements using a flicker, so I'm going to declare an image object and print an image inside the flicker. However, images that meet the running conditions are not printed, and only the first image continues to appear.

ViewFlipper mLocationFlipper;
ImageView mimage;
-> declare flippper and image variables

public void onClick_01(View v){

    int Alti = Integer.parseInt(mfind.getAltitude());
    int Longi = Integer.parseInt(mfind.getLongitude());

    if(Alti <= 300 && Longi < -80){
        mimage.setImageResource(R.drawable.suwon);
    }
    else{
        mimage.setImageResource(R.drawable.welcome);
    }

}
-> I received latitude and longitude as string, but after converting to int type, I added if conditional statement. 

The app I made is a composition that receives the latitude and longitude of the current location when I click the button, but the image does not change I posted it here because I was curious.

Also, I wonder if it's a problem because I received it as an int type

public void onClick_01(View v){

    float Alti = Float.parseFloat(mfind.getAltitude());
    float Longi = Float.parseFloat(mfind.getLongitude());

    if(Alti <= 300.0 && Longi < -80.0){
        mimage.setImageResource(R.drawable.suwon);
    }
    else{
        mimage.setImageResource(R.drawable.welcome);
    }

}

-> float brother also tried but he can't. ㅠ<

Thank you for reading this long article.

android-studio

2022-09-21 17:21

1 Answers

<ViewFlipper 
    android:id="@+id/flipper"
    android:layout_width="match_parent"
    android:layout_height="match_parent">   

    <ImageView 
        android:id="@+id/img01"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/img01"/>

    <ImageView 
        android:id="@+id/img02"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/img02"/>    
</ViewFlipper>

Declare the image inside ViewFlipper as shown above in the xm file

mLocationFlipper.showPrevious(); mLocationFlipper.showNext();

You can turn it over to the two methods above.


2022-09-21 17:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.