I've tried looking online for a good solution to this but I can't seem to find one.
There's a listview of accounts. A selected account is indicated by a lighter blue color for its background but only when pressed. This is where I got the code from: Android ListView selected item stay highlighted
In the onCreate method, I have an onItemClickListener method and if I do listview.setSelection(0); above the onItemClick method, the default item is the first item in the listview. The system knows that the very first account in the list is the current item that is selected but how do I show it visually?
Essentially, I want to somehow do view.setSelected(true); for the first item in the listview.
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parentAdapter,
View view, int position, long id) {
view.setSelected(true);
Account account= accounts.get(position);
accountNumber = account.getAccountNumber();
}
});
Thank you!
Edit: Here's the getView from our custom adapter
public final View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = inflater.inflate(rowResourceId, parent, false);
textView = (TextView) rowView.findViewById(R.id.textView);
textView.setTextColor(Color.BLACK);
textView.setText(objects.get(position).debug());
return rowView;
}