到目前为止,我已经完成了从 ListView 中选择我想要的数据并使用以下代码打开下一个活动的困难。
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> listView, View view,
int position, long id) {
// Get the cursor, positioned to the corresponding row in the result set
Cursor cursor = (Cursor) listView.getItemAtPosition(position);
String playerName =
cursor.getString(cursor.getColumnIndexOrThrow("Player_Name"));
Toast.makeText(getApplicationContext(),
playerName, Toast.LENGTH_SHORT).show();
Intent in = new Intent(context, PlayerStatsActivity.class);
in.putExtra ("Name", playerName);
startActivity(in);
finish();
}
});
PlayerStatsActivity 类
public void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.statseditor);
dbHelper = new PlayerStatsDatabase(this);
dbHelper.open();
Bundle extras = getIntent().getExtras();
if(extras !=null){
String value = extras.getString("Name");
}
//Clean all data
// dbHelper.deleteAllStats();
//Add some data
//dbHelper.insertSomeCountries();
//Generate ListView from SQLite Database
//displayListView();
// list = getListView();
String PlayerNameText = extras.getString("Name");
btnSave2 = (Button) findViewById(R.id.btnSaveStats);
btnClear = (Button) findViewById(R.id.btnClearStats);
txtGoalsScored = (EditText) findViewById(R.id.txtGoal);
txtMinutesPlayed = (EditText) findViewById(R.id.txtMinPlayed);
txtSubstituteIn = (EditText) findViewById(R.id.txtSubIn);
txtSubstituteOut = (EditText) findViewById(R.id.txtSubOut);
radioSubIn = (RadioButton) findViewById (R.id.rdoSubIn);
radioSubOut = (RadioButton) findViewById (R.id.rdoSubOut);
playerRating = (RatingBar) findViewById (R.id.ratingBar1);
playerName = (TextView) findViewById (R.id.textView1);
playerName.setText(PlayerNameText);
我希望playerName
从上一个活动中选择的字符串显示在playerName TextView
. 以上是我尝试过但PlayerNameText
返回空值的方法。
我已经有了
String value = extras.getString("name");
}
这应该得到我的 playerName String 我只需要调用我的 playerName textfeild 我想但不知道怎么做。