Hello I want to create a list. On long-press on the toolbar will be shown option to select all and delete selected. I don't know whether I should RadioGroup and hide button or use listView and create own row example and there add radio button.
4 Answers
Where I cant get very specific, I can say, usually to achieve your own specific goals creating your own row will prove beneficial to your end goal. Rather then hiding a RadioGroup

- 3
- 3
Default standard android behavior is Contextual Action Bar(which I can interpret) should come when user long presses an item list
as in
One of the many resources are
https://androidkennel.org/contextual-toolbar-actionbar-tutorial/

- 888
- 2
- 9
- 28
-
Thank you very much. I don't know how it is called – Michał Urban Apr 17 '17 at 15:39
-
I created this using your second link. How can I manage this overlay toolbar, changing color and removing pink line on the bottom – Michał Urban Apr 20 '17 at 21:28
-
Well u need to customize CAB with http://stackoverflow.com/questions/27458421/how-to-customize-the-contextual-action-bar-using-appcompat-in-material-design .In order to cutomize list item try to play with item-selector as here
I have a little problem with understanding menuInflater. This class instantiate menu XML files into Menu objects. But there set new menu
public boolean onCreateActionMode(ActionMode actionMode, Menu menu) { //when this method is going to be made? Menu is int the toolbar and ListView isn't connected with toolbar so which menu I get in the next next line?
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.toolbar_cab, menu); // in this line set a new menu
return true;
}`

- 5
- 5
To hide RadioButton from RadioGroup is very simple. You just write btnRadio1.setVisibility(View.INVISIBLE);. BUT you have to know this rule: If you have, for example, 4 RadioButtons in RadioGroup, you can make them invisible in reverse order only! I mean the order they are defined in RadioGroup in your layout .xml file. It is impossible to hide btnRadio3 only, and btnRadio4 to be visible! You have to hide btnRadio3 and btnRadio4. Or only btnRadio4. So, if you want to hide 1 button, it is button 4. If you want to hide 2 buttons - they are 4 and 3. If you want to hide 3 buttons they are 4, 3, and 2. All other combinations, simply doesn't work. Here is code from my Quiz app, where every question may have from 2 to 6 answers. The answers of current question are stored in array of strings answers [].
RadioButton btnAnswer1;
RadioButton btnAnswer2;
RadioButton btnAnswer3;
RadioButton btnAnswer4;
RadioButton btnAnswer5;
RadioButton btnAnswer6;
RadioGroup radioGroup;
// onCreate activity
btnAnswer1 = (RadioButton) findViewById(R.id.btnAnswer1);
btnAnswer2 = (RadioButton) findViewById(R.id.btnAnswer2);
btnAnswer3 = (RadioButton) findViewById(R.id.btnAnswer3);
btnAnswer4 = (RadioButton) findViewById(R.id.btnAnswer4);
btnAnswer5 = (RadioButton) findViewById(R.id.btnAnswer5);
btnAnswer6 = (RadioButton) findViewById(R.id.btnAnswer6);
radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
radioGroup.clearCheck();
btnAnswer1.setVisibility(View.VISIBLE);
btnAnswer2.setVisibility(View.VISIBLE);
numberOfAnswers = 2; //at least 2 answers
//if 3-d element is empty i.e. 2 answers only
//i.e. buttons 3,4,5,6 must be hidden
if (answers[2].isEmpty()) {
btnAnswer3.setVisibility(View.INVISIBLE);
btnAnswer4.setVisibility(View.INVISIBLE);
btnAnswer5.setVisibility(View.INVISIBLE);
btnAnswer6.setVisibility(View.INVISIBLE);
} else {
btnAnswer3.setVisibility(View.VISIBLE);
numberOfAnswers = 3;
}
if (answers[3].isEmpty()) {
btnAnswer4.setVisibility(View.INVISIBLE);
btnAnswer5.setVisibility(View.INVISIBLE);
btnAnswer6.setVisibility(View.INVISIBLE);
} else {
btnAnswer4.setVisibility(View.VISIBLE);
numberOfAnswers = 4;
}
if (answers[4].isEmpty()) {
btnAnswer5.setVisibility(View.INVISIBLE);
btnAnswer6.setVisibility(View.INVISIBLE);
} else {
btnAnswer5.setVisibility(View.VISIBLE);
numberOfAnswers = 5;
}
if (answers[5].isEmpty()) {
btnAnswer6.setVisibility(View.INVISIBLE);
} else {
btnAnswer6.setVisibility(View.VISIBLE);
numberOfAnswers = 6;
}
And here is xml file:
<ScrollView
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_marginLeft="5dip"
android:orientation="vertical">
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/btnAnswer1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<RadioButton
android:id="@+id/btnAnswer2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<RadioButton
android:id="@+id/btnAnswer3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<RadioButton
android:id="@+id/btnAnswer4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<RadioButton
android:id="@+id/btnAnswer5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<RadioButton
android:id="@+id/btnAnswer6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</RadioGroup>
</ScrollView>

- 191
- 2
- 5