How to use ListView in app widget and fill it with data in android?

215 Views Asked by At

I´ve searched a long time, but I don't understand the methods which are used.

So, I want to add a home screen widget to my app and then populate the widget with data...

String[] data = new String[]{"first","second","third"};

But my problem is to set the ListView Adapter in my AppWidgetProvider class.

I already have a widget, which displays a TextView but I'm struggling with ListView.

Could somebody help me in setting the adapter or using ListView in Android Widget on a easy way?

Thank you in advanced!

1

There are 1 best solutions below

1
On
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>(this,
            android.R.layout.simple_list_item_1, lv_arr));

}


}