java – 如何将原语int传递给我的AsyncTask?

栏目: Java · 发布时间: 7年前

内容简介:翻译自:https://stackoverflow.com/questions/32069309/how-can-i-pass-a-primitive-int-to-my-asynctask

我想要的是将一个int变量传递给我的AsyncTask.

int position = 5;

我宣布我的AsyncTask是这样的:

class proveAsync extends AsyncTask<int, Integer, Void> {

    protected void onPreExecute(){
    }

    protected Void doInBackground(int... position) {
    }

    .
    .
    .

但我得到一个错误,它是以下内容:

Type argument cannot be of primitive type

我只能传递一个int []和Integer变量,但从不传递一个int变量,我执行我的AsyncTask,如下所示:

new proveAsync().execute(position);

我能做些什么才能通过这个职位吗?

提前致谢!

将参数传递为Integer

class proveAsync extends AsyncTask<Integer, Integer, Void> {

    protected void onPreExecute(){
    }

    protected Void doInBackground(Integer... position) {
        int post = position[0].intValue();
    }

    .
    .
    .

执行时执行此操作

new proveAsync().execute(new Integer(position));

您可以使用intValue()获取AsyncTask中的int值

翻译自:https://stackoverflow.com/questions/32069309/how-can-i-pass-a-primitive-int-to-my-asynctask


以上所述就是小编给大家介绍的《java – 如何将原语int传递给我的AsyncTask?》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

编程精粹

编程精粹

Steve Maguire / 人民邮电出版社 / 2009.2 / 45.00元

编写高质量的、没有bug的程序,是每位程序员所追求的目标。但随着软件规模越来越大,功能日趋复杂,这一目标变得越来越困难。 本书揭示了微软公司应对质量挑战、开发出世界级代码的技术内幕,作者在自己不断探索、实践和思考的基础上,系统总结了多年来指导微软各团队的经验,将其凝聚为许多切实可行的编程实践指导,可谓字字珠玑。正因如此,本书被公认为与《代码大全》齐名的编程技术名著,曾于1993年荣获有软件开......一起来看看 《编程精粹》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

html转js在线工具
html转js在线工具

html转js在线工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具