0

データベースから取得したSMS本体を使用してシステムSMSアプリケーションを開こうとしています。

Cursorデータベースからタイトルとメッセージを取得するために使用していSQLiteます。smsButtonクリックされるものがあります。クリックすると、SMSインテントが作成されます。

私の問題はメッセージの本文にあります。本体をデータベースから取得した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);
        }
    });

コンテンツの文字列を参照する方法はありますか?

4

1 に答える 1

0

findViewById()データベースからデータを取得するためのアクティビティを要求していますか?

あなたはあなたの情報を得るためにあなたを使うべきですCursor

実際のソースコード(いくつかの不連続なスニペット、AFAICT)をわざわざ提供しなかったため、具体的なアドバイスを提供することは困難です。答えをランダムに突き刺して、削除smsButtonし、代わりにListViewアイテムのクリックをリッスンし(たとえば、onListItemClick()を実装している場合ListActivity)、提供されたものを使用positionしての適切な場所に移動しCursor、データを読み取ります。

于 2011-07-10T12:10:03.533 に答える