---前台界面部分


<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="10" >


</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="10" >
</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="10" >
</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;//插入
private Button search;//查找
private EditText et1;//单词
private EditText et2;//解释
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);
//单词的朗读
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,"暂时不支持该语种朗读 !",Toast.LENGTH_LONG).show();
}
}

}
});
//添加单词与解释
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,"请添加生词",Toast.LENGTH_SHORT).show();
}else{
cValues.put("word",str1);
cValues.put("detail",str2);
db.insert("word_scb",null, cValues);
Toast.makeText(MainActivity.this,"添加生词成功",Toast.LENGTH_LONG).show();
}
cValues.clear();
db.close();


}
});

//查找单词与解释
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,"请输入单词或者该单词意思",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();
}
}

}

--非常简单在这里就不一 一解释了,谢谢大家关注

更多相关文章

  1. android 获取路径目录方法以及判断目录是否存在,创建目录
  2. Android(安卓)支持的度量单位
  3. android 获取路径目录方法以及判断目录是否存在,创建目录
  4. 【Android基础】Android开发学习笔记
  5. GestureDetector 和SimpleOnGestureListener的使用和解释
  6. 开发可统计单词个数的Android驱动程序(1)
  7. 开发可统计单词个数的Android驱动程序(1)
  8. Android(安卓)SDCard操作(文件读写,容量计算)
  9. android 获取路径目录方法以及判断目录是否存在,创建目录

随机推荐

  1. Android开发之语音识别
  2. 禁用GPU硬件加速方法
  3. android 使用xmpp smack openfire实现即
  4. android之基于Echart的图表
  5. Android中铃声总结【安卓源码解析一】
  6. Android手动清除APP中Data目录下的文件
  7. Android(安卓)8.0源码编译问题记录
  8. Android(安卓)彩色上下文菜单 Context
  9. Android(安卓)webview ajax session 问题
  10. getSystemService 的参数