Changes

Jump to: navigation, search
no edit summary
=== 3. Adding Functionality to Main Screen Elements ===
3.1. Create class <code>Student</code>. It is holder for contacts:
<pre>source lang="java"
package cs.ecl.team1.android;
public class Student {
private String firstName;
private String lastName;
}
</presource>
3.2. Inside the <code>ContractList</code> class create a Vector of objects <code>Student</code>:
<presource lang="java">
private Vector<Student> studentList;
</presource>
3.3. Populate the Vector:
<presource lang="java">
public Vector<Student> getList(){
studentList = new Vector<Student>();
return studentList;
}
</presource>
3.4. Create the method that generates list on the screen:
<presource lang="java">
public void displayData(){
contactsList.setAdapter(adapter);
}
</presource>
3.5. Populate the listView on the main screen:
<presource lang="java">
ListAdapter adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, studentList);
ListView contactsList = (ListView) findViewById(R.id.listView1);
contactsList.setAdapter(adapter);
</presource>
3.6. Add list to the main screen on create:
<presource lang="java">
@Override
public void onCreate(Bundle savedInstanceState) {
}
</presource>
3.7. Run the application:<br/>
[[Image: A_main5.png | 450px]]<br/>
3.8. Add the functionality to "Search" button by implementing the <code>onClickListener()</code>:
<presource lang="java">
searchButton.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
}
});
</presource>
3.9. Run the application, type in search text in the Text Field and click search button:<br/>
[[Image: A_search.png | 450px]]<br/>
1
edit

Navigation menu