Android 使用来自另一个Java类的方法

Android 使用来自另一个Java类的方法,android,Android,如何在(NoteEdit java)中使用(Detail java)中的方法speakOut 所以我在菜单搜索后使用它,而不是viewDetails(mDateText)。 这是细节课 public class Detail extends Activity implements TextToSpeech.OnInitListener{ private Button prsstospeak; public String data; private int result=0;

如何在(NoteEdit java)中使用(Detail java)中的方法speakOut 所以我在菜单搜索后使用它,而不是viewDetails(mDateText)。 这是细节课

public class Detail extends Activity implements TextToSpeech.OnInitListener{
    private Button prsstospeak;
public String data;
    private int result=0;
      private TextToSpeech tts;
private TextView passedView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.disp);
         tts = new TextToSpeech(this, this);



        prsstospeak.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View arg0) {
                  speakOut();
                }
            });
          }
    @Override
      public void onDestroy() {
      // Don't forget to shutdown!
      if (tts != null) {
        tts.stop();
        tts.shutdown();
       }
       super.onDestroy();
      }
      //It will called before TTS started
      @Override
      public void onInit(int status) {
      // TODO Auto-generated method stub
      //check status for TTS is initialized or not
      if (status == TextToSpeech.SUCCESS) {
      //if TTS initialized than set language
      result = tts.setLanguage(Locale.US);

      // tts.setPitch(5); // you can set pitch level
      // tts.setSpeechRate(2); //you can set speech speed rate

      //check language is supported or not
      //check language data is available or not
     if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
       Toast.makeText(this, "Missing data", Toast.LENGTH_LONG).show();
       //disable button
       prsstospeak.setEnabled(false);
      } else {

          prsstospeak.setEnabled(true);
       }
      } else {
          Log.e("TTS", "Initilization Failed");
         }
      }

      private void speakOut() {

      if(result!=tts.setLanguage(Locale.US))
      {
      Toast.makeText(getApplicationContext(), "Enter right Words...... ", Toast.LENGTH_LONG).show();
      }else
       {
        //speak given text
        tts.speak(data, TextToSpeech.QUEUE_FLUSH, null);
       }
      }
}
这是NoteEdie:

public class NoteEdit extends Activity {
    public static int numTitle = 1; 
    public static String curDate = "";
    public static String curText = "";  
    private EditText mTitleText;
    private EditText mBodyText;
    private TextView mDateText;
    private Long mRowId;

    private Cursor note;

    private NotesDbAdapter mDbHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mDbHelper = new NotesDbAdapter(this);
        mDbHelper.open();        

        setContentView(R.layout.note_edit);

        setTitle(R.string.app_name);

        mTitleText = (EditText) findViewById(R.id.title);
        mBodyText = (EditText) findViewById(R.id.body);
        mDateText = (TextView) findViewById(R.id.notelist_date);

        long msTime = System.currentTimeMillis();  
        Date curDateTime = new Date(msTime);

        SimpleDateFormat formatter = new SimpleDateFormat("d'/'M'/'y");  
        curDate = formatter.format(curDateTime);        

        mDateText.setText(""+curDate);


        mRowId = (savedInstanceState == null) ? null :
            (Long) savedInstanceState.getSerializable(NotesDbAdapter.KEY_ROWID);
        if (mRowId == null) {
            Bundle extras = getIntent().getExtras();
            mRowId = extras != null ? extras.getLong(NotesDbAdapter.KEY_ROWID)
                                    : null;
        }

        populateFields();

    }

      public static class LineEditText extends EditText{

            public LineEditText(Context context, AttributeSet attrs) {
                super(context, attrs);
                    mRect = new Rect();
                    mPaint = new Paint();
                    mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
                    mPaint.setColor(Color.BLUE);
            }

            private Rect mRect;
            private Paint mPaint;       

            @Override
            protected void onDraw(Canvas canvas) {

                int height = getHeight();
                int line_height = getLineHeight();

                int count = height / line_height;

                if (getLineCount() > count)
                    count = getLineCount();

                Rect r = mRect;
                Paint paint = mPaint;
                int baseline = getLineBounds(0, r);

                for (int i = 0; i < count; i++) {

                    canvas.drawLine(r.left, baseline + 1, r.right, baseline + 1, paint);
                    baseline += getLineHeight();

                super.onDraw(canvas);
            }

        }
      }

      @Override
        protected void onSaveInstanceState(Bundle outState) {
            super.onSaveInstanceState(outState);
            saveState();
            outState.putSerializable(NotesDbAdapter.KEY_ROWID, mRowId);
        }

        @Override
        protected void onPause() {
            super.onPause();
            saveState();
        }

        @Override
        protected void onResume() {
            super.onResume();
            populateFields();
        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.noteedit_menu, menu);
            return true;        
        }

        @Override
        public boolean onOptionsItemSelected(MenuItem item) {

            switch (item.getItemId()) {
            case R.id.menu_about:


                dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {

                       @Override
                       public void onClick(DialogInterface dialog, int which) {
                           dialog.cancel();

                       }
                   });
                   dialog.show();              
                   return true;
            case R.id.menu_delete:
                if(note != null){
                    note.close();
                    note = null;
                }
                if(mRowId != null){
                    mDbHelper.deleteNote(mRowId);
                }
                finish();
                return true;
                //speech button
            case R.id.menu_search:
                viewDetails(mDateText);
                finish();           
                return true;


            case R.id.menu_save:
                saveState();
                finish();           
                return true;
           /* case android.R.id.home:
                finish();  */   
           default:
                return super.onOptionsItemSelected(item);
            }


        }




        private void saveState() {
            String title = mTitleText.getText().toString();
            String body = mBodyText.getText().toString();

            if(mRowId == null){
                long id = mDbHelper.createNote(title, body, curDate);
                if(id > 0){
                    mRowId = id;
                }else{
                    Log.e("saveState","failed to create note");
                }
            }else{
                if(!mDbHelper.updateNote(mRowId, title, body, curDate)){
                    Log.e("saveState","failed to update note");
                }
            }
        }


        private void populateFields() {
            if (mRowId != null) {
                note = mDbHelper.fetchNote(mRowId);
                startManagingCursor(note);
                mTitleText.setText(note.getString(
                        note.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE)));
                mBodyText.setText(note.getString(
                        note.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY)));
                curText = note.getString(
                        note.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY));
            }

        }
public void viewDetails(View view){

String data= mDbHelper.getALLData();



}

}
public类notedit扩展活动{
公共静态int numTitle=1;
公共静态字符串curDate=“”;
公共静态字符串curText=“”;
私有编辑文本mTitleText;
私人编辑文本;
私有文本视图mDateText;
私人长mRowId;
私人光标注释;
私人票据登记簿;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
mDbHelper=新的NotesDbAdapter(本);
mDbHelper.open();
setContentView(R.layout.note\u编辑);
setTitle(R.string.app_name);
mTitleText=(EditText)findViewById(R.id.title);
mBodyText=(EditText)findViewById(R.id.body);
mDateText=(TextView)findViewById(R.id.notelist\u日期);
long msTime=System.currentTimeMillis();
日期curDateTime=新日期(msTime);
SimpleDataFormat格式化程序=新的SimpleDataFormat(“d'/'M'/'y”);
curDate=formatter.format(curDateTime);
mDateText.setText(“+curDate”);
mRowId=(savedInstanceState==null)?null:
(Long)savedInstanceState.getSerializable(NotesDbAdapter.KEY_ROWID);
if(mRowId==null){
Bundle extras=getIntent().getExtras();
mRowId=extras!=null?extras.getLong(NotesDbAdapter.KEY\u ROWID)
:null;
}
populateFields();
}
公共静态类LineEditText扩展了EditText{
公共LineEditText(上下文、属性集属性){
超级(上下文,attrs);
mRect=新的Rect();
mPaint=新油漆();
mPaint.setStyle(绘制、样式、填充和笔划);
mPaint.setColor(Color.BLUE);
}
私人直肠;
私人油漆;
@凌驾
受保护的void onDraw(画布){
int height=getHeight();
int line_height=getLineHeight();
int count=高度/线条高度;
如果(getLineCount()>count)
count=getLineCount();
Rect r=mRect;
油漆油漆=mPaint;
int基线=getLineBounds(0,r);
for(int i=0;i0){
mRowId=id;
}否则{
Log.e(“保存状态”,“无法创建注释”);
}
}否则{
if(!mDbHelper.updateNote(mRowId、title、body、curDate)){
Log.e(“保存状态”,“无法更新注释”);
}
}
}
私有void populateFields(){
if(mRowId!=null){
note=mDbHelper.fetchNote(mRowId);
开始管理光标(注);
mTitleText.setText(note.getString(
note.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE));
mBodyText.setText(note.getString(
note.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY));
curText=note.getString(
注:getColu