Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/199.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php android每输入一个新的pid(id),然后刷新listview。我是怎么做到的?_Php_Android_Listview - Fatal编程技术网

Php android每输入一个新的pid(id),然后刷新listview。我是怎么做到的?

Php android每输入一个新的pid(id),然后刷新listview。我是怎么做到的?,php,android,listview,Php,Android,Listview,我的密码。请帮帮我。我是初学者。php json andriod Mainactivity java 请帮帮我。当数据更改时,listview自动实时更新显示我的android应用程序,请帮助我 package com.example.aaa111; public class MainActivity extends ListActivity { private ProgressDialog pDialog; // URL to get c

我的密码。请帮帮我。我是初学者。php json andriod Mainactivity java 请帮帮我。当数据更改时,listview自动实时更新显示我的android应用程序,请帮助我

  package com.example.aaa111;




    public class MainActivity extends ListActivity {

        private ProgressDialog pDialog;

        // URL to get contacts JSON
        private static String url = "http://test.pokupat.net/get_all_products.php";

        // JSON Node names




        private static final String TAG_PRODUCTS = "products";
        private static final String TAG_PID = "pid";
        private static final String TAG_NAME = "name";

        // contacts JSONArray
        JSONArray contacts = null;

        // Hashmap for ListView
        ArrayList<HashMap<String, String>> contactList;

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            contactList = new ArrayList<HashMap<String, String>>();

            ListView lv = getListView();
    // refresh function if this true ..
             Handler handler = new Handler();

                handler.postDelayed(new Runnable() {
                @Override
                public void run() {

                //do anything
                    new GetContacts().execute();

                }
                }, 10000);

            // Listview on item click listener
            lv.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                        int position, long id) {
                    // getting values from selected ListItem
                    String name = ((TextView) view.findViewById(R.id.name))
                            .getText().toString();
                    String pid = ((TextView) view.findViewById(R.id.pid))
                            .getText().toString();


                    // Starting single contact activity
                    Intent in = new Intent(getApplicationContext(),
                            SingleContactActivity.class);
                    in.putExtra(TAG_NAME, name);
                    in.putExtra(TAG_PID, pid);

                    startActivity(in);

                }
            });

            // Calling async task to get json uyffuyfuyfuy fyuf yfuy fuf uyfuy
            new GetContacts().execute();
        }

        /**
         * Async task class to get json by making HTTP call
         * */
        private class GetContacts extends AsyncTask<Void, Void, Void> {

            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                // Showing progress dialog
                pDialog = new ProgressDialog(MainActivity.this);
                pDialog.setMessage("Please wait...");
                pDialog.setCancelable(false);
                pDialog.show();

            }

            @Override
            protected Void doInBackground(Void... arg0) {
                // Creating service handler class instance
                ServiceHandler sh = new ServiceHandler();

                // Making a request to url and getting response
                String jsonStr = sh.makeServiceCall(url, ServiceHandler.GET);

                Log.d("Response: ", "> " + jsonStr);

                if (jsonStr != null) {
                    try {
                        JSONObject jsonObj = new JSONObject(jsonStr);

                        // Getting JSON Array node
                        contacts = jsonObj.getJSONArray(TAG_PRODUCTS);

                        // looping through All Contacts
                        for (int i = 0; i < contacts.length(); i++) {
                            JSONObject c = contacts.getJSONObject(i);

                            String name = c.getString(TAG_NAME);
                            String pid = c.getString(TAG_PID);



                                                    // tmp hashmap for single contact
                            HashMap<String, String> contact = new HashMap<String, String>();

                            // adding each child node to HashMap key => value
                            contact.put(TAG_NAME, name);
                            contact.put(TAG_PID, pid);



                            // adding contact to contact list
                            contactList.add(contact);
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                } else {
                    Log.e("ServiceHandler", "Couldn't get any data from the url");
                }

                return null;
            }

            @Override
            protected void onPostExecute(Void result) {
                super.onPostExecute(result);
                // Dismiss the progress dialog
                if (pDialog.isShowing())
                    pDialog.dismiss();

                        ListAdapter adapter = new SimpleAdapter(
                                MainActivity.this, contactList,
                                R.layout.list_item, new String[] { TAG_NAME, TAG_PID
                                         }, new int[] { R.id.name,
                                        R.id.pid});

                        setListAdapter(adapter);



            }

        }

    }
请刷新下面的背景

ListView lv = getListView();

将适配器声明为专用变量

private SimpleAdapter adapter;
然后在onPostExecute方法调用中

adapter.notifyDataSetChanged();

与每次调用都设置一个新适配器不同,您只需要让适配器知道已添加了新数据。这将告诉列表视图重新评估它自己,然后您将看到新数据出现

您可能会更幸运地使用一个Android开发者支持站点,使用一种更适合您的语言。我有很多列在。我怎么办?我想每分钟刷新我的列表视图。请帮帮我
adapter.notifyDataSetChanged();