English 中文(简体)
撰写文稿
原标题:writing an "if" statement in Android
  • 时间:2012-04-12 16:25:48
  •  标签:
  • java
  • android

I m new to Anders. 我试图书写一种在其中作陈述的方法。 我想要做到的是,“如果文本概览中的案文与某种价值相等,就改变布局中的背景形象”。 我知道背景比照工作,我把问题缩小到发言中。 下面的代码显示Book是一份文本意见,而VtvString是具有显示Book价值的扼杀。 bgview为布局。

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

问题是:

if(bookDisp.equals("John")){

它不想将书记与“John”号插图相比较。 不过,如果我比较两个案文观点,例如,它将发挥作用。

if(bookDisp.equals(newTextView)){

so I think the problem is the .equals bit. what code would I use to compare bookDisp with "John"? it s not if(bookDisp = ("John")){ 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"?

永远不会忘记民俗! 我把这一错误算出,而这一错误完全是用这种方法,而是用另一种方法。 我有<代码>+曲线(1)+“; in that means, so the strings in the textviews are showing as “John” and the “if” statement above is search for “John”。

问题回答

使用:

if ("John".equals(bookDisp.getText().toString())) {

也许希望使用:

bookDisp.getText().toString().equals("John");

a. 比较以下图象:

tvString. Equals (“John”);

You need to get the text from the TextView in order to see if it equals "John". do: bookDisp.getText().equals("John")

That should work. getText for TextViews returns an editable. Heres the class so you can work with it: Editable Class





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签