I have created ListView fetching data from app db, and it’s working fine, when I want to display just one information, like team name, in one entry.
Now I’m trying to display more information, like team name, date, and town (all data from db, delivered by Cursor). And I can’t make it work, Intent is displaying ListView but there is no text in any of the entries… I don’t know how to explain it more clearly.
Intent code:
public class Games extends Activity implements OnClickListener {
Button bNewGame;
ListView gameList;
GameDayTableAdapter db;
Cursor c;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.games);
bNewGame = (Button) findViewById(R.id.bNewGame);
bNewGame.setOnClickListener(this);
gameList = (ListView) findViewById(R.id.lvGameList);
db = new GameDayTableAdapter(this);
db.open();
c = db.getAll();
startManagingCursor(c);
setListView();
}
private void setListView() {
// TODO Auto-generated method stub
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this,
android.R.layout.simple_expandable_list_item_1, c,
new String[] { AbstractDbAdapter.TEAM_NAME, AbstractDbAdapter.GAME_DAY_HOME_GAME, AbstractDbAdapter.GAME_DAY_DATE },
new int[] { R.id.game_entry_team, R.id.game_entry_home, R.id.game_entry_date });
gameList.setClickable(true);
gameList.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View v, int position, long id) {
}
});
gameList.setAdapter(mAdapter);
gameList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.bNewGame:
Intent intent = new Intent(Games.this, NewGame.class);
startActivity(intent);
db.close();
finish();
break;
}
}
game_list_entry.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/game_entry_team"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/game_entry_home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Space
android:layout_width="50dp"
android:layout_height="match_parent" />
<TextView
android:id="@+id/game_entry_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"/>
</LinearLayout>
That’s what I managed to do based on some tutorial available on-line, but not, it’s not working, and I don’t know how to fix it. I found other tutorials where people create new class which extends SimpleCursorAdapter, but that looks like a lot of extra work, and I’m wondering if there is an easier way to do it.
You are setting your list to use the expandablelist row view that comes with the framework. You need to specify your custom one instead.
Replace this:
With this: