Search code examples
androidsettext

.setText method will not work


I'm trying to get a string value from a listview and put into another view. I've managed to do this successfully for my first listview but it won't seem to work for my third. ( I managed to get it to work but its stopped working now for reasons I cant understand) I am using the exact same method and the information i'm trying to retrieve is being retrieved as I have confirmed while running the problem is its just not getting changed.

Code

 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);
        }
    });
 }

In this first instance where I use this method playerName actually gets changed to PlayerNameText But further down when I try to use it again it doesnt work

private void dipsplayPlayerName() {
    setContentView (R.layout.statslist);
    Bundle extras = getIntent().getExtras();
    PlayerNameText = extras.getString("Name"); 
     playerTitle = (TextView) findViewById (R.id.textTitle);
     playerTitle.setText (PlayerNameText);

}

Any ideas? The is no LogCat as the app doesnt crash


Solution

  • Put the text data you received into a field and use it instead of getting it from the intent again.

    Also, check that displayListView() doesn't change the textView.