So currently I've got an activity that's to do with something called Ad-Libs, in which there is a blank space in a sentence and the user taps on it to open a popup menu to add a word into the space. Currently I have it set so that only 3 words are available and they're the same 3 words every time its pressed, however I was wondering if its possible to have those 3 words be randomly selected from a list per-say, or maybe an array-list. I'll include my code that I use for when the user taps on the empty space as well as the xml code for the popup menu, however be noted that it's basically just a simple pop up menu.
beginningtext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v){
PopupMenu heroPop = new PopupMenu(AdventureActivity.this, beginningtext);
heroPop.getMenuInflater().inflate(R.menu.heropop_menu, heroPop.getMenu());
heroPop.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
Toast.makeText(AdventureActivity.this,"You Selected : " + item.getTitle(),Toast.LENGTH_SHORT).show();
beginningtext.setText(R.string.partyMembers);
beginningtext.append(item.getTitle());
return true;
}
});
heroPop.show();//showing popup menu
}
});//closing the setOnClickListener method
And for the pop up menu xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/one"
android:title="@string/party1"/>
<item
android:id="@+id/two"
android:title="@string/party2"/>
<item
android:id="@+id/three"
android:title="@string/party3"/>
<item
android:id="@+id/four"
android:title="@string/party4"/>
</menu>
Any help with this is very much appreciated, thank you very much.