如何在每次单击按钮时创建增量成就[复制]

问题描述 投票:-1回答:1

这个问题在这里已有答案:

所以我的想法是每次我点击我的分享按钮(通过电子邮件等分享内容)我想添加一个成就功能,当我在列表上的每个不同项目上单击共享按钮20次时(来自recyclerview)将弹出一条消息,我想使用Toast表示我已经达到了从共享按钮共享20个内容的成就。

这是我的共享Button方法。我需要为此添加什么?任何人都可以帮忙,我是初学者......谢谢

   //Share Button click
    mShareBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            shareImage();
        }
    });

}

private void shareImage() {
    try {
        //Get title, description, price, category and save in string
        String s = detTitleTv.getText().toString() + "\n" + detDescriptionTv.getText().toString()
                + "\n" + detPriceTv.getText().toString() + "\n" + detCategoryTv.getText().toString()
                + "\n" + detLocationTv.getText().toString();

        File file = new File(getExternalCacheDir(), "sample.png");
        FileOutputStream fOut = new FileOutputStream(file);
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
        fOut.flush();
        fOut.close();
        file.setReadable(true,false);
        //Intent to share image and text
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra(Intent.EXTRA_TEXT, s);//Put the text
        intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
        intent.setType("image/png");
        startActivity(Intent.createChooser(intent,"Share via"));

    } catch (Exception e) {
        Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
    }
}
android onclicklistener android-button
1个回答
-1
投票

活动A无法访问活动B的元素。有两个独立的。

© www.soinside.com 2019 - 2024. All rights reserved.