嘗試使用以下方法從列表視圖中將數據導入到GridView中。但是,當我運行應用程序,我沒有看到gridview,只有statslist
和更新按鈕。爲什麼我的GridView沒有顯示?
代碼
public class StatsListActivity extends Activity {
(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
public String PlayerData;
public String playerNumberStr;
public String playerPositionStr;
public String playerTeamStr;
private PlayerStatsDatabase dbHelper;
private SimpleCursorAdapter statsAdapter;
Button updateButton = null;
TextView playerTitle = null;
TextView playerNumber = null;
TextView playerPosition = null;
TextView playerTeam = null;
public void onCreate (Bundle savedInstanceState) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
super.onCreate(savedInstanceState);
dbHelper = new PlayerStatsDatabase(this);
dbHelper.open();
displayGridView();
}
private void displayGridView() {
// TODO Auto-generated method stub
//playerTitle.setText (PlayerNameText);
Cursor cursor = dbHelper.fetchAllStats();
setContentView(R.layout.scoreupdate);
// The desired columns to be bound
String[] columns = new String[] {
PlayerStatsDatabase.KEY_SCORE,
PlayerStatsDatabase.KEY_MINUTES,
PlayerStatsDatabase.KEY_SUBIN,
PlayerStatsDatabase.KEY_SUBOUT,
PlayerStatsDatabase.KEY_BOOKING,
};
// the XML defined views which the data will be bound to
int[] to = new int[] {
R.id.pGoals,
R.id.pMinutes,
R.id.pSubIn,
R.id.pSubOut,
R.id.pBook,
};
// create the adapter using the cursor pointing to the desired data
//as well as the layout information
statsAdapter = new SimpleCursorAdapter(
this, R.layout.statslist,
cursor,
columns,
to
);
GridView grid= (GridView) findViewById(R.id.gridViewPlayers);
// Assign adapter to ListView
grid.setAdapter(statsAdapter);
statsAdapter.notifyDataSetChanged();
dbHelper.close();
}
爲什麼沒有出現在網格也是爲什麼是空的ListView?
XML
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id = "@+id/RHE"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:padding="5dp">
<Button
android:id="@+id/btnUpdt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Update" />
<GridView
android:id="@+id/gridViewPlayers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="5" >
</GridView>
u能烏拉圭回合後XML .... – user1969053 2013-04-30 04:44:16
發佈的XML。 – b0w3rb0w3r 2013-04-30 04:48:19
這裏發佈的代碼將無法成功編譯。 – 2013-04-30 04:48:21