我想在mylick中运行两种方法。第一种方法是显示ListView
。第二种方法是从先前的ListView
获取数据并将其放入新的ListView
中。目的是将所有这些数据组合在一起并同时显示在新的ListView
中。
摘要
显示ListView B. 从ListView A获取数据 同时显示所有数据
代码
btnSave2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
PlayerStatsDatabase db = new PlayerStatsDatabase(getApplicationContext());
db.open();
db.createStats(txtGoalsScored.getText().toString(), txtMinutesPlayed.getText().toString(),txtSubstituteIn.getText().toString(),txtSubstituteOut.getText().toString(), checkText.toString());
db.close();
displayListView();
dipsplayPlayerName();
}
});
}
private void displayListView() {
// TODO Auto-generated method stub
//playerTitle.setText (PlayerNameText);
Cursor cursor = dbHelper.fetchAllStats();
setContentView(R.layout.playerstats);
// 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
);
ListView list= (ListView) findViewById(R.id.listView1);
// Assign adapter to ListView
list.setAdapter(statsAdapter);
statsAdapter.notifyDataSetChanged();
}
private void dipsplayPlayerName() {
setContentView (R.layout.statslist);
playerTitle = (TextView) findViewById (R.id.textTitle);
playerTitle.setText (PlayerData);
playerNumber = (TextView) findViewById (R.id.pNumber);
playerNumber.setText (playerNumberStr);
playerPosition = (TextView) findViewById (R.id.pPosition);
playerPosition.setText (playerPositionStr);
playerTeam = (TextView) findViewById (R.id.pTeam);
playerTeam.setText (playerTeamStr);
}
}
问题是他们两个都不能同时工作。首先被调用的是唯一有效的。
我该如何解决这个问题?