-1

Hi So I'm trying to make an application for a project I'm working on that involves google cloud Api. Basically the application will scan the name of a game (Could be anything but using games as an example in this case) and the activity it moves to will populate with a textview based on the game name scanned. I'll provide code below but basically all I have at this moment is that the application scans the logo and it'll appear in the ActionBar of the next activity, is there a way to populate the TextView's that I'm going to place in based on the Title returned to the Action bar? Or is there a way to set it based on the text sent in the intent?

Code for the logo sender. This is just the intent basically. The variable text is the text that's passed in through the cloud vision API.

 public void run() {
  Toast.makeText(getApplicationContext(),
  text.getText(), Toast.LENGTH_LONG).show();

 Intent intent = new Intent(LogoDetectionActivity.this, GameInfoActivity.class);
 intent.putExtra("TITLE", text.getText());
 startActivity(intent);
}

Code from the new activity to set to actionbar:

public class GameInfoActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_game_info);

    String title = getIntent().getExtras().getString("TITLE");
    getSupportActionBar().setTitle(title);

}

public void goToLogoDetection(View view) {
    Intent intent = new Intent(this, LogoDetectionActivity.class);
    startActivity(intent);
}
}

If anyone could help me out here it'd be greatly appreciated!

EDIT: Just because I seemed to of caused some confusion, what I want is to have the contents of a TextView change based on the Title, but more than just the title into the Textview. For example if the Title was to do with mario the contents of the textview would include information about Mario and not jsut the title "Mario". Same for any other game. Of course I know I'd have to program in this text of what goes into it myself but thats another story.

Alex Wong
  • 13
  • 5
  • Not clear how your code relates to Google vision – OneCricketeer Dec 03 '17 at 17:51
  • With your edit, what's preventing you from doing a method like `setText(getInformation("Mario"))`? – OneCricketeer Dec 03 '17 at 18:27
  • It relates to Google Vision as it uses Google vision to supply the text variable. Through taking a picture of a logo. I just didn't include the code for it because I thought it'd be a bit too long. As for that Method, is there a way to use this method based on the "text" variable returned from google vision? The reason why I'm asking is because I'm still a quite beginner level student so I don't know the in's and outs of android development. – Alex Wong Dec 03 '17 at 18:31
  • These are Java basics of calling methods. If you are returned a string, you can manipulate that however you wish before applying it to a TextView – OneCricketeer Dec 03 '17 at 18:33
  • I see, although that method you posted above, wouldn't that just return the word "Mario" into the textview and nothing else? – Alex Wong Dec 03 '17 at 18:34
  • No, `getInformation` can do anything. Including returning the input given, but that seems pointless – OneCricketeer Dec 03 '17 at 18:36

3 Answers3

0

I don't know if I understood the question correctly. Does that answer your question?

textView.setText(getSupportActionBar().getTitle());
Alex Covizzi
  • 971
  • 8
  • 9
  • Sadly now, as I said in my answer to a comment below I sort of want it to write more than just the title into the textview. I want it to write stuff into the textview based on the text inputted from the "text" variable. So for Mario it'd be one thing and then for Zelda it'd be another thing. – Alex Wong Dec 03 '17 at 18:18
0

just directly use the string passed in the intent. Suppose your TextView object is textView, then

textView.setText(title);

No need to take it from action bar.

Shahrukh khan
  • 196
  • 1
  • 7
  • The thing about that is, That'll just set the text in the Textview as the Title correct? I want it to populate the TextView with something more. So as an example say if the title was say "Mario" then the TextView would say like "Mario is a action platformer style of video game that was developed in xxxx and is spread across almost all consoles" Something like that. If you know what I mean. – Alex Wong Dec 03 '17 at 18:17
  • You can put a switch case on the title. Like if the case is mario, you populate the text view as textView.setText(“whatever you wish to write”). – Shahrukh khan Dec 03 '17 at 18:40
  • I see, would you know of any good examples I can look at for reference to this? Or how exactly it'd be formatted? I think I understand how a switch case works. – Alex Wong Dec 03 '17 at 18:46
  • I guess you can implement a normal switch case, if the title is mario do textView.setText(“hi i am mario”). And if it’s luigi do textView.setText(“hi i am luigi”). I hope you get the gist. – Shahrukh khan Dec 03 '17 at 18:53
  • I sort of get you, I think it should hopefully enough to at least get the Ball Rolling. I need to wrap my head around switch statements. But I think I can try enough. Thanks. – Alex Wong Dec 03 '17 at 18:56
  • I think I did one. :) Says it doesn't change the public score but is recorded. – Alex Wong Dec 03 '17 at 19:05
0

as far as i understood your question , you want to take the title from your activity's actionbar and want to set in a textview , this you can achieve by doing

String actionBarTitle = getSupportActionBar().getTitle() ;
yourTextView.setText(actionBarTitle);
Sachin Rajput
  • 4,326
  • 2
  • 18
  • 29