Binden ArrayList mit ListView - Android

Ich versuche mich zu binden ListView mit ArrayList auf eine Schaltfläche klicken Sie (btnGetPost) . Ich bin sehr sehr sehr neu in Android-Programmierung. Jetzt bin ich in der Lage zum abrufen der Facebook-Gruppe Posten als JSON-Antwort. Dann bin ich die Schleife durch das JSON-Objekt hinzufügen und alle Meldungen an eine ArrayList.

Nun meine Frage, wie zeige ich alle Nachrichten in einem ListView auf eine button click. Ich meine, wie kann ich binden das ArrayList zu einem ListView ? Freundlich zeigen Sie mich in die richtige Richtung.

package org.example.fbapp;



@SuppressWarnings("deprecation")
public class FBAppActivity extends Activity {

    //Your Facebook APP ID
    private static String APP_ID = "********************";

    //JSON Node names
    private static final String TAG_DATA = "data";
    private static final String TAG_MESSAGE = "message";

    //data JSONArray
    JSONArray data = null;

    //Instance of Facebook Class
    private Facebook facebook = new Facebook(APP_ID);
    private AsyncFacebookRunner mAsyncRunner;
    String FILENAME = "AndroidSSO_data";
    private SharedPreferences mPrefs;

    //Hashmap for ListView
    ArrayList<HashMap<String, String>> messages = new ArrayList<HashMap<String, String>>();

    //Buttons

    Button btnGetPost;

    @SuppressWarnings("deprecation")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fbapp);


        btnGetPost = (Button) findViewById(R.id.btn_group_posts);
        mAsyncRunner = new AsyncFacebookRunner(facebook);


        /**
         * Get Posts from Group
         * */
        btnGetPost.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                getGPosts();
            }
        });


    }



    @SuppressWarnings("deprecation")
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        facebook.authorizeCallback(requestCode, resultCode, data);
    }



    /**
     * Get Group Posts by making request to Facebook Graph API
     * */
    @SuppressWarnings("deprecation")
    public void getGPosts() {
        mAsyncRunner.request("203153109726651/feed", new RequestListener() {
            @Override
            public void onComplete(String response, Object state) {
                Log.d("GET POSTS", response);
                String json = response;

                try {

                    //Facebook Profile JSON data
                    JSONObject obj = new JSONObject(json);
                    JSONArray finalObj = obj.getJSONArray("data");

                    for (int i = 0; i < finalObj.length(); i++) {

                        final String message = finalObj.getJSONObject(i)
                                .getString("message");

                        //creating new HashMap
                        HashMap<String, String> map = new HashMap<String, String>();

                        //adding each child node to HashMap key => value
                        map.put(TAG_MESSAGE, message);

                        //adding HashList to ArrayList
                        messages.add(map);


                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                Toast.makeText(getApplicationContext(),
                                        "Name: " + message, Toast.LENGTH_LONG)
                                        .show();
                            }

                        });
                    }

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

        }

            @Override
            public void onIOException(IOException e, Object state) {
            }

            @Override
            public void onFileNotFoundException(FileNotFoundException e,
                    Object state) {
            }

            @Override
            public void onMalformedURLException(MalformedURLException e,
                    Object state) {
            }

            @Override
            public void onFacebookError(FacebookError e, Object state) {
            }
        });
    }


    }



}
InformationsquelleAutor Monodeep | 2013-10-27
Schreibe einen Kommentar