【发布时间】:2011-04-13 23:57:07
【问题描述】:
我(认为)我已经设法构建了在自定义对话框中显示 SQLite 数据所需的大部分代码,但仍然坚持如何将它们放在一起。
我的适配器如下所示:
public class ScoresDisplayerAdaptor extends CursorAdapter {
private LayoutInflater mLayoutInflater;
private Context mContext;
public ScoresDisplayerAdaptor(Context context, Cursor c) {
super(context, c);
mContext = context;
mLayoutInflater = LayoutInflater.from(context);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View v = mLayoutInflater.inflate(R.layout.playerscoresrow, parent, false);
return v;
}
/**
* @author will
*
* @param v
* The view in which the elements we set up here will be displayed.
*
* @param context
* The running context where this ListView adapter will be active.
*
* @param c
* The Cursor containing the query results we will display.
*/
@Override
public void bindView(View v, Context context, Cursor c) {
int player1Score = c.getInt(c.getColumnIndexOrThrow(DBAdaptor.KEY_PLAYER1_SCORE));
int player2Score = c.getInt(c.getColumnIndexOrThrow(DBAdaptor.KEY_PLAYER2_SCORE));
int player3Score = c.getInt(c.getColumnIndexOrThrow(DBAdaptor.KEY_PLAYER3_SCORE));
int player4Score = c.getInt(c.getColumnIndexOrThrow(DBAdaptor.KEY_PLAYER4_SCORE));
/**
* Next set the title of the entry.
*/
TextView tvwPlayer1Score = (TextView) v.findViewById(R.id.tvwPlayer1score);
TextView tvwPlayer2Score = (TextView) v.findViewById(R.id.tvwPlayer2score);
TextView tvwPlayer3Score = (TextView) v.findViewById(R.id.tvwPlayer3score);
TextView tvwPlayer4Score = (TextView) v.findViewById(R.id.tvwPlayer4score);
tvwPlayer1Score.setText(player1Score);
tvwPlayer2Score.setText(player2Score);
tvwPlayer3Score.setText(player3Score);
tvwPlayer4Score.setText(player4Score);
}
}
我的 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">
<ListView android:id="@+id/android:list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout>
<Table>
<TableRow>
<TextView android:id="@+id/tvwPlayer1score" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/tvwPlayer2score" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/tvwPlayer3score" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/tvwPlayer4score" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</TableRow>
</Table>
</RelativeLayout>
最后,我使用它的代码是这样的:
private void showCurrentScores(){
DBAdaptor dbAdaptor;
Cursor scoresCursor;
ScoresDisplayerAdaptor scoresDisplayerAdaptor;
dbAdaptor = new DBAdaptor(this);
scoresCursor = dbAdaptor.getScores();
startManagingCursor(scoresCursor);
scoresDisplayerAdaptor = new ScoresDisplayerAdaptor(this,scoresCursor);
}
但我现在被困在最后一行之后该放什么了。
【问题讨论】: