我試圖從列表視圖中獲取字符串值並將其放入另一個視圖。我已經成功地爲我的第一個listview做到了這一點,但它似乎不適用於我的第三個。 (我設法讓它工作,但它停止工作,因爲我不能理解的原因)我使用完全相同的方法,我試圖檢索的信息正在檢索,因爲我已經確認,而運行問題是它只是不變了。.setText方法不起作用
代碼
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();
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);
//playerTitle = (TextView) findViewById (R.id.textTitle);
playerName = (TextView) findViewById (R.id.textView1);
playerName.setText(PlayerNameText);
//playerTitle.setText (PlayerNameText);
checkBox = (CheckBox) findViewById (R.id.checkBox1);
if (checkBox.isChecked()){
checkBox.append("Booked");
}
final CharSequence checkText = checkBox.getText();
//final Context context =
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();
dipsplayPlayerName();
displayListView();
//Intent intent = new Intent(context, ListItemsActivity.class);
// startActivity(intent);
}
});
}
在我用這個方法playerName
實際上得到改變PlayerNameText
但進一步下跌,當我再次嘗試使用這個一審它不工作
private void dipsplayPlayerName() {
setContentView (R.layout.statslist);
Bundle extras = getIntent().getExtras();
PlayerNameText = extras.getString("Name");
playerTitle = (TextView) findViewById (R.id.textTitle);
playerTitle.setText (PlayerNameText);
}
任何想法?沒有LogCat作爲應用程序不會崩潰
你在哪裏首先實例化'意圖'發送?你確認「名稱」在那裏有價值嗎? – codeMagic 2013-04-20 19:48:13
是的,因爲我說過,該方法的第一個實例按預期工作。而如果我檢查「名稱」,它運行時,它有我正在尋找的價值。 – b0w3rb0w3r 2013-04-20 19:54:07
您是否曾經通過創建Activity的新實例或調用invalidate()來重新創建'view'?它有點混淆哪部分是和不在這裏工作 – codeMagic 2013-04-20 19:54:56