0

嗨,在我的应用程序中,我有一个带有列表视图和微调器的片段,我正在使用 cursoradapter 将数据从我的数据库中获取到列表视图中,我想通过电子邮件共享此列表视图数据,我正在我的操作栏上实现 shareintent 操作,但被击中如何将列表视图数据获取到意图选择器中。

下面是我的代码:

 actionBar.addAction(new IntentAction(this, createShareIntent(), R.drawable.ic_title_share_default));

  private Intent createShareIntent() {
        final Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT, "Shared from the ActionBar widget.");
        return Intent.createChooser(intent, "Share");
    }

下面是我的 cursorAdapter

public class bottomlistmonthlyvolume extends CursorAdapter {
    LayoutInflater inflater;
    public bottomlistmonthlyvolume(Context context, Cursor c) {
    super(context, c);
    inflater = LayoutInflater.from(context);
    }

    @Override
    public void bindView(View view, Context context, Cursor topcursor) {
    // TODO Auto-generated method stub
    TextView tv1 = (TextView)view.findViewById(R.id.textView123);
    TextView tv2 = (TextView)view.findViewById(R.id.achievmentValue);
    TextView tv3 = (TextView)view.findViewById(R.id.shortfallValue);
    TextView et1 = (TextView)view.findViewById(R.id.actualvalue);
    TextView et2 = (TextView)view.findViewById(R.id.budgetvalue);

    tv1.setText(topcursor.getString(1));
    tv2.setText(topcursor.getString(7));
    tv3.setText(topcursor.getString(9));
    et1.setText(topcursor.getString(3));
    et2.setText(topcursor.getString(5));

    }
    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {


    return inflater.inflate(R.layout.word_list_item, parent, false);


    }
}

有人可以建议如何实现它

4

1 回答 1

0

我看到了 2 种方法:
1. 向您的SQLiteOpenHelper类添加一个方法(如果您使用它),该方法会直接从数据库返回一个字符串,其中包含您的数据。
2. 在你CursorAdapter的类中定义一个字符串成员,每次调用时bindView将每个列表项数据连接到该字符串。

如果您发布更多代码,我可以更具体。

编辑:所以从你的代码中你想继续方式 2:
假设你的片段中有一个引用,bottomlistmonthlyvolume mAdapter;
在适配器中看到注释

public class bottomlistmonthlyvolume extends CursorAdapter {
    LayoutInflater inflater;
    StringBuilder shareData = new StringBuilder(); // container for shared data

    public bottomlistmonthlyvolume(Context context, Cursor c) {
    super(context, c);
    inflater = LayoutInflater.from(context);
    }

    @Override
    public void bindView(View view, Context context, Cursor topcursor) {
    // TODO Auto-generated method stub
    TextView tv1 = (TextView)view.findViewById(R.id.textView123);
    TextView tv2 = (TextView)view.findViewById(R.id.achievmentValue);
    TextView tv3 = (TextView)view.findViewById(R.id.shortfallValue);
    TextView et1 = (TextView)view.findViewById(R.id.actualvalue);
    TextView et2 = (TextView)view.findViewById(R.id.budgetvalue);

    // Assume we want to share all 'achievmentValue' with a title
    shareData.append("YOUR TITLE").append(topcursor.getString(7)).append("\n");

    tv1.setText(topcursor.getString(1));
    tv2.setText(topcursor.getString(7));
    tv3.setText(topcursor.getString(9));
    et1.setText(topcursor.getString(3));
    et2.setText(topcursor.getString(5));

    }
    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {


    return inflater.inflate(R.layout.word_list_item, parent, false);


    }

    public String getShareData(){
        return shareData.toString();
    }
}

在操作栏中:

actionBar.addAction(new IntentAction(this, createShareIntent(), R.drawable.ic_title_share_default));

  private Intent createShareIntent() {
        final Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT, mAdapter.getShareData());
        return Intent.createChooser(intent, "Share");
    }
于 2013-10-08T09:03:47.273 回答