Hello I am new to Android programming and I am a bit rusty with Java too since I haven’t done it in a while.
I am trying to use an example that I found online and when I try to run it with the emulator it said that my program has stopped and I have no idea why.
All that I modified was the main Java file
The code that I have is:
import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class ScottTestActivity extends ListActivity {
/** Called when the activity is first created. */
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
//Values to display
String[] values = new String[] { "Android", "iPhone",
"Windows Mobile", "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);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
String item = (String) getListAdapter().getItem(position);
Toast.makeText(this, item + " selected", Toast.LENGTH_LONG).show();
}
}
Could someone please help me? and if possible point me in a good direction that explains Android programming?
is this where you took your sample :
http://www.vogella.de/articles/AndroidListView/article.html
anyway as Dawid Sajdak refers, it looks that there is no listview tag in main.xml
you need to add this to res/layout/main.xml
<
good luck