0

このプログラムのすべては、htmlを除いて機能します。xまたは他のhtmlコードを使用しようとすると、コードはそれをまったくフォーマットしません。何か案は?私は通常、htmlを機能させています。htmlはどちらの文字列配列でも機能しません。2番目の文字列配列の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;

    }

}







}
4

1 に答える 1

0

私のオリジナルよりも良い答え-テキストを設定するときは、これを行います

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

それはあなたのためにスパンナブルを構築します

于 2013-01-20T18:32:44.073 に答える