how to get random string value from list - android [closed] - android

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have a few youtube API keys for my android project.
eg :
YOUTUBE_API_KEY1 = XXXXXXXXXXX
YOUTUBE_API_KEY2 = BBBBBBBBBBB
YOUTUBE_API_KEY3 = NNNNNNNNNNN
and I want that my String YOUTUBE_API_KEY = random key from the keys list.
how can I do it?
thanks

Use Random Class to get Random value
Java.util.Random
Get Random index value from list and use it.
index = new Random().nextInt(list.size())
item = list.get(index)

Related

search text in a website programmatically [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
i want my app to search a specific website(from an url) for a specific text and give me the 3 chars after that text or to search for a pattern with a placeholder and give me the first matching string. Is that possible? There is no need to display the website.
Once you download the page using something like HTTPUrlConnection, you can use a regex with your search term
Pattern p = Pattern.compile("specific text(\w\w\w)");
Matcher m = p.matcher(site_text);
boolean b = m.matches();
The three \w will be captured in a group for you to use if there's a match.

Place data from jsonobject into AutoCompleteTextview [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I need to get data from http://schedule.sumdu.edu.ua/index/json?method=getTeachers, parse it and load into AutoCompleteTextview. Any suggestions?
You need to access the service URL using an AsyncTask<>, then later on get its response into a String object.
And, parse it, using JSONObject/Json Array present in android. You will get many examples for this.
Later on you can create a String array, load your data in it, and set it for auto complete for text view.
Here is an example for this.
String[] listTeachers; // initialize this with teachers JSON data
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.layout_teacher_list, listTeachers);
tvTeacher.setAdapter(adapter);

How can i display time as '5 minute ago', 'yesterday' etc in android [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have stored time in milliseconds in android SQLite database. Now, I want to display it as messaging application displays time e.g. '5 minute ago' etc. How can I do that?
use following code:
private String calculateRelativeTime(long time) {
String relativetime = DateUtils.getRelativeTimeSpanString(time).toString();
return relativetime;
}
Try this: DateUtils.getRelativeTimeSpanString(long time, long now, long minResolution, int flags)

How to make a special call and get result in android? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I want to dial a special number like
*123#
which is a network request and get result sent by network.
Is this possible? How can I do it?
Yes you can do this:
Intent calling=new Intent(Intent.ACTION_CALL);
if ( phno.contains( "#" ))
phno = Uri.encode(phno+"#");
calling.setData(Uri.parse("tel:"+( phno ) ) );
startActivity(calli);
Note:
Here phno is String that contains phone number like *123# or 123456789

How to get the answers in String Array (ie) Vector? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
This is my code:
blanks=new EditText(this);
String values =blanks.getText().toString();
answers.put(relative.getId(),answer);
if(answer[0].equals(values)) {
Toast.makeText(this,"Match!", Toast.LENGTH_LONG).show();
}
Your code makes no sense. You crate a new EditText field, and then immediately get the text. But this will always be null.

Categories

Resources