Android短信意图问题

发布于 2024-11-19 05:09:32 字数 1276 浏览 6 评论 0原文

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

我使用 CursorSQLite 数据库检索标题和消息。我有一个将被单击的 smsButton 。单击时,它将创建短信意图。

我的问题是邮件正文。我希望正文是从数据库检索的 msg_content 。我试图参考它,但我相信我失败了。

这是我的最后一次尝试,尝试拥有一个 TextView 来获取 msg_content 布局的 id:

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

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

I'm trying to open the System SMS application with a sms body that is taken from a database.

I'm using Cursor to retrieve titles and messages from a SQLite database. I have a smsButton which will be clicked. When clicked, it will create the sms intent.

My problem is with the body of the message. I want the body to be the msg_content which is retrieved from the database. I tried to have a reference to it but I believe I failed.

here is my last attempt, trying to have a TextView that will take the id of the msg_content layout :

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

Any way to reference the string of the content ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

┾廆蒐ゝ 2024-11-26 05:09:32

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

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

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

You are calling findViewById() on an activity... to get data out of database?

You should be using your Cursor to get at your information.

Since you did not bother to provide the actual source code (just a couple of dis-contiguous snippets, AFAICT), it is difficult to give you concrete advice. Taking a random stab at an answer, I would delete smsButton, and instead listen for ListView item clicks (e.g., onListItemClick() if you are implementing a ListActivity), then use the supplied position to move to the right spot in the Cursor and read out the data.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文