Cannot resolve symbol notifyDatasetChanged

那年仲夏 提交于 2019-12-25 18:49:13

问题


I am working with an application where i get records from my azure database and insert it into an array, and the listview must display my array. My error comes when i try to call the method notifyDatasetChanged, Here is my code:

    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;
        }


}

The Error comes in this portion of the code:

            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();

回答1:


write

ADAhere.notifyDataSetChanged();

instead of

ADAhere.notifyDatasetChanged();

You wrote small s instead of S

This is more better practice to write this code in onPostExecute instead of writing this is doInBackground




回答2:


Your problem is with the way you write the method name notifyDataSetChanged() (you used a small s in set), so it's normal that it does not recognize it

Change this line

ADAhere.notifyDatasetChanged();

with

ADAhere.notifyDataSetChanged();



回答3:


You have created BaseAdapter and trying to notify the adapter. Create an ADAhere object as a SimpleAdapter which extends BaseAdapter



来源:https://stackoverflow.com/questions/50000961/cannot-resolve-symbol-notifydatasetchanged

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!