2015-11-11 118 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"); 
相關問題