使用 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/