Open main menu

CDOT Wiki β

Changes

no edit summary
=== 3. Adding Functionality to Main Screen Elements ===
3.1. Inside the Create class <code>ContractListStudent</code> class create a String array. It is holder for contacts:
<pre>
protected String[] studentList = { "Anastasia Semionova", "Minoo Ziaei", "Ladan Zadeh", "Sergiu Ecob" };
</pre>
3.2. Inside the <code>ContractList</code> class create a Vector of objects <code>Student</code>: <pre> private Vector<Student> studentList; </pre>3.3. Populate the Vector: <pre> public Vector<Student> getList(){ studentList = new Vector<Student>(); studentList.addElement(new Student("Anastasia", "Semionova", "asemionova1@learn.senecac.on.ca")); studentList.addElement(new Student("Minoo", "Ziaei", "minoo.ziaei@senecac.on.ca")); studentList.addElement(new Student("Ladan", "Zadeh", "lzahiroleslamzadeh@learn.senecac.on.ca")); studentList.addElement(new Student("Sergiu", "Ecob", "secob@learn.senecac.on.ca")); return studentList; } </pre>3.4. Create the method that generates list on the screen: <pre> public void displayData(){ ListAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, studentList); contactsList = (ListView) findViewById(R.id.listView1); contactsList.setAdapter(adapter); } </pre>3.5. Populate the listView on the main screen:
<pre>
ListAdapter adapter = new ArrayAdapter<String>(this,
contactsList.setAdapter(adapter);
</pre>
3.6. Add list to the main screen on create: <pre> @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); studentList = getList(); displayData(); } </pre>3.5. run the application:<br/>
[[Image: A_main5.png | 450px]]<br/>
3.4.
1
edit