清除适配器我想从列表视图中明确适配器,但没有发生 这里是我的代码需要从列表视图
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
search_button = (Button) findViewById(R.id.next_button);
editText = (EditText) findViewById(R.id.edit_text);
emptyTextView = (TextView) findViewById(R.id.empty_view);
bookListView = (ListView) findViewById(R.id.list_view);
// Get a reference to the ConnectivityManager to check state of network connectivity
ConnectivityManager connMgr = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
// Get details on the currently active default data network
final NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
search_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (networkInfo != null && networkInfo.isConnected()) {
new GetBook().execute(BOOK_REQUEST_URL);
} else {
//这里需要明确的适配器,但什么也没发生
emptyTextView.setText(R.string.NoConnect);
bookListView.setEmptyView(emptyTextView);
bookAdapter.clear();
}
}
你的Adapter的实现是错误的...... Fx你是从ArrayAdapter扩展并重写getCount但不清楚。常见的错误是将数据再次存储在自定义ArrayAdapter中,而ArrayAdapter已经存储了数据。 – Selvin
你需要阅读很多:https://stackoverflow.com/questions/24775171/the-clear-in-custom-listview-adapter-also-updates-the-list-data – Stanojkovic