我收到以下代碼的錯誤。我不明白爲什麼,但adapter.notifyDataSetChanged();
不起作用。錯誤消息是:「無法解析符號'適配器'」。無法解析符號'適配器'
final String URL = "http://example....";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
rv = (RecyclerView) findViewById(R.id.rv);
....
public class PrintA extends AsyncTask<String, String, List<Model>> {
....
@Override
protected void onPostExecute(final List<MyModel> result) {
super.onPostExecute(result);
if (result != null) {
MyAdapter adapter = new MyAdapter(result);
rv.setAdapter(adapter);
} else {
Toast.makeText(getApplicationContext(), "no internet",
}
}
}
new PrintA().execute(URL);
rv.addOnScrollListener(new RecyclerView.OnScrollListener() {
....
public class PrintB extends AsyncTask<String, String, List<Model>> {
....
@Override
protected void onPostExecute(final List<MyModel> result) {
super.onPostExecute(result);
if (result != null) {
....
adapter.notifyDataSetChanged();
} else {
Toast.makeText(getApplicationContext(), "can't add",
}
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
....
new PrintB().execute(URL);
}
}
}
}
這並不比任何噸的不同他人無法找到本網站詢問的符號錯誤。 – csmckelvey
'adapter'是'PrintA'的'onPostExecute()'方法內的局部變量。在該方法之外的任何地方都不能引用它。 – CommonsWare