English 中文(简体)
ListView cookie 问题
原标题:ListView cookie questions

以下是我从网络服务中 输入ListView的代码。

  1. How can I set and get this ListView from cookies? (There`s an example on my code)
  2. Let`s say I have a button that will refresh this list, how to handle it?
  3. How to handle if the user is connected to internet or not?

我想知道如何管理一个来自网络服务的 ListView 。

public class EventsActivity extends Activity {

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

        RequestParams params = new RequestParams();
        params.put("user_id", "1");

        BloompItClient.get("get_events", params, new AsyncHttpResponseHandler() {
            @Override
            public void onStart() {

            }

            @Override
            public void onSuccess(String response) {                
                JSONObject jsonResponse;
                try {
                    jsonResponse = new JSONObject(response);

                    try {
                        String state = jsonResponse.getString("state");

                        if (state.equals("1")) {
                            ArrayList<HashMap<String, String>> eventsList = new ArrayList<HashMap<String, String>>();
                            JSONArray events = jsonResponse.getJSONArray("events");

                            for (int i = 0; i < events.length(); i++) {
                                JSONObject currentEvent = events.getJSONObject(i);
                                HashMap<String, String> eventMap = new HashMap<String, String>();

                                eventMap.put("college", currentEvent.getString("college_username"));
                                eventMap.put("author", currentEvent.getString("user_username"));
                                eventMap.put("title", currentEvent.getString("title"));                                                     
                                eventMap.put("date", currentEvent.getString("date"));

                                eventsList.add(eventMap);
                            }

                            ListView eventsListView = (ListView) findViewById(R.id.events);
                            EventsListAdapter eventsListAdapter = new EventsListAdapter(getApplicationContext(), eventsList);

                            // testing cookies

                            AsyncHttpClient asyncHttpClient = new AsyncHttpClient();

                            PersistentCookieStore persistentCookieStore = new PersistentCookieStore(getApplicationContext());
                            asyncHttpClient.setCookieStore(persistentCookieStore);

                            BasicClientCookie baseClientCookie = new BasicClientCookie("cookiesare", "awesome");
                            baseClientCookie.setVersion(1);
                            baseClientCookie.setDomain("it.bloomp");
                            baseClientCookie.setPath("/");
                            persistentCookieStore.addCookie(baseClientCookie);

                            List<Cookie> cookieList = persistentCookieStore.getCookies();

                            for (int i = 0; i < cookieList.size(); i++) {
                                System.out.println(cookieList.toString());
                            }

                            // testing cookies end

                            eventsListView.setAdapter(eventsListAdapter);
                        } else {

                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                } catch (JSONException e1) {
                    e1.printStackTrace();
                }
            }

            @Override
            public void onFailure(Throwable e) {

            }

            @Override
            public void onFinish() {

            }
        });
    }

    public void getEvents() {

    }
}
最佳回答

我会反悔回答你的问题

如果用户是否连接到互联网, 如何处理?

如果这不是本地保存的数据, 那么没有互联网连接, 您就无能为力。 如果您想要激活无线网络或数据连接( 如果这两个数据都尚未激活), 您可以提示用户 。

问题回答

暂无回答




相关问题
Write-though caching of large data sets in WCF?

We ve got a smart client that talks to a SQL Server database via WCF, displaying the entities in the database, and allowing the user to edit those entities. Some of the WCF calls return a large data ...

Clearing RSL in Cache

I have built a flex application which has a "main" project and it is assosciated with a few RSL s which are loaded and cached once i run my "main" application. The problem i am facing is that the ...

how to tell clicking "back" to load cache?

I would like for my site when someone clicks "Back" or "Forward" for the server to tell the browser to load the cache instead of reloading the entire page. I ve tested some headers and done research, ...

java plugin cache and dynamic IP host

I m trying to use Amazon S3 and Amazon Cloudfront CDN to deliver the jar files of my applet application. I m seeing several cache misses of my jars by the java plugin. This is a show-stopper for me, ...

Frequently Used metadata Hashmap

Are there any implementations of a static size hashtable that limits the entries to either the most recently or most frequently used metadata? I would prefer not to keep track of this information ...

PHP - Memcache - HTML Caching

I would like to create a caching system that will bypass some mechanisms in order to improve the performance. I have some examples: 1-) I have a dynamic PHP page that is updated every hour. The page ...

Performance of Sql subqueriesfunctions

I am currently working on a particularly complex use-case. Simplifying below :) First, a client record has a many-to-one relationship with a collection of services, that is, a single client may have ...

热门标签