assertEquals("Numbers doesn't match.", mJohn.getNumber(), number.getText());
public class Contact implements Comparable<Contact> { .... //return -1 for less than, 0 for equals, and 1 for more than public compareTo(Contact anotherContact) { int result = 0; result = getName().compareTo(anotherContact.getName()); if (result != 0) { return result; } result = getNunmber().compareTo(anotherContact.getNumber()); if (result != 0) { return result; } ... } }
public ContactsAdapter(Context context, String[] values){ super(context, R.layout.contact_row_layout, values); } @Override public View getView(int position, View convertView, ViewGroup parent){ Log.d(TAG, "getView"); // The LayoutInflator puts a layout into the right View LayoutInflater inflater = LayoutInflater.from(getContext()); // inflate takes the resource to load, the parent that the resource may be // loaded into and true or false if we are loading into a parent view. View view = inflater.inflate(R.layout.contact_row_layout, parent, false); // We retrieve the text from the array // Get the TextView we want to edit //Create more textviews for showing desired atributes TextView mContactName = (TextView)view.findViewById(R.id.contact_name); TextView mContactNumber = (TextView) view.findViewById(R.id.contact_number); view.findViewById(R.id.contacts_avatar); //Create object contact that will have name, number, etc atributes... Contact contact = getItem(position); // Put the next TV Show into the TextView mContactName.setText(contact.getName()); mContactNumber.setText(contact.getNumber()); return view;
public void writer(){ String x = "MyContacts.txt"; try { PrintWriter outputs = new PrintWriter(x); for( int i=0; i < myContacts.length; i++) { Contact c = myContacts[i]; if(c!=null){ // check if c is null before writing to file outputs.println(""+c.getName()+" "+c.getNumber()+" "+c.getName()); outputs.flush(); } } outputs.close(); }catch (IOException e) { e.printStackTrace(); } catch(NullPointerException ex){ // Or just catch the NPE }
public void retrieveInformation(BackendlessDataQuery query,final DefaultTableModel model){ System.out.println("Retrieving Data..."); Backendless.Data.of(Contact.class).find(query, new AsyncCallback<BackendlessCollection<Contact>>() { @Override public void handleResponse(BackendlessCollection<Contact> backendlessCollection) { Object[] row = new Object[2]; for (Contact map : backendlessCollection.getCurrentPage()){ row[0] = map.getName(); row[1] = map.getNumber(); model.addRow(row); System.out.println("Retrieving Data complete !"); } } @Override public void handleFault(BackendlessFault backendlessFault) { System.out.println(backendlessFault.getMessage()); } });}
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); listView = getListView(); populateList(listView); } void populateList(ListView lv) { db = new DatabaseAccess(getActivity().getApplicationContext()); List<Contact> contacts = db.getAllContacts(); if (contacts.size() > 0) { List<Map<String, String>> contactList = new ArrayList<Map<String, String>>(); for (Contact con : contacts) { Map<String, String> data = new HashMap<String, String>(2); data.put("name", con.getName()); data.put("number", con.getNumber()); contactList.add(data); } SimpleAdapter adapter = new SimpleAdapter(getView().getContext(), contactList, android.R.layout.simple_list_item_2, new String[] {"name", "number"}, new int[] {android.R.id.text1, android.R.id.text2}); lv.setAdapter(adapter); } else { setEmptyText("Masih belum ada kontak"); } setListShown(true); db.closeDB(); }
textNumber.setText(myContact.getNumber());
Contact c = myContacts[i]; outputs.println(""+c.getName()+" "+c.getNumber()+" "+c.getName()); outputs.flush();