Is there a way to color/style certain portions of the resulting string?
I have a ListView layout, and the following onCreate method for the corresponding Activity.
public class AddressesActivity extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.addresses);
AddressDBHandler datasource = new AddressDBHandler(this);
datasource.open();
List<Address> values = datasource.getAllAddresses();
ArrayAdapter<Address> adapter = new ArrayAdapter<Address>(this,
android.R.layout.simple_list_item_1, values);
setListAdapter(adapter);
}
.
.
.
The data is loaded from the following class:
public List<Address> getAllAddresses() {
List<Address> addresses = new ArrayList<Address>();
Cursor cursor = database.query(MySQLiteHelper.TABLE_ADDRESSES,
allColumns, null, null, null, null, null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
Address address = cursorToAddress(cursor);
addresses.add(address);
cursor.moveToNext();
}
cursor.close();
return addresses;
}
My toString() method in the Address class is the following:
// Will be used by the ArrayAdapter in the ListView
@Override
public String toString() {
Spanned format = Html.fromHtml("<br/>" + address + "<br/>" + name + "<br/>");
return format.toString();
}
Seems like I am getting results with the break tags. I would just like the address to be a different color from the name.
You should create a adapter class as follows:
Then use it
onCreate
as follows: