Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the ArrayList data in to the ListView?

I have Data in ArrayList like:

[android_metadata, test1, test5, test4, test2, test3, test10, test1002, abcd, zxy, re, test1001, testing, test21, test12]

Now i want to Set such data in to the ListView in android. Please help me in this matter. I have seen many Example. but should i have to implement getter setter class to store data and display it into ListView ? I have just to show Just above List of data in to List View and set its ClickEvent. Please Give me Some code to done such implement.

like image 699
Shreyash Mahajan Avatar asked Nov 30 '22 07:11

Shreyash Mahajan


1 Answers

try this code

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class Start extends Activity {

private String[] lv_arr = {};

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


    // Get a handle to the list view
    ListView lv = (ListView) findViewById(R.id.ListView01);

    // Convert ArrayList to array
    lv_arr = (String[]) arrayList.toArray();
    lv.setAdapter(new ArrayAdapter<String>(Start.this,
            android.R.layout.simple_list_item_1, lv_arr));

}


}
like image 134
Balaji.K Avatar answered Dec 04 '22 10:12

Balaji.K