gpt4 book ai didi

android - .setText 方法将不起作用

转载 作者:行者123 更新时间:2023-11-29 00:30:19 25 4
gpt4 key购买 nike

我正在尝试从 ListView 中获取字符串值并将其放入另一个 View 中。我已经为我的第一个 ListView 成功地做到了这一点,但它似乎不适用于我的第三个。 (我设法让它工作但由于我无法理解的原因它现在停止工作)我正在使用完全相同的方法并且正在检索我试图检索的信息正如我在运行问题时确认的那样只是不是正在改变。

代码

 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,因为应用程序不会崩溃

最佳答案

将您收到的文本数据放入一个字段中并使用它,而不是再次从 Intent 中获取它。

此外,检查 displayListView() 是否不会更改 textView。

关于android - .setText 方法将不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16124425/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com