android - 分享ListView的内容

标签 android share

使用 Android Studio 我在我的 xml 文件中创建了一个 Button,我想分享我的自定义 ListView< 的内容 点击它。 问题是在我点击它之后没有任何反应。我究竟做错了什么?

CustomList.class:

Button btn = (Button)rowView.findViewById(R.id.btn_share);
    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
           Intent intent = new Intent(android.content.Intent.ACTION_SEND);
           intent.setType("text/plain");
           intent.putExtra(Intent.EXTRA_TEXT, txtTitle2.getText().toString());
           intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Share via...");
           startActivity(Intent.createChooser(intent, "Share"));

        }

这是xml:

<Button
    android:id="@+id/btn_share"
    android:layout_width="35dp"
    android:layout_height="35dp"
    android:layout_marginBottom="10dp"
    android:layout_marginLeft="10dp"
    android:background="@android:drawable/ic_menu_share" />

最佳答案

android:onClick="onClick" 添加到您的 XML 中,它应该可以解决问题

如果您想阅读更多内容,请阅读此 Starting Another Activity

关于android - 分享ListView的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20530953/

相关文章:

php - Android JSONPARSER致命异常: AsyncTask

android - 在构建时排除文件夹 Intel XDK

ios - Netflix 使用什么 NSExtensionActivationRule key ?

Android - 通过 Facebook 分享自定义链接

java - Android各版本分享文字图片时出现错误

android - 无法加载 Activity 。 outofMemory 运行时异常

Android EditText 强制数字键盘但允许非数字字符

java - 避免 WorkManager 立即运行?

windows - 您可以从 PowerShell 创建一个匿名访问的 Windows 共享吗?

ios - 设置UIButton共享快速操作图标