新手在这里,我试图从内部AsyncTask
拨打AsyncTask
,如下所示,但它不起作用。有人能指出我正确的方向吗?当我从setCrowdSubtitle
调用方法card1
时,它没关系,但在尝试从AsyncTask
类设置时却没有。
class Card extends CardBase {
public void setCrowdTitle(String cTitle) {
CardHeader header = new CardHeader(getContext());
header.setTitle(cTitle);
header.setButtonExpandVisible(true);
addCardHeader(header);
}
public class HttpAsyncTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... urls) {
return GET(urls[0]);
}
@Override
protected void onPostExecute(String result) {
}
}
}
class Activity {
private class LoaderAsyncTask extends AsyncTask<Void, Void, ArrayList<Card>> {
@Override
protected ArrayList<Card> doInBackground(Void... params) {
if (isAdded()) {
ArrayList<Card> cards = initcrowdCard();
return cards;
} else
return null;
}
@Override
protected void onPostExecute(ArrayList<Card> cards) {
onRefreshComplete(cards);
}
private ArrayList<Card> initcrowdCard() {
ArrayList<Card> cards = new ArrayList<>();
Card card1 = new Card(this.getActivity(), R.layout.crowd_card);
card1.setCrowdSubtitle("Url");
cards.add(card1);
Card card2 = new Card(this.getActivity(), R.layout.crowd_card);
card2.new HttpAsyncTask() {
@Override
public void onPostExecute(String picUrl) {
card2.setCrowdSubtitle(picUrl);
}
}.execute(phpScript);
cards.add(card2);
}
}