Android短信意图问题

时间:2011-07-10 11:00:21

标签: android sqlite sms android-listview android-cursor

我正在尝试使用从数据库中获取的短信主体打开系统SMS应用程序。

我正在使用CursorSQLite数据库中检索标题和消息。我点击了smsButton。单击时,它将创建短信意图。

我的问题在于信息的正文。我希望body是从数据库中检索的msg_content。我试图引用它,但我相信我失败了。

这是我的最后一次尝试,尝试使用将采用msg_content布局的id的TextView:

//First: DataBase Retrieving :
//fetch a msg from table `t` with id `id`
Cursor cursor = myDbHelper.fetchMessage(t, id); 
String[] columns = {cursor.getColumnName(1), cursor.getColumnName(2)}; 
int[] columnsLayouts = {R.id.title, R.id.msg_content}; //the columns styles
ca = new SimpleCursorAdapter(this.getBaseContext(), R.layout.msg_items_layout, cursor,columns , columnsLayouts);
lv = (ListView) findViewById(android.R.id.list); 
lv.setAdapter(ca);

//Here is MY PROBLEM :
TextView msgText = (TextView) findViewById(R.id.msg_content); //same Id as the msg_content column above
smsButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            String uri= "smsto:";
            Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse(uri));
            intent.putExtra("sms_body", msgText.getText());
            intent.putExtra("compose_mode", true);
            startActivity(intent);
        }
    });

有什么方法可以引用内容的字符串吗?

1 个答案:

答案 0 :(得分:0)

您正在调用活动上的findViewById() ...以从数据库中获取数据?

您应该使用Cursor来获取您的信息。

由于您没有提供实际的源代码(只是几个不连续的片段,AFAICT),因此很难给出具体的建议。随机抽取一个答案,我会删除smsButton,而是监听ListView项目点击(例如onListItemClick(),如果您正在实施ListActivity),然后使用提供的position移动到Cursor中的正确位置并读出数据。