EditText e1;
Button b1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
e1 = (EditText) findViewById(R.id.editText);
b1 = (Button) findViewById(R.id.button);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) { copyMethod(); }
});
Runnable myRunnable = new Runnable() {
@Override
public void run() {
while (true) {
try { Thread.sleep(1000); }
catch (InterruptedException e) { e.printStackTrace(); }
Runnable newRunnable = new Runnable() {
@Override
public void run() { copyMethod(); }
};
}
}
};
Thread myThread = new Thread(myRunnable);
myThread.start();
}
public void copyText(View view) { copyMethod(); }
public void copyMethod()
{
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Copied Text", (CharSequence) e1.getText().toString());
if (clipboard != null) { clipboard.setPrimaryClip(clip); }
e1.setText("");
}
@Override
public void onClick(View view) { copyMethod(); } }
XML:
<?xml version="1.0" encoding="utf-8"?>
<android.widget.RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.quickclip.panky.quickclip.MainActivity">
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:ems="100"
android:inputType="textAutoCorrect" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText"
android:layout_centerHorizontal="true"
android:onClick="copyText"
android:text="Copy" />
</android.widget.RelativeLayout>
logcat:
01-31 20:58:49.951 11883-11883/com.quickclip.panky.quickclip I/art: Late-enabling -Xcheck:jni
01-31 20:58:50.262 11883-11883/com.quickclip.panky.quickclip W/System: ClassLoader referenced unknown path: /data/app/com.quickclip.panky.quickclip-1/lib/arm64
01-31 20:58:50.264 11883-11883/com.quickclip.panky.quickclip D/ActivityThread: installProvider: context.getPackageName()=com.quickclip.panky.quickclip
01-31 20:58:50.267 11883-11883/com.quickclip.panky.quickclip I/InstantRun: starting instant run server: is main process
01-31 20:58:50.398 11883-11883/com.quickclip.panky.quickclip W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
01-31 20:58:50.447 11883-11883/com.quickclip.panky.quickclip D/PhoneWindow: DEBUG_SYSTEMUI:origin statusbar style
01-31 20:58:50.447 11883-11883/com.quickclip.panky.quickclip D/PhoneWindow: DEBUG_SYSTEMUI:windowDrawsFlag set
01-31 20:58:50.447 11883-11883/com.quickclip.panky.quickclip D/PhoneWindow: DEBUG_SYSTEMUI:IconColor=1
01-31 20:58:50.447 11883-11883/com.quickclip.panky.quickclip D/PhoneWindow: DEBUG_SYSTEMUI:StatusBarColor final set ff303f9f
01-31 20:58:50.631 11883-11883/com.quickclip.panky.quickclip V/PhoneWindow: DecorView setVisiblity: visibility = 4 ,Parent =null, this =com.android.internal.policy.PhoneWindow$DecorView{19bf69f I.E...... R.....ID 0,0-0,0}
01-31 20:58:50.637 11883-11883/com.quickclip.panky.quickclip D/WindowClient: Add to mViews: com.android.internal.policy.PhoneWindow$DecorView{19bf69f I.E...... R.....ID 0,0-0,0}, this = android.view.WindowManagerGlobal@143e3bd
01-31 20:58:50.638 11883-11883/com.quickclip.panky.quickclip D/OpenGLRenderer: Dumper init 4 threads <0x7fa0c7f5c0>
01-31 20:58:50.638 11883-11883/com.quickclip.panky.quickclip D/OpenGLRenderer: <com.quickclip.panky.quickclip> is running.
01-31 20:58:50.640 11883-11902/com.quickclip.panky.quickclip D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
01-31 20:58:50.641 11883-11902/com.quickclip.panky.quickclip D/OpenGLRenderer: CanvasContext() 0x7fa3a46000
01-31 20:58:50.644 11883-11883/com.quickclip.panky.quickclip D/ViewRootImpl: hardware acceleration is enabled, this = ViewRoot{a79bdb2 com.quickclip.panky.quickclip/com.quickclip.panky.quickclip.MainActivity,ident = 0}
01-31 20:58:50.648 11883-11883/com.quickclip.panky.quickclip V/PhoneWindow: DecorView setVisiblity: visibility = 0 ,Parent =ViewRoot{a79bdb2 com.quickclip.panky.quickclip/com.quickclip.panky.quickclip.MainActivity,ident = 0}, this =com.android.internal.policy.PhoneWindow$DecorView{19bf69f V.E...... R.....ID 0,0-0,0}
01-31 20:58:50.690 11883-11902/com.quickclip.panky.quickclip D/OpenGLRenderer: CanvasContext() 0x7fa3a46000 initialize window=0x7fac9df010, title=com.quickclip.panky.quickclip/com.quickclip.panky.quickclip.MainActivity
01-31 20:58:50.690 11883-11883/com.quickclip.panky.quickclip D/Surface: Surface::allocateBuffers(this=0x7fac9df000)
01-31 20:58:50.696 11883-11902/com.quickclip.panky.quickclip I/OpenGLRenderer: Initialized EGL, version 1.4
01-31 20:58:50.699 11883-11902/com.quickclip.panky.quickclip D/MALI: gles_context_new:265: [MTK] sufficient memory..
01-31 20:58:50.699 11883-11902/com.quickclip.panky.quickclip D/OpenGLRenderer: Created EGL context (0x7fa4672f80)
01-31 20:58:50.701 11883-11902/com.quickclip.panky.quickclip I/OpenGLRenderer: Get enable program binary service property (1)
01-31 20:58:50.701 11883-11902/com.quickclip.panky.quickclip I/OpenGLRenderer: Initializing program atlas...
01-31 20:58:50.702 11883-11902/com.quickclip.panky.quickclip D/ProgramBinary/Service: BpProgramBinaryService.getFileDescriptor
01-31 20:58:50.703 11883-11902/com.quickclip.panky.quickclip D/ProgramBinary/Service: BpProgramBinaryService.getProgramMapLen
01-31 20:58:50.703 11883-11902/com.quickclip.panky.quickclip D/ProgramBinary/Service: BpProgramBinaryService.getProgramMapArray
01-31 20:58:50.703 11883-11902/com.quickclip.panky.quickclip D/ProgramBinary/Service: BpProgramBinaryService.getProgramBinaryLen
01-31 20:58:50.704 11883-11902/com.quickclip.panky.quickclip I/OpenGLRenderer: Program binary detail: Binary length is 173520, program map length is 152.
01-31 20:58:50.704 11883-11902/com.quickclip.panky.quickclip I/OpenGLRenderer: Succeeded to mmap program binaries. File descriptor is 47, and path is /dev/ashmem.
01-31 20:58:50.704 11883-11902/com.quickclip.panky.quickclip I/OpenGLRenderer: No need to use file discriptor anymore, close fd(47).
01-31 20:58:50.704 11883-11902/com.quickclip.panky.quickclip D/OpenGLRenderer: Initializing program cache from 0x7fb1123bc8, size = 6
01-31 20:58:50.707 11883-11902/com.quickclip.panky.quickclip D/OpenGLRenderer: -- init (key = 0x0000000000000000)
01-31 20:58:50.707 11883-11902/com.quickclip.panky.quickclip D/OpenGLRenderer: -- not init (key = 0x0000000000500040)
01-31 20:58:50.708 11883-11902/com.quickclip.panky.quickclip D/OpenGLRenderer: -- init (key = 0x0000000000500041)
01-31 20:58:50.710 11883-11902/com.quickclip.panky.quickclip D/OpenGLRenderer: -- init (key = 0x0000000800000003)
01-31 20:58:50.711 11883-11902/com.quickclip.panky.quickclip D/OpenGLRenderer: -- init (key = 0x0000001000500040)
01-31 20:58:50.713 11883-11902/com.quickclip.panky.quickclip D/OpenGLRenderer: -- init (key = 0x0000003800000000)
01-31 20:58:50.713 11883-11902/com.quickclip.panky.quickclip D/Surface: Surface::connect(this=0x7fac9df000,api=1)
01-31 20:58:50.714 11883-11902/com.quickclip.panky.quickclip W/libEGL: [ANDROID_RECORDABLE] format: 1
01-31 20:58:50.715 11883-11902/com.quickclip.panky.quickclip D/mali_winsys: new_window_surface returns 0x3000
01-31 20:58:50.747 11883-11883/com.quickclip.panky.quickclip W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
01-31 20:58:50.779 11883-11902/com.quickclip.panky.quickclip D/OpenGLRenderer: CacheTexture 2 upload: x, y, width height = 0, 0, 97, 148
01-31 20:58:50.786 11883-11902/com.quickclip.panky.quickclip I/[MALI][Gralloc]: [+]r_hnd(0x7fa4675440), client(51), share_fd(49)
01-31 20:58:50.786 11883-11902/com.quickclip.panky.quickclip D/GraphicBuffer: register, handle(0x7fa4675440) (w:720 h:1280 s:720 f:0x1 u:0x000b00)
01-31 20:58:50.790 11883-11902/com.quickclip.panky.quickclip D/OpenGLRenderer: ProgramCache save to disk, size = 6
01-31 20:58:50.801 11883-11902/com.quickclip.panky.quickclip I/[MALI][Gralloc]: [+]r_hnd(0x7fa4675120), client(51), share_fd(53)
01-31 20:58:50.801 11883-11902/com.quickclip.panky.quickclip D/GraphicBuffer: register, handle(0x7fa4675120) (w:720 h:1280 s:720 f:0x1 u:0x000b00)
01-31 20:58:50.805 11883-11883/com.quickclip.panky.quickclip V/InputMethodManager: onWindowFocus: android.support.v7.widget.AppCompatEditText{23f6523 VFED..CL. .F....ID 0,60-720,151 #7f070030 app:id/editText} softInputMode=288 first=true flags=#81810100
01-31 20:58:50.806 11883-11893/com.quickclip.panky.quickclip I/System: FinalizerDaemon: finalize objects = 1
01-31 20:58:50.808 11883-11883/com.quickclip.panky.quickclip V/InputMethodManager: START INPUT: android.support.v7.widget.AppCompatEditText{23f6523 VFED..CL. .F....ID 0,60-720,151 #7f070030 app:id/editText} ic=com.android.internal.widget.EditableInputConnection@b1db6e0 tba=android.view.inputmethod.EditorInfo@a9f4d99 controlFlags=#107
01-31 20:58:50.825 11883-11902/com.quickclip.panky.quickclip I/[MALI][Gralloc]: [+]r_hnd(0x7fa46754e0), client(51), share_fd(56)
01-31 20:58:50.825 11883-11902/com.quickclip.panky.quickclip D/GraphicBuffer: register, handle(0x7fa46754e0) (w:720 h:1280 s:720 f:0x1 u:0x000b00)
01-31 20:59:20.710 11883-11883/com.quickclip.panky.quickclip D/TextView: touchFinish handled:true --- mShowToolbar=true
01-31 20:59:22.042 11883-11902/com.quickclip.panky.quickclip D/OpenGLRenderer: CacheTexture 2 upload: x, y, width height = 0, 147, 18, 29
01-31 20:59:22.340 11883-11902/com.quickclip.panky.quickclip D/OpenGLRenderer: CacheTexture 2 upload: x, y, width height = 0, 175, 20, 23
01-31 20:59:23.804 11883-11902/com.quickclip.panky.quickclip D/OpenGLRenderer: CacheTexture 2 upload: x, y, width height = 0, 197, 19, 30
01-31 20:59:24.070 11883-11902/com.quickclip.panky.quickclip D/OpenGLRenderer: CacheTexture 2 upload: x, y, width height = 64, 62, 6, 29
01-31 20:59:24.514 11883-11902/com.quickclip.panky.quickclip D/OpenGLRenderer: CacheTexture 2 upload: x, y, width height = 0, 226, 19, 23
01-31 20:59:33.248 11883-11883/com.quickclip.panky.quickclip I/View: Key down dispatch to android.support.v7.widget.AppCompatEditText{23f6523 VFED..CL. .F...... 0,60-720,151 #7f070030 app:id/editText}, event = KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_ENTER, scanCode=0, metaState=0, flags=0x16, repeatCount=0, eventTime=44923912, downTime=44923912, deviceId=-1, source=0x0 }
01-31 20:59:33.252 11883-11883/com.quickclip.panky.quickclip V/ViewRootImpl: [ANR Warning]Input routeing takes more than 6000ms since 1970-01-01 05:30:00.000, this = ViewRoot{a79bdb2 com.quickclip.panky.quickclip/com.quickclip.panky.quickclip.MainActivity,ident = 0}
01-31 20:59:33.252 11883-11883/com.quickclip.panky.quickclip V/ViewRootImpl: Input event delivered to android.view.ViewRootImpl$EarlyPostImeInputStage@76d1217 at 2018-01-31 20:59:33.244
01-31 20:59:33.253 11883-11883/com.quickclip.panky.quickclip V/ViewRootImpl: Input event delivered to android.view.ViewRootImpl$NativePostImeInputStage@9bde604 at 2018-01-31 20:59:33.245
01-31 20:59:33.253 11883-11883/com.quickclip.panky.quickclip V/ViewRootImpl: Input event delivered to android.view.ViewRootImpl$ViewPostImeInputStage@d0857ed at 2018-01-31 20:59:33.245
01-31 20:59:33.253 11883-11883/com.quickclip.panky.quickclip V/ViewRootImpl: Input event delivered to android.view.ViewRootImpl$SyntheticInputStage@5a5d622 at 2018-01-31 20:59:33.250
01-31 20:59:33.255 11883-11883/com.quickclip.panky.quickclip I/View: Key up dispatch to android.support.v7.widget.AppCompatEditText{23f6523 VFED..CL. .F...... 0,60-720,151 #7f070030 app:id/editText}, event = KeyEvent { action=ACTION_UP, keyCode=KEYCODE_ENTER, scanCode=0, metaState=0, flags=0x16, repeatCount=0, eventTime=44923912, downTime=44923912, deviceId=-1, source=0x0 }
01-31 20:59:33.267 11883-11883/com.quickclip.panky.quickclip V/ViewRootImpl: [ANR Warning]Input routeing takes more than 6000ms since 1970-01-01 05:30:00.000, this = ViewRoot{a79bdb2 com.quickclip.panky.quickclip/com.quickclip.panky.quickclip.MainActivity,ident = 0}
01-31 20:59:33.267 11883-11883/com.quickclip.panky.quickclip V/ViewRootImpl: Input event delivered to android.view.ViewRootImpl$EarlyPostImeInputStage@76d1217 at 2018-01-31 20:59:33.253
01-31 20:59:33.267 11883-11883/com.quickclip.panky.quickclip V/ViewRootImpl: Input event delivered to android.view.ViewRootImpl$NativePostImeInputStage@9bde604 at 2018-01-31 20:59:33.254
01-31 20:59:33.268 11883-11883/com.quickclip.panky.quickclip V/ViewRootImpl: Input event delivered to android.view.ViewRootImpl$ViewPostImeInputStage@d0857ed at 2018-01-31 20:59:33.254
01-31 20:59:33.268 11883-11883/com.quickclip.panky.quickclip V/ViewRootImpl: Input event delivered to android.view.ViewRootImpl$SyntheticInputStage@5a5d622 at 2018-01-31 20:59:33.266
01-31 20:59:33.268 11883-11883/com.quickclip.panky.quickclip E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
01-31 20:59:33.270 11883-11883/com.quickclip.panky.quickclip E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
您应该从主线程访问任何UI组件,其中
如果您的活动
Activity activity = this;
所以修改后的Runnable应该如下所示。
Runnable myRunnable = new Runnable() {
@Override
public void run() {
while (true) {
try { Thread.sleep(1000); }
catch (InterruptedException e) { e.printStackTrace(); }
activity.runOnUiThread(new Runnable() {
public void run() {
copyMethod();
}
});
}
}
};
问题内容: 我已经为此奋斗了2天,尽我所能用Google搜索和stackoverflow,但是我无法解决。 我正在构建一个简单的节点应用程序(+ Express + Mongoose),其登录页面重定向到主页。这是我的服务器JS代码: 登录页面向发出POST请求,在此验证发布的数据。这可行。我可以在Node控制台中看到“我们在这里:’/ credentials’”。 然后是问题:res.redir
问题内容: 当使用带点名的名称时,例如:,返回的模块不是,返回的内容几乎都是空的!这里发生了什么? 问题答案: 从python文档上: … 当name变量的形式为package.module时,通常返回顶级包(名称直到第一个点),而不是按名称命名的模块。但是,当给出非空的fromlist参数时,将返回按名称命名的模块。这样做是为了与为不同种类的import语句生成的字节码兼容。使用“ import
问题内容: 根据JavaDoc for ,该函数在比较期间不考虑比例。 现在,我有一个测试用例,看起来像这样: 我希望函数返回的值是10,小数位数为10。打印该值可显示预期的结果。但是该功能似乎并未按照我认为的方式工作。 这里发生了什么? 问题答案: 并 没有 代表0.7。 它代表0.69999999999999999999555910790149937383830547332763671875(
问题内容: 我是否错过了明显痛苦的事情?还是世界上没有人真正使用java.util.BitSet? 以下测试失败: 我真的不清楚,为什么我没有得到长度为2的BitSet和值为10的结果。我偷看了java.util.BitSet的源代码,并且在随意检查时似乎无法对两者进行足够的区分。设置为false且从未设置为任何值… (请注意,在构造函数中显式设置BitSet的大小无效,例如: 问题答案: 人们确
问题内容: 以下Dockerfile: 具有输出: 构建时(docker build命令) 看来RUN cd tmp123没有任何作用 为什么呢? 问题答案: 实际上是预期的。 泊坞窗文件不过是docker run + docker commit的包装器。 与做相同的事情: 每次运行时,都会生成一个新容器,因此pwd为’/’。 如果您愿意,可以在github上打开一个问题,以便向Dockerfil
我试着将一个双精度值四舍五入到小数点后两位: var x=0.68999995 var roundX=round(x*100.0)/100.0 println(roundX)//打印0.69 如果打印值是正确的...但var值不是我期望的,继续0.68999999999999995 我需要双值...不像其他StackOverflow答案那样字符串:(
问题内容: 我将 Jasmine 和 Karma 一起使用,以测试基于 Angular 构建的应用程序。 我必须测试加载用户数据的服务,并且使用 $ httpBackend 模拟响应。但是,当我运行测试时,出现两个错误: 错误:没有等待刷新的请求! 错误:请求不满意:GET https://api.github.com/users/wilk 模块: 测试: 假设GITHUB_API_URL等于 ‘
Apache Camel:2.12.2,activemq:5.7 我们注意到,在下面的路由中,对于前100次交换,节流工作正常。此后,它不是每秒发送100次交换,而是每秒仅发送1次交换。现在,如果我们将timePeriodMillis设置为100,它似乎可以正常工作。注意,我们同时发送500个交换。