如何使用上下文菜单获取Edittext数据?

时间:2013-01-09 12:29:42

标签: android android-intent contextmenu android-edittext

我希望通过单击“编辑”使用“上下文菜单”选项获取EditText值。我的代码:

这是我创建的上下文菜单选项,代码:

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 );
                 startActivity(intent2);

                break;

这是我获得意图的地方:

    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);


    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 allcontent = intent2.getIntExtra("Content", 0);

    System.out.println(allcontent + "Intent ID");

    Database_Notepad db = new Database_Notepad(Add_Task.this);

     Cursor c = db.GetNote(allcontent);

     title_Edit.setText(c.getString(0));
     content_Edit.setText(c.getString(1));
     duedatetext.setText(c.getShort(2));

我收到错误:cursorIndexoutofbound

Index 0 requested with a size of 0

1 个答案:

答案 0 :(得分:1)

使用

 int allcontent = intent2.getIntExtra("content", 0);

而不是

 int allcontent = intent2.getIntExtra("Content", 0);

因为您使用content密钥在Intent中发送了值,但尝试使用Content

来获取它
相关问题