我是android新手,我正在使用上下文菜单,我正在尝试获取那些保存在数据库中的EditText值。请帮我下面是我的代码:
title = (TextView) findViewById(R.id.Listname);
Title_Edit = (EditText)findViewById(R.id.title_Edit);
content = (TextView) findViewById(R.id.content);
Content_Edit = (EditText)findViewById(R.id.content_Edit);
duedate = (Button)findViewById(R.id.duedate);
duedatetext = (TextView)findViewById(R.id.duedatetext);
Intent intent2 = getIntent();
int content = intent2.getIntExtra("content", 0);
isEdit = intent2.getBooleanExtra("isEdit", false);
System.out.println(content + "Intent ID");
if(isEdit) {
Database_Notepad db = new Database_Notepad(Add_Task.this);
Cursor c = db.GetNote(content);
db.close();
Title_Edit.setText(c.getString(0));
Content_Edit.setText(c.getString(1));
duedatetext.setText(c.getString(2));
save.setText(getResources().getString(R.string.Updatenote));
上下文菜单项选项:
case R.id.Edit_Note:
Intent intent2 = new Intent(this, Add_Task.class);
Cursor cursor = (Cursor) this.getListAdapter().getItem((int) info.id);
cursor.moveToPosition(itemPosition);
int content = cursor.getInt(0);
intent2.putExtra("content", content );
intent2.putExtra("isEdit", true);
startActivity(intent2);
break;
如果有其他任何方法,我可以获取Edittext值吗请告诉我。感谢。
答案 0 :(得分:0)
如果您的EditText
是您班级的成员,即:
private EditText title = null;
public void onCreate() {
// ...
title = findViewById(R.id.yourId);
}
你应该能够做到:
String titleText = title.getText().toString();