0

I have a very basic android app that has 1 tab, with three sub sections on it. Section 1, 2, and 3. The code below tells the app to display "1", "2", or "3" in a string depending on which section is selected. I added an if statement to see if I could alter the output, but it appears to be ignoring the condition. When I debug the code using logcat it shows the value of dummyTextView is "1", but it does not step into the condition and change it to the "Peeshaw" line i created. Anyone know why this is happening?

@Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main_dummy,
                    container, false);
            TextView dummyTextView = (TextView) rootView
                    .findViewById(R.id.section_label);
            dummyTextView.setText(Integer.toString(getArguments().getInt(
                    ARG_SECTION_NUMBER)));

            if (dummyTextView.getText() == "1")
            {
                dummyTextView.setText("Peeshaw");
            }

            if (dummyTextView.getText().toString() == "1")
            {
                dummyTextView.setText("Peeshaw");
            }

            return rootView;
        }
snapplex
  • 851
  • 3
  • 13
  • 27
  • http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java/513839#513839 – Alexander_Winter Feb 07 '14 at 10:01
  • @Alexander_Winter, wow! Guess there is a bigger learning curve than I expected. if (dummyTextView.getText().equals("1")) { dummyTextView.setText("Peeshaw"); } This is what I had to do, so it would work. Thanks for your help and quick response. – snapplex Feb 07 '14 at 10:19

1 Answers1

1

use .equals() to compare string insted of ==

if(dummyTextView.getText().equals("1"))
null pointer
  • 5,874
  • 4
  • 36
  • 66