CreAToR
CreAToR

Reputation: 63

how to set Data from database to ListView

i have developed an Call recording application. it works absolutely right. i managed to show all recorded audio files to listView and managed to play these files from listView. i Have created a database to show the Caller number into listView. the database is working right and it Inserting and Selecting the data from database. know i want to show the database data into ListView. How can i do this plz help. thanks. i'm uploading the code for you to understand.

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

    listView = (ListView) findViewById(R.id.mylist);
    mp = new MediaPlayer();

    // database 
            getData = new CallerDatabase(MainActivity.this);
            getData.open();
            receivedData = getData.retrieveData();
            getData.close();
            Toast.makeText(this, ""+receivedData, Toast.LENGTH_SHORT).show();

    FileDataPathForArrayList();
}

private void FileDataPathForArrayList() {
    // this will show the recorded files into ListVIew
    myList = new ArrayList<String>();
    File files = new File(MEDIA_PATH);
    File list[] = files.listFiles();
    for (int i = 0; i < list.length; i++) {
        myList.add(list[i].getName());
    }

know how can i show the database data in this ArrayAdapter?

    adapter = new ArrayAdapter<String>(this, R.layout.rowlayout,
            R.id.label, myList);

    listView.setAdapter(adapter);

Upvotes: 0

Views: 985

Answers (2)

CreAToR
CreAToR

Reputation: 63

i have to change the ArrayAdapter from this

 adapter = new ArrayAdapter<String>(this, R.layout.rowlayout,
        R.id.label, myList);

to this

adapter = new ArrayAdapter<String>(this, R.layout.rowlayout,
        R.id.label, receivedData);

where receivedData is the folder who receive the data form database and show it into ListView

Upvotes: 1

bottus
bottus

Reputation: 903

It depends on what you want to display ...

if you just want to display some text into the rows of the listview, here is a good example => http://www.androidhive.info/2011/10/android-listview-tutorial/

if you want to custom your listview, you need to create custom adaptor for you listview.

Upvotes: 0

Related Questions