1

I wanna make a button (say, Button1) viewable and usable only when a certain thing appears on the internet. For example if "A" appears on the internet on the page I mention in the code, the button 'button1' with the text 'Vote for A' should appear and other buttons (say, Button2 & Button3) should disappear.

How do I write the code for this?

Andy G
  • 19,232
  • 5
  • 47
  • 69
Paresh Kalinani
  • 93
  • 1
  • 11

3 Answers3

0

Maybe this will help you :

//x is a string

if(x == "test"){

Button2.setVisibility(false);
Button2.setClickable(false);
Button3.setVisibility(false);
Button3.setClickable(false);

}

else{

//Do something else

}

To load something you can check here

Load URL

Or here :

Load URL2

Community
  • 1
  • 1
David
  • 840
  • 6
  • 17
  • 37
  • Don't use the == operator to compare strings, use the String.equals(String someString) function instead. – Shpongoloid Sep 09 '13 at 16:19
  • 1
    And always start with the constant: "test".equals(unknownValue), this way you don't have to test for the string being null (if unknownValue is null, than unknownValue.equals("test") will result in a NullPointerException) – Andras Balázs Lajtha Sep 09 '13 at 16:27
0

I suppose you're loading an HTML page from a remote server and act based on the content displayed to the user.

You should read the page's text and search for your text. If it's specific enough, it'll only appear in the right context: "Vote for A" will probably not be part of any script, styling or comment. If your text is "width" than you would be in huge trouble: you would have to create a parser that runs through the DOM of the page, and searches only in html content of the tags.

To load a URL you can find an example here. This will give you an input stream. You should read the stream's content, and match your string without whitespaces using a sliding window. You can figure this out, or take a look at this optimised solution.

Afterwards you only have to set the visibility property of your views with View.setVisibility(View.VISIBLE) or View.setVisibility(View.GONE);

Community
  • 1
  • 1
Andras Balázs Lajtha
  • 2,576
  • 25
  • 32
0

You can set the visibility of the button to View.VISIBLE or View.Gone based on your conditions. I hope that will do it assuming that is what you want.

khubaib
  • 535
  • 4
  • 12