0

I'm creating a android app, I have a fragment which as textview and a button. When you click the button you will be taken to another activity which is a form to fill it has a add button. When the add button is clicked the data will be save to parse, now the question is I to want retrieve the data and populate it to listview and view it in the fragment. Please help.

  • You can use base adapter with listview inside your Fragment class. check this thread's code: http://stackoverflow.com/questions/20177089/android-baseadapter-with-fragment – Lokesh Feb 06 '14 at 10:46

1 Answers1

2

Use Arraylist and adapter,

Your code should look like :

public class YourActivity extends Activity {

private ListView lv;

public void onCreate(Bundle saveInstanceState) {
     setContentView(R.layout.your_layout);

     lv = (ListView) findViewById(R.id.your_list_view_id);

     // Instanciating an array list (you don't need to do this, 
     // you already have yours).
     ArrayList<String> your_array_list = new ArrayList<String>();
     your_array_list.add("foo");
     your_array_list.add("bar");

     // This is the array adapter, it takes the context of the activity as a 
     // first parameter, the type of list view as a second parameter and your 
     // array as a third parameter.
     ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
             this, 
             android.R.layout.simple_list_item_1,
             your_array_list );

     lv.setAdapter(arrayAdapter); 
  }
}

Refer : Populating a ListView using an ArrayList?

Community
  • 1
  • 1