2016-09-11 9 views
0

Javaプログラミングの初心者で、計算によって値が色が変わるAndroidでアプリケーションを作成しようとしています。Javaの値に応じて文字列の色を変更します。

public void calculate(View view) { 
    EditText spindleSpeed = (EditText) findViewById(R.id.spindle_speed); 
    String speedString=spindleSpeed.getText().toString(); 
    int speed=Integer.parseInt(speedString);     
    EditText diameter = (EditText) findViewById(R.id.tool_diameter); 
    String diaString=diameter.getText().toString(); 
    int dia=Integer.parseInt(diaString);    
    EditText feedRate = (EditText) findViewById(R.id.feed_rate); 
    String feedString=feedRate.getText().toString(); 
    int feed=Integer.parseInt(feedString);    
    EditText numberOfTeeth = (EditText) findViewById(R.id.number_of_teeth); 
    String teethString=numberOfTeeth.getText().toString(); 
    int teeth=Integer.parseInt(teethString);     
    double feedPerTooth = ((feed*1.0)/(speed*teeth)); 
    double cuttingSpeed = (dia*3.14*speed)/(1000); 
    String FPT = new DecimalFormat("0.00").format(feedPerTooth); 
    String surfaceSpeed = new DecimalFormat("0.00").format(cuttingSpeed); 

このセクションでは私が問題を抱えていますが、値に応じてテキストの色を変更する方法を教えてください。

if (feedPerTooth >0.35){ 
     String attrs = new TextAttributes(Color.BLUE).format(feedPerTooth; 
     FPT.getColor("#FF0000").format(feedPerTooth); 
    } else if (feedPerTooth<0.07){ 
     FPT = "<font color=#FF0000>"; 
    } else ; 

任意のヘルプやガイダンスが理解されるであろう:)

+0

なぜこの質問はjs ??とタグ付けされていますか? –

答えて

0

の色を設定したいと思います0はこれを使用します:textView.setTextColor(Color.parseColor("#F5DC49"));

+0

ありがとう!それは素晴らしい仕事:) –

+0

@AwaisMunawarそれを聞いてうれしい、あなたが受け入れるように私の答えを設定することができます:) – Entea

0

Stringオブジェクトが何色のattibuteを持っていないので、これはあなたの代わりにメソッド#setError

を使用する必要があります

if (feedPerTooth >0.35){ 
     String attrs = new TextAttributes(Color.BLUE).format(feedPerTooth); 

最善の方法ではありません

diameter.setError("feedPerTooth is to high!") 
+0

ありがとうが、私はそれが動作するように感じることはできません。私はちょうど以下のEnteaのメソッドを使用して:) –

関連する問題