これまでのところ、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
null値を返します。
私は既に持っています
String value = extras.getString("name");
}
これは私のplayerName文字列を取得する必要がありますこれを私のplayerNameテキストフィールドに呼び出す必要があるだけだと思いますが、方法がわかりません。