---The Foreground interface section
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Xmlns:tools= "Http://schemas.android.com/tools"
Android:id= "@+id/linearlayout1"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:background= "@drawable/beijing"
android:orientation= "Vertical"
Tools:context= ". Mainactivity ">
<edittext
Android:id= "@+id/word"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:hint= "@string/_hint_word"
android:layout_margintop= "25SP"
Android:ems= "Ten" >
</EditText>
<edittext
Android:id= "@+id/jieshi"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:hint= "@string/_jieshi"
android:layout_margintop= "25SP"
Android:ems= "Ten" >
</EditText>
<button
Android:id= "@+id/insert"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:layout_margintop= "25SP"
android:text= "@string/_insert"
Android:textsize= "20SP"
Android:textcolor= "@android: Color/holo_blue_bright"
Android:background= "@android: Color/holo_green_light"
/>
<edittext
Android:id= "@+id/sh"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:hint= "@string/_sh"
android:layout_margintop= "5SP"
Android:ems= "Ten" >
</EditText>
<button
Android:id= "@+id/search"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:layout_margintop= "25SP"
android:text= "@string/_search"
Android:textsize= "20SP"
Android:textcolor= "@android: Color/holo_green_light"
Android:background= "@android: Color/holo_blue_bright"
/>
<textview
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:text= "@string/_yw"
android:gravity= "Center"
Android:textcolor= "@android: Color/holo_orange_dark"
Android:textsize= "25SP"
/>
<textview
Android:id= "@+id/yw"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
Android:text= ""
Android:textsize= "25SP"
android:gravity= "Center"
Android:textcolor= "@android: Color/holo_red_light"
android:layout_margintop= "5SP"
/>
<textview
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:text= "@string/_dcys"
android:gravity= "Center"
Android:textcolor= "@android: Color/holo_purple"
Android:textsize= "25SP"
/>
<textview
Android:id= "@+id/tv"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:layout_margintop= "5SP"
android:gravity= "Center"
Android:textcolor= "@android: Color/holo_red_light"
Android:textsize= "25SP"
/>
</LinearLayout>
-----Mydbhelper
Package com.example.note;
Import Android.content.Context;
Import Android.database.sqlite.SQLiteDatabase;
Import Android.database.sqlite.SQLiteDatabase.CursorFactory;
Import Android.database.sqlite.SQLiteOpenHelper;
public class Mydbhelper extends Sqliteopenhelper {
Public Mydbhelper (Context context, String name, Cursorfactory factory,
int version) {
Super (context, name, Factory, version);
}
@Override
public void OnCreate (Sqlitedatabase db) {
Db.execsql ("CREATE Table WORD_SCB (_id integer primary key autoincrement," +
"Word,detail)");
}
@Override
public void Onupgrade (sqlitedatabase db, int arg1, int arg2) {
}
}
----mainactivity
Package com.example.note;
Import Java.util.Locale;
Import android.app.Activity;
Import android.content.ContentValues;
Import Android.database.Cursor;
Import Android.database.sqlite.SQLiteDatabase;
Import Android.os.Bundle;
Import Android.speech.tts.TextToSpeech;
Import Android.speech.tts.TextToSpeech.OnInitListener;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.widget.Button;
Import Android.widget.EditText;
Import Android.widget.TextView;
Import Android.widget.Toast;
public class Mainactivity extends Activity {
Private TextView Dcys;
Private TextView YWDC;
Private Mydbhelper Mydbhelper;
Private Button insert;//Insert
Private Button search;//Find
Private EditText et1;//Words
Private EditText et2;//Explanation
Private EditText CZ;
Private Texttospeech TTS;
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
Mydbhelper=new Mydbhelper (mainactivity.this, "danci.db", null,3);
Sqlitedatabase db=mydbhelper.getwritabledatabase ();
Db.execsql ("INSERT into WORD_SCB (word,detail) VALUES (' VDS ', ' hh ')");
et1= (EditText) Findviewbyid (R.id.word);
Et2= (EditText) Findviewbyid (R.id.jieshi);
Insert= (Button) Findviewbyid (R.id.insert);
Search= (Button) Findviewbyid (R.id.search);
dcys= (TextView) Findviewbyid (r.id.tv);
Ywdc= (TextView) Findviewbyid (R.ID.YW);
cz= (EditText) Findviewbyid (r.id.sh);
The reading of words
Tts=new Texttospeech (mainactivity.this,new Oninitlistener () {
@Override
public void onInit (int status) {
if (TTS. Success==status) {
int Result=tts.setlanguage (locale.us);
int Lan=tts.setlanguage (Locale.chinese);
if (result!=texttospeech.lang_country_available&&result!=texttospeech.lang_available) {
Toast.maketext (Mainactivity.this, "temporarily does not support this language to read aloud!" ", Toast.length_long). Show ();
}
}
}
});
Add words and explanations
Insert.setonclicklistener (New Onclicklistener () {
@Override
public void OnClick (View v) {
Sqlitedatabase db=mydbhelper.getwritabledatabase ();
Contentvalues cvalues=new contentvalues ();
String Str1=et1.gettext (). toString (). Trim ();
String Str2=et2.gettext (). toString (). Trim ();
if (Str1.length () ==0|str2.length () ==0) {
Toast.maketext (Mainactivity.this, "Please add new words", toast.length_short). Show ();
}else{
Cvalues.put ("word", str1);
Cvalues.put ("detail", str2);
Db.insert ("WORD_SCB", null, cValues);
Toast.maketext (Mainactivity.this, "Add new words Success", Toast.length_long). Show ();
}
Cvalues.clear ();
Db.close ();
}
});
Find words and explanations
Search.setonclicklistener (New Onclicklistener () {
@Override
public void OnClick (View arg0) {
String Key=cz.gettext (). toString (). Trim ();
Sqlitedatabase db=mydbhelper.getreadabledatabase ();
Tts.speak (Cz.gettext (). toString (), texttospeech.queue_add, NULL);
if (Key.length () ==0) {
Toast.maketext (Mainactivity.this, "Please enter the word or the meaning of the word", Toast.length_long). Show ();
}else{
Cursor cursor=db.rawquery ("select * from WORD_SCB where word like '" +key+ "' or detail like '" +key+ "'", null);
while (Cursor.movetonext ()) {
String ws=cursor.getstring (Cursor.getcolumnindex ("word"));
String del=cursor.getstring (Cursor.getcolumnindex ("detail"));
Dcys.settext (DEL);
Ywdc.settext (WS);
}
Db.close ();
}
}
});
}
protected void OnDestroy () {
TODO auto-generated Method Stub
Super.ondestroy ();
if (TTS!=null) {
Tts.stop ();
}
}
}
--very simply not explained here, thank you for your attention
This article is from the "Essays" blog, make sure to keep this source http://lishouxiang.blog.51cto.com/8123559/1749707
The words that Android can pronounce