本文介绍了开始buttonclick新线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的按钮启动一个新的线程,并摧毁该按钮位于之一,在单击它,我怎么做呢?

 包inno.games;进口android.app.Activity;
进口android.content.Context;
进口android.os.Bundle;
进口android.util.Log;
进口android.view.MotionEvent;
进口android.view.View;
进口android.view.inputmethod.InputMethodManager;
进口android.widget.Button;
进口android.widget.EditText;公共类Introscreen延伸活动{
按钮继续;@覆盖
保护无效的onCreate(捆绑savedInstanceState){
    // TODO自动生成方法存根
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.intro);
继续=(按钮)findViewById(R.id.bProceed);}


解决方案

Although your wording is not exactly clear, there is only one UI thread which is the main thread. The button being part of the UI "is located" (more or less) on the UI thread. You can't destroy that thread and replace it.

If there's something specific that you're looking to achieve by this, you should post that along with specific requirements.

Update:

If you just want to create a new thread on click then technically this does it:

proceed.setOnClickListener(new OnClickListener() {
    @Override
    public void OnClick(View v) {
        new Thread();
    }
});

but that doesn't exactly do anything useful. Also note that creating a new thread does not "get the CPU usage to a minimum". Creating a new thread creates more work for the CPU to do. However, you might be able to move some work from the UI thread to a background thread which will make the user experience smoother. If that's your goal, you should probably read this document entitled Painless Threading.

这篇关于开始buttonclick新线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 06:27
查看更多