2011-06-28 25 views
1

私は、SimpleCursoradapterを使用して、私がアクティビティで持っているリストに値を設定しています。リストからのアクティビティ間の値の受け渡し

このアクティビティのString値を別の値に渡す必要があり、値をローカルデータベースから取得する必要があります。

私はlistviewで新しいtextviewを作成し、SimpleCursorAdapterを使用して文字列値をマッピングすることで同じことをしました。

これは、これを実行するための最良の方法ですか?

public class InboxAdapter extends SimpleCursorAdapter { 

    public InboxAdapter(Context context, int layout, Cursor c, 
      String[] from, int[] to) { 
     super(context, layout, c, from, to); 
    } 

    @Override 
    public void bindView(View view, Context context, Cursor cursor) { 
     super.bindView(view, context, cursor); 

     Button msgReply = (Button) view.findViewById(R.id.msgReply); 
     final TextView msgId = (TextView) view.findViewById(R.id.msgId); 
     msgReply.setOnClickListener(new View.OnClickListener() { 

      private Intent intent; 

      @Override 
      public void onClick(View v) { 
       intent = new Intent(getApplicationContext(), ComposeMessage.class); 
       Bundle b = new Bundle(); 
       b.putCharSequence("id", msgId.getText()); 
       intent.putExtras(b); 
       startActivity(intent); 
      } 
     }); 
    } 

} 
+1

私はそれが最善の方法だと思う、それを渡すntnt.putExtras(String yourString); ' – Houcine

答えて

1

私はこのようにしました。

Bundle bundle = new Bundle(); 
bundle.putString(ClientList.KEY_Client, nameText.getText().toString());//ClientList is another activity 
Intent ok=new Intent(); 
ok.putExtras(bundle); 
setResult(RESULT_OK, ok); 
finish(); 
2

私は少し短い通知でんだけど、thisは、私は通常のSimpleCursorAdapterでこれを行うために管理方法の例です。

コンテンツはデータベースからフェッチされ、ListActivityに表示されます。これはListViewでも動作します。

ユーザーがリスト内のアイテムをクリックすると、onClickメソッドはデータベースからアイテムIDをパラメータとして取得します。私の例では、データベースから特定の情報をクエリする新しいアクティビティを開きます。

関連する問題