java 不是封闭类_java – MainActivity.this不是一个封闭的类AsyncTask

我试图第一次创建一个AsyncTask,但我没有太多的运气.

我的AsyncTask需要从服务器获取一些信息,然后将新的布局添加到主布局以显示此信息.

一切似乎或多或少是清楚的,但是错误信息“MainActivity不是封闭的类”是困扰我的.

没有人似乎有这个问题,所以我想我很想念一些很明显的东西,我只是不知道是什么.

此外,我不知道我是否使用正确的方式获取上下文,并且因为我的应用程序不编译,所以我无法测试它.

您的帮助非常感激.

这是我的代码:

public class BackgroundWorker extends AsyncTask>

{

Context ApplicationContext;

@Override

protected ArrayList doInBackground(Context... contexts)

{

this.ApplicationContext = contexts[0];//Is it this right way to get the context?

SomeClass someClass = new SomeClass();

return someClass.getCards();

}

/**

* Updates the GUI before the operation started

*/

@Override

protected void onPreExecute()

{

super.onPreExecute();

}

@Override

/**

* Updates the GUI after operation has been completed

*/

protected void onPostExecute(ArrayList cards)

{

super.onPostExecute(cards);

int counter = 0;

for(Card card : cards)// Amount of "cards" can be different each time

{

//Create new view

LayoutInflater inflater = (LayoutInflater) ApplicationContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

ViewSwitcher view = (ViewSwitcher)inflater.inflate(R.layout.card_layout,null);

ImageButton imageButton = (ImageButton)view.findViewById(R.id.card_button_edit_nickname);

/**

* A lot of irrelevant operations here

*/

// I'm getting the error message below

LinearLayout insertPoint = (LinearLayout)MainActivity.this.findViewById(R.id.main);

insertPoint.addView(view,counter++,new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT));

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值