1

我正在使用 SimpleCursoradapter 填充我在活动中拥有的列表。

现在我需要将此活动的字符串值传递给另一个活动,并且该值将从本地数据库中获取。

我通过在列表视图中创建一个新的文本视图并使用 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);
            }
        });
    }

}
4

2 回答 2

2

我有点匆忙,但这我如何用普通的SimpleCursorAdapter.

内容从数据库中获取并显示在ListActivity. 这也适用于ListViews。

当用户单击列表中的项目时,onClick方法从数据库中获取项目 ID 作为参数。在我的示例中,它会打开一个新的活动,该活动从数据库中查询特定信息。

于 2011-06-28T14:52:22.990 回答
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();
于 2011-06-28T14:44:36.123 回答