I am kind of new to Android, I started working with SQLite 3 days ago. I managed to populate a list from database and defined some views following The Pragmatic Programmers – Hello Android, but I have a problem: when the list is displayed and I want to select an item it only highlights a line below and above the entry in the list. I am sure it has to do something with the definition of the lists row xml or listview xml. Though I will post the entire code.
validations_list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/l_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/l_idcolon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=": "
/>
<TextView
android:id="@+id/l_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/L_namecolon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=": "
/>
<TextView
android:id="@+id/av"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:textStyle="italic"
/>
</LinearLayout>
testing.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<!-- Note built-in ids for 'list' and 'empty' -->
<ListView
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/empty" />
</LinearLayout>
And here is the code for my activity:
public class LinesListActivity extends ListActivity {
private static final String TAG = "ValidationsListActivity";
private static int [] TO = {R.id.l_id,R.id.l_name,R.id.av};
private DbManipulator dbm;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.testing);
dbm = new DbManipulator(this);
try
{
Cursor c = dbm.getLines();
startManagingCursor(c);
showEvents(c);
}
finally
{
}
}
private void showEvents(Cursor c) {
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,R.layout.validations_list,c,FROM_V,TO);
setListAdapter(adapter);
}
@Override
public void onPause()
{
super.onPause();
dbm.close();
}
}
And I have a style defined for my app, but when I change it back to normal style the problem stays, nothing actually changes.
The selector defaults to showing behind the list which defaults to transparent, so you can see the selector through it.
You have set an opaque color for the background, so you need to set the selector on top.
Add this to your listview XML
That should fix it up.
EDIT
Ok, next trick. Set up a color state selector.
1) Create a color list in your
valuesfolder, setting color names to their hex numbers:colors.xml
2) Create a selector in your
drawablefolder:item_selector.xml
3) Finally, set the selector as the background of your list row elements:
Using the above would cause the background of the list item you were pressing to turn green while pressed, leaving the text visible on top.