Hi guys ,
I am able to get the position where the text has got selected ,but how can I
get the selected text value so that I can change the font style and replace
the text at concerned position.
 I was using Typecase to change the font style.

Please can you help me
My code is as follows:
package com.pradeep.texteditor;



import java.util.ArrayList;






import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.Editable;
import android.text.Spannable;
import android.text.style.StyleSpan;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public  class TextEditor extends Activity {
    private static final String TAG = "pradeep";



    String text;
    String txt;
    private EditText mUserText;
    private EditText waitingTimeView;

    private ArrayAdapter<String> mAdapter;

    private ArrayList<String> mStrings = new ArrayList<String>();

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mUserText = (EditText) findViewById(R.id.enterText);
        mUserText.setTextColor(Color.BLACK);


        Button bold = (Button) findViewById(R.id.Button02);
        bold.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                  mUserText.setTextColor(Color.RED);
                  //txt1 =
mUserText.setTypeface(Typeface.SERIF,Typeface.BOLD);
                   int start = mUserText.getSelectionStart();
                    int end = mUserText.getSelectionEnd();
                    //TextView myTextView = new  TextView(this);
                  //String selectedText =
mUserText.getText().toString().substring(start, end);
//                     txt1=
mUserText.setTypeface(Typeface.SERIF,Typeface.BOLD);


                    Editable txt = mUserText.getText();



                //       Editable a = mUserText.getText() ;
                //    //        a.append(txt, start, end);
//                    Editable txt1 = mUserText.getText().s

                //    txt.replace(start,end,a);

                 // String selectedText =
et.getText().substring(startSelection, endSelection);

//                  int selStart = ((EditText) v).getSelectionStart();
//                    int end = ((EditText) v).getSelectionEnd();
                    // Determine the word "under" selStart...

                  //char a = txt.charAt(end);



                    Log.d(TAG, "sel:" + String.valueOf(start)+" end:"+
String.valueOf(end));







                 // int selStart = ((EditText) v).getSelectionStart();
                    //int end = ((EditText) v).getSelectionEnd();
                     //Determine the word "under" selStart...
                    //Log.d(TAG, "sel:" + String.valueOf(selStart) + "
end:"+ String.valueOf(end));

                    //Typeface myTypeface =
Typeface.createFromAsset(this.getAssets(),"DS-DIGIB.TTF");
                    Typeface myTypeface = Typeface.DEFAULT_BOLD;
                    waitingTimeView = (EditText)
findViewById(R.id.enterText);
                    waitingTimeView.setTypeface(myTypeface);
                    mUserText.setBackgroundColor(Color.GREEN);

            }



        });


    }

    private void sendText() {
        text = mUserText.getText().toString();

       mAdapter.add(text);

       mUserText.setText(null);
   }

   public boolean onKey(View v, int keyCode, KeyEvent event) {

       if (event.getAction() == KeyEvent.ACTION_DOWN) {

           switch (keyCode) {
               case KeyEvent.KEYCODE_DPAD_CENTER:
               case KeyEvent.KEYCODE_ENTER:
                  sendText();
                   return true;
           }
       }
       return false;
   }






}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to