2015-11-11 65 views
-2

我有一个布尔值,它根据方法结果返回True或False。将文本更改为True或False

我想制作一个大文本,每次根据该布尔值写入TRUE或FALSE。

我该怎么做?
这是一个爆裂相机。

事情是,我使用相机作为按钮,每次有人触摸相机时它都会返回FALSE,并且每次相机拍摄照片时都没有人将其设置为黑暗,则会返回TRUE。

当FALSE发生时,相机将转到另一个活动。
TRUE和FALSE事情工作得很好,但我只能在我的日志中检查它。

我只想要一个按钮,而不是在应用程序UI中写入文本。

public static boolean ImagemEscura(Bitmap img) 
    { 
     float totalpixel = img.getWidth() * img.getHeight(); 
     float totalpixelescuro = 0; 
     for(int x = 0; x < img.getWidth(); x++) 
     { 
      for(int y = 0; y < img.getHeight(); y++) 
      { 
       int cor = img.getPixel(x, y); 

       if(SomaRGB(cor) > 90) 
       { 
        totalpixelescuro++; 
       } 
      } 
     } 

     return totalpixelescuro/totalpixel > 0.75f; 
    } 

    public static int SomaRGB(int cor) 
    { 
     return getRed(cor) + getGreen(cor) + getBlue(cor); 
    } 

    public static int getRed(int argb) 
    { 
     return argb >> 16 & 0xFF; 
    } 

    public static int getGreen(int argb) 
    { 
     return argb >> 8 & 0xFF; 
    } 

    public static int getBlue(int argb) 
    { 
     return argb & 0xFF; 
    } 

} 
+0

邮政你写的代码来实现这一点。 – csmckelvey

回答

1

如果该函数返回一个布尔值,然后检查返回值是truefalse。然后相应地设置您的TextView

您只需添加到您的代码

Boolean result=your_class.ImagemEscura(your_bitmap); 
if(result) 
    your_textview.setText("TRUE"); 
else 
    your_textview.setText("FALSE"); 
+0

我把这个放在我的代码上? – user3068649

+0

你将不得不决定......如果不知道你想要达到什么目的,你真的很难说。 – Lal

0

这可以在一个行完成:

mYourTextView.setText(String.valueOf(ImagemEscura(bitmap))); 
0

你可以做,在一个行:

your_textview.setText(your_class.ImagemEscura(your_bitmap) ? "TRUE" : "FALSE"); 
相关问题