【问题标题】:Problems with html in eclipse, androideclipse、android中的html问题
【发布时间】:2013-01-20 18:28:47
【问题描述】:

该程序中的所有内容都可以正常工作,除了 html。当我尝试使用 x 或任何其他 html 代码时,代码根本不会对其进行格式化。有任何想法吗?我通常让 html 工作。 html 不适用于任一字符串数组。我知道我还没有为第二个字符串数组定义 html。它只是不适用于我认为可行的第一个字符串数组。

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;

    }

}







}

【问题讨论】:

    标签: java android html eclipse


    【解决方案1】:

    比我原来的答案更好 - 当你设置文本时,这样做

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

    这将为您构建跨度对象

    【讨论】:

    • 好的,感谢您的帮助,我找到了问题 display.setText(builder);我把它留了下来,现在它可以工作了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-24
    • 2014-10-13
    • 2012-07-11
    • 1970-01-01
    • 2012-01-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多