我有這樣的方法:Android - 如何使用內部類聲明的變量?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AnimalWebService animalWebService = restAdapter.create(AnimalWebService.class);
Callback<List<Animal>> callback = new Callback<List<Animal>>() {
@Override
public void success(List<Animal> animals, Response response) {
if (animals == null) {
Context context = getApplicationContext();
CharSequence text = "No animals available!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
else {
ListAdapter theAdapter = new MyAdapter(getApplicationContext(), animals);
}
}
@Override
public void failure(RetrofitError retrofitError) {
return;
}
};
animalWebService.get(callback);
theListView.setAdapter(theAdapter);
}
我到底有theListView.setAdapter(theAdapter);
但theAdapter
因爲它是在一個內部類中聲明不承認這裏。
我該如何解決這個問題?在Android中進行編程時,這種情況的最佳做法是什麼?
我剛剛發佈您的答案請採取食物吧。 – AnixPasBesoin