无法解析符号 notifyDatasetChanged

Cannot resolve symbol notifyDatasetChanged

我正在使用一个应用程序,我从我的 azure 数据库中获取记录并将其插入到一个数组中,listview 必须显示我的数组。当我尝试调用方法 notifyDatasetChanged 时出现错误,这是我的代码:

    Button search;
EditText Esearch;
ListView list;
BaseAdapter ADAhere;
Connection connect;

List<Map<String,String>> MyData = new ArrayList();

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.srail, container, false);
    search = (Button)rootView.findViewById(R.id.btnSearch);
    Esearch = (EditText)rootView.findViewById(R.id.srch);
    list = (ListView)rootView.findViewById(R.id.view);

    search.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            CheckLogin checkLogin = new CheckLogin();
            checkLogin.execute("");






            String[] fromwhere = { "NAME","PRICE","RANGE","SUPPLIER","SIZE" };

            int[] viewswhere = {R.id.Name_txtView , R.id.price_txtView,R.id.Range_txtView,R.id.size_txtView,R.id.supplier_txtView};



            ADAhere = new SimpleAdapter(getActivity(), MyData,R.layout.list_products, fromwhere, viewswhere);



            list.setAdapter(ADAhere);






        }
    });


    return rootView;
}


public class CheckLogin extends AsyncTask<String, String, String> {
    String z = "";
    Boolean isSuccess = false;

    ProgressDialog progress;

    @Override
    protected void onPreExecute() {
        progress = ProgressDialog.show(getActivity(), "Searching...",
                "Listview Loading! Please Wait...", true);
    }

    @Override
    protected void onPostExecute(String r) {
        progress.dismiss();
        Toast.makeText(getActivity(), r, Toast.LENGTH_SHORT).show();
        if (isSuccess) {
            Toast.makeText(getActivity(), "Search Successfull", Toast.LENGTH_LONG).show();


            //finish();
        }
    }

    @Override
    protected String doInBackground(String... strings) {
        String Search = search.getText().toString();





            try {
                ConnectionHelper conStr = new ConnectionHelper();
                connect = conStr.connectionclass();        // Connect to database
                if (connect == null) {
                    z = "Check Your Internet Access!";
                } else {
                    // Change below query according to your own database.
                    String query = "select * from cc_rail where rail_name='" + Search.toString() +"' ";
                    Statement stmt = connect.createStatement();
                    ResultSet rs = stmt.executeQuery(query);
                    while (rs.next()) {
                        Map<String, String> datanum = new HashMap<String, String>();
                        datanum.put("NAME", rs.getString("RAIL_NAME"));

                        datanum.put("PRICE", rs.getString("RAIL_UNIT_PRICE"));

                        datanum.put("RANGE", rs.getString("RAIL_RANGE"));

                        datanum.put("SUPPLIER", rs.getString("RAIL_SUPPLIER"));

                        datanum.put("SIZE", rs.getString("RAIL_SIZE"));
                        MyData.add(datanum);

                    }
                    ADAhere.notifyDatasetChanged();


                    z = " successful";
                    isSuccess = true;
                    connect.close();
                }
            } catch (Exception ex) {
                isSuccess = false;
                z = ex.getMessage();
            }

            return z;
        }


}

错误出现在这部分代码中:

            String query = "select * from cc_rail where rail_name='" + Search.toString() +"' ";
            Statement stmt = connect.createStatement();
            ResultSet rs = stmt.executeQuery(query);
            while (rs.next()) {
                Map<String, String> datanum = new HashMap<String, String>();
                datanum.put("NAME", rs.getString("RAIL_NAME"));

                datanum.put("PRICE", rs.getString("RAIL_UNIT_PRICE"));

                datanum.put("RANGE", rs.getString("RAIL_RANGE"));

                datanum.put("SUPPLIER", rs.getString("RAIL_SUPPLIER"));

                datanum.put("SIZE", rs.getString("RAIL_SIZE"));
                MyData.add(datanum);

            }
            ADAhere.notifyDatasetChanged();

ADAhere.notifyDataSetChanged();

而不是

ADAhere.notifyDatasetChanged();

你写的小 s 而不是 S

更好的做法是在 onPostExecute 中编写此代码,而不是在 doInBackground

中编写此代码

你的问题是方法名的写法notifyDataSetChanged()(你在set中用了一个小s),不识别是正常的

更改此行

ADAhere.notifyDatasetChanged();

ADAhere.notifyDataSetChanged();

您已创建 BaseAdapter 并尝试通知适配器。创建一个 ADAhere 对象作为扩展 BaseAdapter

的 SimpleAdapter