我想按下它(长按)可以复制我的滚动视图的内容。
我的scrollview包含一个textview(我从FloatingActionButtonBasic示例中获取代码):
<ViewAnimator
android:id="@+id/log"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="false">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="4dp"
android:typeface="monospace" />
</ScrollView>
<fragment
android:name="com.logger.LogFragment"
android:id="@+id/log_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</ViewAnimator>
如何复制我的整个日志(我不希望每次在scrollview中写入时都保存附加字符串,因为这个函数不会经常使用,仅用于调试目的)?
谢谢!
答案 0 :(得分:1)
为文字视图提供id
标记
<TextView
android:id="@+id/txtId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="4dp"
android:typeface="monospace" />
TextView txtV = (TextView)findViewById(R.id.txtId);
txtV.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
String txt = v.getText()
return false;
}
});
}
将字符串txt保存在您想要的位置。