Created
December 15, 2014 10:14
-
-
Save taycaldwell/e934633e58e15d687046 to your computer and use it in GitHub Desktop.
Using riot-api-java within Android app. (AsyncTask)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends Activity{ | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
final Button button = (Button) findViewById(R.id.button1); | |
button.setOnClickListener(new View.OnClickListener() { | |
public void onClick(View v) { | |
FetchSummonerTask summonerTask = new FetchSummonerTask(); | |
summonerTask.execute("summoner name"); | |
} | |
}); | |
} | |
public class FetchSummonerTask extends AsyncTask<String, Void, Summoner> { | |
@Override | |
protected Summoner doInBackground(String... params) { | |
try { | |
Summoner summoner = ((GlobalClass)getActivity().getApplication()).getApi() | |
.getSummonerByName(params[0]) | |
.get(params[0].replaceAll("\\s+", "").toLowerCase()); | |
if(summoner != null) { | |
return summoner; | |
} | |
} catch (RiotApiException e) { | |
e.printStackTrace(); | |
} | |
return null; | |
} | |
@Override | |
protected void onPostExecute(Summoner result) { | |
super.onPostExecute(result); | |
if(result != null) { | |
TextView dis = (TextView) findViewById(R.id.textView1); | |
dis.setText(String.valueOf((result.getSummonerLevel()))); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment