I'm new to android programming and I still have a few things that I don't understand. For example, I'm with a program that when you click on a button, it tries to find any devices near. The problem is that I don't know how to solve a mistake I seem to have made from the beggining. This is what I have
This is the main activity:
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void buscar(View view){
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
List<String> s = new ArrayList<String>();
for(BluetoothDevice bt : pairedDevices)
s.add(bt.getName());
setListAdapter(new ArrayAdapter<String>(this, R.id.list, s));
}
}
And here is the xml file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="#+id/botonvinculo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:clickable="true"
android:onClick="buscar"
android:text="Buscar dispositivos" />
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/botonvinculo"
android:layout_below="#+id/botonvinculo" >
</ListView>
</RelativeLayout>
The thing is that I cannot make the call to setListAdapter unless my main activity extends from ListActivity, and even trying so, it returns an error saying "You must have a ListView whose attribute is "android.R.id.list".
I'd appreciate any help. Thank you very much.
If you use ListActivity then you should use android:id="#android:id/list" in your XML instead of android:id="#+id/list"
or else you can get an object of ListView in your XML like
ListView list = (ListView) findViewById(R.id.list);
and then use list.setAdapter
setListAdapter will work only when your activity extends from ListActivity. use this in your case
listview.setAdapter();
if you want to use setListAdapter() only make change these things
public class MainActivity extends Activity
to
public class MainActivity extends ListActivity
and
android:id="#android:id/list" for your list view in xml
Your class extends Activity. setListAdapter is a method of ListActivity
ListView lv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv = (ListView)findViewById(R.id.list);
}
Then
public void buscar(View view){
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
List<String> s = new ArrayList<String>();
for(BluetoothDevice bt : pairedDevices)
s.add(bt.getName());
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple.list_item_1,s);
lv.setAdapter(adapter);
}
Related
I am just trying to inflate a simple fragment for a newsreader project that uses an RSS feed to display news stories. The task is simply to convert the activities to fragments and retain functionality. I have been trying for days to get this to work.
The only goal right now is to get the fragment to inflate and display a test button, a textview and an empty listview. I have checked the fragment XML dozens of times and found no errors. As far as I understand displaying fragment_items in ActivityItems should work. I am performing this inflation exactly as my textbook describes how to inflate a fragment to no avail. I have tried googling every line of the logcat and reading through as many threads as possible and haven't found a solution yet.
ItemsActivity.java
package com.murach.newsreader;
import java.util.ArrayList;
import java.util.HashMap;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
public class ItemsActivity extends Activity {
private RSSFeed feed;
private FileIO io;
private TextView titleTextView;
private ListView itemsListView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_items);
io = new FileIO(getApplicationContext());
titleTextView = (TextView) findViewById(R.id.titleTextView);
itemsListView = (ListView) findViewById(R.id.itemsListView);
}
class DownloadFeed extends AsyncTask<Void, Void, Void> {
#Override
protected Void doInBackground(Void... params) {
io.downloadFile();
return null;
}
#Override
protected void onPostExecute(Void result) {
Log.d("News reader", "Feed downloaded");
new ReadFeed().execute();
}
}
class ReadFeed extends AsyncTask<Void, Void, Void> {
#Override
protected Void doInBackground(Void... params) {
feed = io.readFile();
return null;
}
#Override
protected void onPostExecute(Void result) {
Log.d("News reader", "Feed read");
// update the display for the activity
ItemsActivity.this.updateDisplay();
}
}
public void updateDisplay()
{
if (feed == null) {
titleTextView.setText("Unable to get RSS feed");
return;
}
// set the title for the feed
titleTextView.setText(feed.getTitle());
// get the items for the feed
ArrayList<RSSItem> items = feed.getAllItems();
// create a List of Map<String, ?> objects
ArrayList<HashMap<String, String>> data =
new ArrayList<HashMap<String, String>>();
for (RSSItem item : items) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("date", item.getPubDateFormatted());
map.put("title", item.getTitle());
data.add(map);
}
// create the resource, from, and to variables
int resource = R.layout.listview_item;
String[] from = {"date", "title"};
int[] to = {R.id.pubDateTextView, R.id.titleTextView};
// create and set the adapter
SimpleAdapter adapter =
new SimpleAdapter(this, data, resource, from, to);
itemsListView.setAdapter(adapter);
Log.d("News reader", "Feed displayed");
}
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
// get the item at the specified position
RSSItem item = feed.getItem(position);
// create an intent
Intent intent = new Intent(this, ItemActivity.class);
intent.putExtra("pubdate", item.getPubDate());
intent.putExtra("title", item.getTitle());
intent.putExtra("description", item.getDescription());
intent.putExtra("link", item.getLink());
this.startActivity(intent);
}
}
activity_items.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/titleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFAC83"
android:padding="7dp"
android:text="#string/items_title"
android:textSize="22sp" />
<ListView
android:id="#+id/itemsListView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
ItemsFragment.java
package com.murach.newsreader;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
public class ItemsFragment extends Fragment {
private Button testButton;
private TextView titleTextView;
private ListView itemsListView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_items, container, false);
testButton = (Button) view.findViewById(R.id.testButton);
titleTextView = (TextView) view.findViewById(R.id.titleTextView);
itemsListView = (ListView) view.findViewById(R.id.itemsListView);
return view;
}
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
}
fragment_items.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment android:name="com.murach.newsreader.ItemsFragment"
android:id="#+id/fragment_items"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="#+id/titleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFAC83"
android:padding="7dp"
android:text="#string/items_title"
android:textSize="22sp" />
<Button
android:id="#+id/testButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TEST BUTTON" />
<ListView
android:id="#+id/itemsListView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
The logcat
<pre>
at
com.murach.newsreader.ItemsFragment.onCreateView(ItemsFragment.java:25)
at android.app.Fragment.performCreateView(Fragment.java:2522)
at
android.app.FragmentManagerImpl.ensureInflatedFragmentView(FragmentManager.jav
a:1486)
at
android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1269)
at
android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1481)
at
android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1723)
at
android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3556)
at
android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:186
)
at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780)
at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
02-06 20:45:13.014 4765-4765/? E/AndroidRuntime: at
android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1481)
at
android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1723)
at
android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3556)
at
android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:186 )
at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780)
at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at
android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at
com.murach.newsreader.ItemsFragment.onCreateView(ItemsFragment.java:25)
at android.app.Fragment.performCreateView(Fragment.java:2522)
at
android.app.FragmentManagerImpl.ensureInflatedFragmentView(FragmentManager.jav
a:1486)
at
android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1269)
at
android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1481)
at
android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1723)
The layoutinflater should just inflate the fragment xml layout and display the test button and the other widgets. I have tried removing all code irrelevant to inflating the fragment and all code/xml relating to the widgets and it still crashes. I have even created a test project with absolutely nothing but an initial activity with a test button and a fragment with a test button and the layoutinflater still won't work.
I am trying to populate a listView with paired bluetooth devices. I tried doing so with a ListView in my MainActivity and it worked perfectly. However, when I tried it with a ListView in a different activity it crashed the app. I basically want to populate a ListView in a pop-up dialog box.
Here is the code:
activity_device_list.xml (MainActivity)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<ListView
android:id="#+id/listDevicesMain"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
device_dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.12"
android:gravity="center"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="Paired Devices"
android:textSize="25sp" />
<ListView
android:id="#+id/listDevicesDialog"
android:layout_width="match_parent"
android:layout_height="395dp"
android:layout_weight="0.38" />
</LinearLayout>
DeviceList.java
package example.btmodule;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Set;
import static example.btmodule.R.layout.activity_device_list;
public class DeviceList extends AppCompatActivity {
ListView devicelist;
private BluetoothAdapter myBluetooth = null;
private Set<BluetoothDevice> pairedDevices;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(activity_device_list);
myBluetooth = BluetoothAdapter.getDefaultAdapter();
if(myBluetooth == null)
{
//Show a mensag. that thedevice has no bluetooth adapter
Toast.makeText(getApplicationContext(), R.string.bluetooth_unavailable, Toast.LENGTH_LONG).show();
//finish apk
finish();
}
else {
if (myBluetooth.isEnabled()) {
} else {
//Ask to the user turn the bluetooth on
Intent turnBTon = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(turnBTon, 1);
}
}
}
private void pairedDevicesList()
{
pairedDevices = myBluetooth.getBondedDevices();
ArrayList list = new ArrayList();
devicelist = (ListView)findViewById(R.id.listDevicesDialog);
if (pairedDevices.size()>0)
{
for(BluetoothDevice bt : pairedDevices)
{
list.add(bt.getName() + "\n" + bt.getAddress()); //Get the device's name and the address
}
}
else
{
Toast.makeText(getApplicationContext(), R.string.no_devices_found, Toast.LENGTH_LONG).show();
}
final ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1, list);
devicelist.setAdapter(adapter);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
// menu item selection
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.action_connect:
showDialog();
pairedDevicesList();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
// show the dialog for connected devices
private void showDialog(){
AlertDialog.Builder mBuilder = new AlertDialog.Builder(DeviceList.this);
View mView = getLayoutInflater().inflate(R.layout.device_dialog, null);
mBuilder.setView(mView);
AlertDialog dialog = mBuilder.create();
dialog.show();
}
}
If I change devicelist to R.id.listDevicesMain the code works perfectly fine.
you calling the wrong list view the id of the list view as you have given is
<ListView
android:id="#+id/listDevicesMain"
android:layout_width="match_parent"
android:layout_height="match_parent" />
and you are trying to call the listview with id
devicelist = (ListView)findViewById(R.id.listDevicesDialog);
hope this will solve the issue.
devicelist = (ListView)findViewById(R.id.listDevicesDialog); - here you are looking for listDevicesDialog in activity layout, so devicesList becomes null. You should add devicelist = (ListView) mView.findViewById(R.id.listDevicesDialog); to showDialog() method and bring there rest of the operations related with searching for paired devices and setting adapter.
You can also call pairedDevicesList from showDialog and pass view where listDevicesDialog is:
private void pairedDevicesList(View dialogView)
{
pairedDevices = myBluetooth.getBondedDevices();
ArrayList list = new ArrayList();
devicelist = (ListView) dialogView.findViewById(R.id.listDevicesDialog);
...
}
// show the dialog for connected devices
private void showDialog()
{
AlertDialog.Builder mBuilder = new AlertDialog.Builder(DeviceList.this);
View mView = getLayoutInflater().inflate(R.layout.device_dialog, null);
mBuilder.setView(mView);
AlertDialog dialog = mBuilder.create();
dialog.show();
pairedDevicesList(mView);
}
I'm currently working on attempting to make an RSS Reader using a ListView in Android studio. I've already managed to make the ListView, but i have no idea where to go next. I cant seem to find any good tutorials online on how i should tackle this, and Anything i do find is out of date by 3 years. Any tips?
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.micha.rssreader.MainActivity">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:id="#+id/listviewAD" />
MainActivity.java
package com.example.micha.rssreader;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class MainActivity extends AppCompatActivity {
public ListView AdFeed; // maakt listview aan
public String[] items;
public ArrayAdapter<String> adapt;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AdFeed = (ListView)findViewById(R.id.listviewAD);
items = new String[]{"blue", "red", "black", "orange", "purpol"};
adapt = new ArrayAdapter<String>(this, R.layout.items, items);
AdFeed.setAdapter(adapt);//zet de data acther de listview
AdFeed.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
});
}
}
Try this example
http://www.androidauthority.com/simple-rss-reader-full-tutorial-733245/
it is up to date since it uses buildToolsVersion 25.0.1.
Only difference is that it uses RecyclerView instead of ListView, which is recommended since it is lighter than ListView
Im new to android and searched a lot regarding this problem but couldnt find solution,im getting this error while setting on click listner option on the spinner options,please help me in solving this error though its a small one.
Error
The method setOnItemSelectedListener(AdapterView.OnItemSelectedListener) in the type AdapterView is not applicable for the arguments (MainActivity)
#MainActivity.java
package com.example.spinners;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
public class MainActivity extends ActionBarActivity implements OnItemSelectedListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Spinner spinner = (Spinner) findViewById(R.id.spinner1);
spinner.setOnItemSelectedListener(this);
// Create an ArrayAdapter using the string array and a default spinner layout
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.planets_array, android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
spinner.setAdapter(adapter);
;
}
#Override
public void onItemSelected(AdapterView<?> parent, View view, int pos,long id) {
// code
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.spinners.MainActivity" >
<Spinner
android:id="#+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="110dp" />
</RelativeLayout>
spinner.setOnItemSelectedListener(this);
This expects this to be an object that implements the onItemSelectedListener interface, you can do it as you want, but you need to change this
public class MainActivity extends ActionBarActivity
to
public class MainActivity extends ActionBarActivity implements onItemSelectedListener
and implement the method
#Override
public void onItemSelected(AdapterView<?> parent, View view, int pos,long id) {
// code
}
Edit:
and this method
#Override
public void onNothingSelected (AdapterView<?> parent) {
// code
}
Here's my main activity:
package com.dannytsegai.worldgeography;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class MainActivity extends ListActivity {
private ListView listview;
private String[] mContinents;
private ArrayAdapter<String> adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listview = (ListView) findViewById(R.id.list);
mContinents = getResources().getStringArray(R.array.continents_array);
adapter = new ArrayAdapter<String>(this, R.layout.simple_list_item, mContinents);
listview.setAdapter(adapter);
}
}
Here's my main layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</ListView>
</LinearLayout>
I've gone through the code, but I can't figure out what's wrong with it for the life of me. Can someone please help me?
Change this
R.layout.simple_list_item
to
android.R.layout.simple_list_item_1
since you are extending ListActivity, in the layout, your ListVeiw must have the id #android:id/list, otherwise you will get the following exeception:
java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'.
To retrieve the ListView you do not need to call findViewById but you can use directly getListView() that returns the ListView
Try with this:
public class MainActivity extends ListActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
"Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
"Linux", "OS/2" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, values);
setListAdapter(adapter);
}
}
If in doubt check this page: http://www.vogella.com/tutorials/AndroidListView/article.html#listactivit