Newbie setting up a ListView

I am just starting out using Android, so this is probably a very basic question.

I have created an array called priorityNames. I want to display that in a list and be able to make a selection from that list. At this stage, I cannot get the list to display.

As a starting point I used a short example from windrealm.org tutorials Any help would be appreciated. Also if anyone can point me to a better example it would be appreciated.

public class SimpleListViewActivity extends Activity {    

private ListView mainListView ;    
private ArrayAdapter<String> listAdapter ;    

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

    // Find the ListView resource.     
    mainListView = (ListView) findViewById( R.id.mainListView );   
    listAdapter = new ArrayAdapter<String>(this, R.layout.simplerow, R.array.priorityNames);    
    mainListView.setAdapter(listAdapter);          
}    

}

Answers


You are passing just an id with R.array.priorityNames.

Use:

getResources().getStringArray(R.array.priorityNames)

Dannyroa gave you the answer. If you're looking for a better set of android tutorials, I would recommend http://www.mkyong.com/android/android-listview-example/

Anything from him is very simple and will help you in your journey to use android.


You are probably missing a TextView in your xml layout (simplerow.xml) with id:

...android:id="@android:id/text1"...

Need Your Help

Salty Vagrant Master hostname: salt not found

vagrant provisioning salt-stack

I am trying to load my vagrant box with salt, asking it to install Apache.

How to Draw a simple GUI Histogram

java project histogram

I need to draw a simple histogram for a project I'm working on that needs to look this...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.