0

我有两种方法要在我的 onlick 中运行。第一种方法是显示一个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);
}
}

问题是它们不能同时工作。第一个被调用的是唯一有效的。

我将如何解决这个问题?可以将它们全部放在同一个方法中吗?

4

0 回答 0