2011-07-10 7 views
0

システムSMSアプリケーションをデータベースから取得したSMS本体で開こうとしています。Android 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); 
     } 
    }); 

コンテンツの文字列を参照するための任意の方法は?

答えて

0

アクティビティでfindViewById()を呼び出しています...データベースからデータを取得するには?

お客様の情報を入手するには、Cursorを使用する必要があります。

実際のソースコード(不連続なスニペットの一部(AFAICT))を提供するのは面倒なので、具体的なアドバイスをするのは難しいです。答えにランダムな刺し傷を付けて、を削除し、代わりにListView個のアイテムのクリックを聞きます(ListActivityを実装する場合はonListItemClick())。付属のpositionを使用してCursorの正しい場所に移動し、データ。