我有这样的方法: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