2013-01-20 34 views
0

本程序中的所有內容除html外都適用。當我嘗試使用x或任何其他html代碼時,代碼根本不會格式化它。有任何想法嗎?我通常得到的HTML工作。該html不適用於任何字符串數組。我知道我還沒有定義第二個字符串數組的html。它只是不工作的第一個字符串數組,我認爲會工作。eclipse中的html問題,android

package wompa.pro; 

import java.util.Random; 
import android.app.Activity; 
import android.os.Bundle; 
import android.text.Html; 
import android.text.SpannableStringBuilder; 
import android.text.Spanned; 
import android.text.style.StyleSpan; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.view.animation.AccelerateInterpolator; 
import android.view.animation.Animation; 
import android.view.animation.TranslateAnimation; 
import android.widget.Button; 
import android.widget.TextView; 
import android.widget.ViewFlipper; 

public class Flashcard extends Activity implements OnClickListener{ 

    View.OnTouchListener gestureListener; 
    ViewFlipper flipper; 
    String facts[] = { 
//Calculus 

"Product Rule: d/dx(fg)=", 
"Quotient Rule: d/dx(f/g)=", 
"(d/dx)c=", 
"(d/dx)cx=", 
"(d/dx)x<sup>n</sup>=", 
"(d/dx)e<sup>x</sup>=", 
"(d/dx)ln(x)=", 
"(d/dx)a<sup>x</sup>=", 
"(d/dx)log<sub>a</sup>x=", 
"(d/dx)sin(x)", 
"(d/dx)cos(x)", 
"(d/dx)tan(x)", 
"(d/dx)csc(x)", 
"(d/dx)sec(x)", 
"(d/dx)cot(x)", 
"d/dx(arcsin(x))", 
"d/dx(arccos(x))", 
"d/dx(arctan(x))", 
"d/dx(arccsc(x))", 
"d/dx(arcsec(x))", 
"d/dx(arccot(x))", 
}; 

    String answers[] = { 
//Biology ch. 9 

"f'g+fg'", 
"(f'g-fg')/g<sup>2</sup>", 
"0", 
"c", 
"nx<sup>n-1</sup>", 
"e<sup>x</sup>", 
"1/x", 
"a<sup>x</sup>lna", 
"(1/x)(1/lna)", 
"cos(x)", 
"-sin(x)", 
"sec<sup>2</sup>x", 
"-cscxcotx", 
"secxtanx", 
"-csc<sup>2</sup>", 
"1/(1-x<sup>2</sup>)<sup>1/2</sup>", 
"-1/(1-x<sup>2</sup>)<sup>1/2</sup>", 
"1/(1+x<sup>2</sup>)", 
"-1/(1+x<sup>2</sup>)", 
"1/(|x|(x<sup>2</sup>-1)<sup>1/2</sup>)", 
"-1/(|x|(x<sup>2</sup>-1)<sup>1/2</sup>)", 
}; 


private Animation inFromRightAnimation() { 

Animation inFromRight = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, +1.0f, Animation.RELATIVE_TO_PARENT, 0.0f, 
Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f 
); 
inFromRight.setDuration(500); 
inFromRight.setInterpolator(new AccelerateInterpolator()); 
return inFromRight; 
} 
private Animation outToLeftAnimation() { 
Animation outtoLeft = new TranslateAnimation(
    Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, -1.0f, 
    Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f 
); 
outtoLeft.setDuration(500); 
outtoLeft.setInterpolator(new AccelerateInterpolator()); 
return outtoLeft; 
} 

private Animation inFromLeftAnimation() { 
Animation inFromLeft = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, -1.0f, Animation.RELATIVE_TO_PARENT, 0.0f, 
Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f 
); 
inFromLeft.setDuration(500); 
inFromLeft.setInterpolator(new AccelerateInterpolator()); 
return inFromLeft; 
} 
private Animation outToRightAnimation() { 
Animation outtoRight = new TranslateAnimation(
    Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, +1.0f, 
    Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f 
); 
outtoRight.setDuration(500); 
outtoRight.setInterpolator(new AccelerateInterpolator()); 
return outtoRight; 
} 

TextView display, display1; 
TextView counter; 
Button begin; 
Button next; 
Button previous; 
Button random; 
Random myRandom; 
TextView tvResults; 

int index = facts.length; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.main); 

flipper = (ViewFlipper) findViewById(R.id.flipper); 
Button button1 = (Button) findViewById(R.id.Button01); 
Button button2 = (Button) findViewById(R.id.Button02); 
TextView t = (TextView)findViewById(R.id.tvResults); 

button1.setOnClickListener(new View.OnClickListener() { 
    public void onClick(View view) { 
     flipper.setInAnimation(inFromRightAnimation()); 
     flipper.setOutAnimation(outToLeftAnimation()); 
     flipper.showNext();    
    } 
}); 

button2.setOnClickListener(new View.OnClickListener() { 
    public void onClick(View view) { 
     flipper.setInAnimation(inFromLeftAnimation()); 
     flipper.setOutAnimation(outToRightAnimation()); 
     flipper.showPrevious();  
    } 
}); 

display = (TextView) findViewById(wompa.pro.R.id.tvResults); 
display1 = (TextView) findViewById(wompa.pro.R.id.tvAnswers); 
    counter = (TextView) findViewById(wompa.pro.R.id.tvCounter); 

    next = (Button) findViewById(wompa.pro.R.id.Next); 
    previous = (Button) findViewById(wompa.pro.R.id.Previous); 
    random = (Button) findViewById(wompa.pro.R.id.Random); 

    next.setOnClickListener(this); 
    previous.setOnClickListener(this); 
    random.setOnClickListener(this); 

    myRandom = new Random(); 
    index++; 
    if (index > facts.length - 1) { 
     index = 0; 
    } 
    showDisplay();} 

private void showDisplay() { 
    Spanned span = Html.fromHtml(facts[index]); 
    SpannableStringBuilder builder = new SpannableStringBuilder(span); 
    int start = builder.nextSpanTransition(0, builder.length(), StyleSpan.class); 
    int stop = builder.nextSpanTransition(start, builder.length(), StyleSpan.class); 
    builder.setSpan(span, start, stop, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); 
    display.setText(facts[index]); 
    display1.setText(answers[index]); 
    counter.setText(String.valueOf(index + 1) + "/" 
      + String.valueOf(facts.length)); 
} 

public void onClick(View arg0) { 
    // TODO Auto-generated method stub 
    switch (arg0.getId()) { 
    case wompa.pro.R.id.Next: 
     index++; 
     if (index > facts.length - 1) { 
      index = 0; 
     } 
     showDisplay(); 

     break; 

    case wompa.pro.R.id.Previous: 
     index--; 
     if (index < 0) { 
      index = facts.length - 1; 
     } 
     showDisplay(); 
     break; 

    case wompa.pro.R.id.Random: 
     index = (myRandom.nextInt(facts.length) - 1); 
     if (index < 0) { 
      index = facts.length - 1; 
     } 
     showDisplay(); 
     break; 

    } 

} 







} 

回答

0

更好的答案比你設定的文字我original-,做到這一點

display.setText(Html.fromHtml(string)); 

,將建立的spannables你

+0

好感謝您的幫助,我發現這個問題顯示。的setText(助洗劑);我離開了它,現在它工作。 – jacobohunter