writing an "if" statement in Android
<p>I'm new to Android. I'm trying to write a method that has an if statement in it.What I'm trying to get happen is "if the text in the Textview is equal to a certain value, change the background image in the layout." I know the setting background bit works, I've narrowed the problem to the If statement. in the below code showBook is a TextView, tvString is the string that holds the value of showBook. bgview is the layout id.</p>

<pre><code>        String tvString = showBook.getText().toString(); 
    bookDisp.setText(tvString); 
    View mainbg = bgview.getRootView(); 
    if(bookDisp.equals("John")){ 
    mainbg.setBackgroundResource(R.drawable.dbvjohn);
</code></pre>

<p>the problem is the line</p>

<pre><code>if(bookDisp.equals("John")){
</code></pre>

<p>it doesn't want to compare bookDisp with a string "John". It will however will work if I compare two textviews for example</p>

<pre><code>if(bookDisp.equals(newTextView)){
</code></pre>

<p>so I think the problem is the .equals bit. what code would I use to compare bookDisp with "John"? it's not <code>if(bookDisp = ("John")){</code> because Eclipse wants me to change bookDisp to a string. So what would be the proper code to compare a textview bookDisp to a string "John"?</p>

<p>Never mind folks! I figured it out, and the error wasn't in this method at all, but in another method. I had <code>+ cursor.getString(1) + " ";</code> in that method, so the strings in the textviews were displaying as "John " and the "if" statement above was looking for "John". </p>
