0

Spannbleクラスを使用して で蛍光ペンメカニズムを作成するアプリを作成していますがEditText、これは正常に機能します。ここで、スパン位置を SQLiteDatabase に保存して、それらをリロードし、スパンされたテキストでそれを表示できるようにしTextViewます。

これが私TextViewのハイライターメカニズムです-

package com.Swap.RR;

import android.os.Bundle;

import android.app.Activity;

import android.content.Intent;

import android.graphics.Typeface;

import android.text.Editable;
import android.text.Spannable;
import android.text.TextWatcher;

import android.text.style.BackgroundColorSpan;

import android.view.Menu;
import android.view.View;

import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;

import android.widget.EditText;
import android.widget.ToggleButton;

public class Add_New_Note extends Activity {

private EditText note;
private int mStart;
private Typeface Roboto_lt;
private int end;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add__new__note);

    note = (EditText) findViewById(R.id.notecontent);
    ToggleButton highlighter = (ToggleButton) findViewById(R.id.highlightToggle);
    Roboto_lt = Typeface.createFromAsset(getAssets(), "Roboto-Light.ttf");
    note.setTypeface(Roboto_lt);

    mStart = -1;    
    final TextWatcher highlightWatcher = new TextWatcher() {


       public void beforeTextChanged(CharSequence s, int start, int count, int after) {
       }

       public void onTextChanged(CharSequence s, int start, int before, int count)
    {
        if(mStart > 0)
        {
            end = note.getText().length();
            note.getText().setSpan(new BackgroundColorSpan(getResources().getColor(R.color.highlighter_green)), mStart, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
       public void afterTextChanged(Editable s) {
       }
    };

    highlighter.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        public void onCheckedChanged(CompoundButton button, boolean isChecked) {


            if (isChecked == true) {  
                //start highlighting when the ToggleButton is ON
                if(mStart == -1) mStart = note.getText().length();
                else mStart = -1;
                mStart = note.getText().length();

                note.addTextChangedListener(highlightWatcher);
            } else {
                //stop highlighting when the ToggleButton is OFF
                note.removeTextChangedListener(highlightWatcher);
            }
        }
    });

} 


public void noteDone(View v) {

    String noteContent = note.getText().toString();

    Intent i = new Intent("com.Swap.Notes_page");

    i.putExtra("NOTE", noteContent);

    setResult(RESULT_OK, i);
    finish();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_add__new__note, menu);
    return true;
}
}

それを行う方法についていくつかの提案を手伝ってください。ありがとう!

4

1 に答える 1

1

あなたの最善の策は、を HTMLHtml.toHtml()に変換するために使用することです。後でデータベースにクエリを実行するときに、HTML を に戻すためにSpannable使用できます。ただし、同じ HTML タグをサポートすることが保証されていないため、適切なテストを行う必要があります。Html.fromHtml()SpannabletoHtml()fromHtml()

于 2014-04-14T19:12:30.340 に答える