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;
// Amount of "cards" can be different each time
for (Card card : cards) {
//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));
}
}
}