/**
* 源码片段
*/
package wordroid.activitys;
import java.util.ArrayList;
import wordroid.database.DataAccess;
import wordroid.model.R;
import wordroid.model.Word;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
/**
* @author Administrator
*
*/
public class EditWord extends Activity implements OnClickListener{
private String action;
private EditText spelling;
private EditText meanning;
private Button confirm;
private Button cancel;
private Word word;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.setTitle("编辑生词本");
this.setContentView(R.layout.editword);
Bundle bundle = this.getIntent().getExtras();
action = bundle.getString("action");
initWidgets();
}
private void initWidgets() {
// TODO Auto-generated method stub
this.spelling = (EditText) this.findViewById(R.id.EditWord_spelling);
this.cancel = (Button) this.findViewById(R.id.attention_cancel_button);
this.confirm = (Button) this.findViewById(R.id.attention_confirm_button);
this.meanning = (EditText) this.findViewById(R.id.EditWord_meanning);
cancel.setOnClickListener(this);
confirm.setOnClickListener(this);
if (action.equals("edit")){
Bundle bundle = this.getIntent().getExtras();
DataAccess data = new DataAccess(this);
Word word =data.QueryAttention("ID ='"+bundle.getString("id")+"'", null).get(0);
spelling.setText(word.getSpelling());
meanning.setText(word.getMeanning());
}
}
@SuppressWarnings("unused")
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (v==cancel){
finish();
}
if (v==confirm){
if (meanning.getText().toString().equals("")||spelling.getText().toString().equals("")){
Toast.makeText(EditWord.this, "信息不能为空", Toast.LENGTH_SHORT).show();
return;
}
if (action.equals("add")){
boolean add =true;
final DataAccess data = new DataAccess(this);
ArrayList
for(int i=0;i