I'm having trouble with enabling buttons while the onTouchEvent is active. In my app the user is supposed to press anywhere on the screen to see a text and while pressing the screen press a button. The problem is that while the onTouchEvent is active the buttons doesnt work. is there anyway to enable buttons while the onTouchEvent is active?
My code for the button and onToch looks like this.
public void correctWord(){
correct_btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
theWord.setText(((global_rules) getApplication()).NewWord(getApplicationContext()));
}
});
}
public boolean onTouchEvent(MotionEvent event){
switch (event.getAction()){
case MotionEvent.ACTION_DOWN:
if(enableTouch) {
holdToView.setVisibility(View.INVISIBLE);
theWord.setVisibility(View.VISIBLE);
}
break;
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
if(enableTouch) {
holdToView.setVisibility(View.VISIBLE);
theWord.setVisibility(View.INVISIBLE);
}
break;
}
return false;
}
edit, added the .xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/bg_1">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rätt"
android:id="#+id/correct_btn"
style="#style/btn_style2"
android:layout_alignTop="#+id/skip"
android:layout_alignLeft="#+id/holdToView"
android:layout_alignStart="#+id/holdToView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text=""
android:id="#+id/theWord"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="invisible"
android:textStyle="bold"
android:textSize="40dp"
android:textColor="#ffffff" />
</RelativeLayout>
Related
I have a microphone button in my app with which user inputs voice. It is using an OnTouchListener to detect whether user holds down the button or not. If they hold the button but drag their finger outside the button, MotionEvent still considers action as "ACTION_DOWN", even if they touch near the edge of the screen, as long as they don't stop touching. We need to change that so if the user drags their finger off of the button then MotionEvent picks up as "ACTION_UP".
recordBtn.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View view, MotionEvent motionEvent) {
switch (motionEvent.getAction()) {
//User stops touching the button.
case MotionEvent.ACTION_UP:
if(isRecording) {
stopRecording();
isRecording = false;
}
break;
//User touches the button.
case MotionEvent.ACTION_DOWN:
if(!isRecording) {
startRecording();
isRecording = true;
}
break;
}
return false;
}
});
XML:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.9">
<TextView
android:id="#+id/recordText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/custom_button"
android:layout_centerHorizontal="true"
android:layout_marginStart="8dp"
android:layout_marginTop="195dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:gravity="center"
android:fontFamily="sans-serif"
android:text="#string/hold_the_mic_and_record"
android:textColor="#color/white"
android:textSize="20sp"/>
<Button
android:id="#+id/custom_button"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_centerHorizontal="true"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:background="#drawable/microphone" />
</RelativeLayout>
Here is required screen design:
As per the above screenshot, I need to design the layout: when i click on add button of recyclerview item row, add options need to show.
Here is my XML code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/cell"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorLightWhite">
<LinearLayout
android:id="#+id/ll_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="visible"
android:layout_marginRight="#dimen/default_margin"
android:layout_marginLeft="#dimen/default_margin"
android:layout_marginTop="#dimen/default_margin"
android:layout_marginBottom="#dimen/default_margin"
android:weightSum="100">
<EditText
android:id="#+id/et_add_member"
android:layout_width="wrap_content"
android:layout_weight="95"
android:layout_height="42dp"
android:padding="#dimen/padding_8"
android:hint="Person"
android:background="#drawable/edit_box"/>
<ImageView
android:id="#+id/iv_addMember"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_gravity="center"
android:layout_marginLeft="#dimen/default_margin"
android:layout_centerVertical="true"
android:layout_weight="5"
android:src="#drawable/add_x" />
</LinearLayout>
<LinearLayout
android:id="#+id/include_add"
android:layout_width="210dp"
android:layout_height="wrap_content"
android:layout_below="#+id/ll_main"
android:layout_alignTop="#+id/ll_main"
android:layout_marginTop="35dp"
android:layout_marginRight="#dimen/margin_10"
android:gravity="center"
android:layout_alignParentRight="true"
android:orientation="vertical"
android:visibility="gone">
<include layout="#layout/include_members" />
</LinearLayout>
</RelativeLayout>
Here is Adapter Code of showing the popup:
holder.ivAddMember.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
holder.include_add.setVisibility(View.VISIBLE);
}
});
include_add LinearLayout is the pop code, but I'm not able to get the exact UI with this code.
Can anyone please suggest me how to show pop on top of respective item click, how to close popup at previously click item position & Popup design as well.
You have to create xml file under menu in res folder and then, make function like below to show pop-up on desired location
public void showPopup() {
PopupMenu popup = new PopupMenu(context, <PASS ID WHERE YOU WISH TO SHOW POPUP>);
popup.getMenuInflater().inflate(R.menu.menu_option, popup.getMenu());
Object menuHelper;
Class[] argTypes;
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.member:
// call member class or function here
return true;
case R.id.guest:
// call Guest class or function here
return true;
case R.id.my_buddies:
// call My Buddies class or function here
return true;
}
return true;
}
});
popup.show();
}
Hope you understand.
I have created an application in which there is a button which moves on touching it .
Now for onTouch I have implemented A different class.There are 2 classes one is main CircleMActivity.java and another for onTouch.
Now the app is running fine but there is one problem. When I am clicking on the button and moving it It is moving but there is a gap between the button and the screen touch.
What I want is to move it exactly where I touch it NOT at some distance later OR you can think that I want to move it at exact the cursor position.
How should I achieve it ?
Code:
CircleMActivity.java:
public class CircleMActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_circle_m);
Button b=(Button)findViewById(R.id.btn1);
MultiTouch mtb=new MultiTouch(this);
b.setOnTouchListener(mtb);
}
}
MultiTouch.java:
public class MultiTouch implements OnTouchListener{
float mPrevX,mPrevY;
CircleMActivity cm;
public MultiTouch(CircleMActivity circleMActivity) {
// TODO Auto-generated constructor stub
cm=circleMActivity;
}
#Override
public boolean onTouch(View arg0, MotionEvent arg1) {
// TODO Auto-generated method stub
float currentX,currentY;
int action=arg1.getAction();
switch(action){
case MotionEvent.ACTION_DOWN:
mPrevX = arg1.getX();
mPrevY = arg1.getY();
break;
case MotionEvent.ACTION_MOVE:
currentX = arg1.getRawX();
currentY = arg1.getRawY();
MarginLayoutParams marginParams = new MarginLayoutParams( arg0.getLayoutParams());
marginParams.setMargins((int)( currentX - mPrevX), (int)( currentY - mPrevY),0, 0);
LayoutParams layoutParams = new LinearLayout.LayoutParams(marginParams);
arg0.setLayoutParams(layoutParams);
break;
case MotionEvent.ACTION_CANCEL:
break;
case MotionEvent.ACTION_UP:
break;
}
return true;
}
}
activity_circle.xml:
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="#000000"
android:weightSum="100">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="4.95"
android:background="#fff"
android:orientation="vertical" >
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="X coord"
android:textColor="#ff00ee"
android:inputType="number" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Y coord"
android:textColor="#ff00ee"
android:inputType="number" />
<EditText
android:id="#+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Radius"
android:textColor="#ff00ee"
android:inputType="number" />
<EditText
android:id="#+id/editText4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:textColor="#ff00ee"
android:hint="Colour"
android:inputType="number" />
</LinearLayout>
<Button
android:id="#+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="4.95"
android:background="#drawable/custom" />
"
</LinearLayout>
So how should I achieve it ?
It is a simple coordinates maths . In your
case MotionEvent.ACTION_DOWN:
mPrevX = arg1.getX();
mPrevY = arg1.getY();
break;
Make
mPrevY = arg1.getY()+250;
Well It will go out of the child linear layout but it is looking good !
I'm trying to develop a riddle game with levels. First level is in "OneActivity.java" and "activity_one.xml" 2nd level on "TwoActivity.java" and "activity_two.xml" and so on. After the user types the answer to the question in level one, a toast display with "Correct" is displayed if the answer is correct and "Wrong" if it's incorrect. Now, how do I automatically go to next level if the answer is correct but remain on same level until the user inputs the correct answer. Here's my OneActivity.java and activity_one.xml
OneActivity.java:
package com.golo.user.gaunkhanekatha;
import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class OneActivity extends Activity {
public Button check;
public EditText typeh;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_one);
check = (Button)findViewById(R.id.check); //R.id.button is the id on your xml
typeh = (EditText)findViewById(R.id.typeh); //this is the EditText id
check.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
//Here you must get the text on your EditText
String Answer = (String) typeh.getText().toString(); //here you have the text typed by the user
//You can make an if statement to check if it's correct or not
if(Answer.equals("4") || (Answer.equals("four")))
{
//Create a Toast because it's correct
Toast.makeText(OneActivity.this, "Correct!",
Toast.LENGTH_LONG).show();
}
else{
//It's not the correct answer
Toast.makeText(OneActivity.this, "Wrong! Try Again",
Toast.LENGTH_LONG).show();
}
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_aboutus, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
activity_one.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background"
android:weightSum="1"
android:textAlignment="center"
android:id="#+id/oneque">
<TextView
android:layout_width="300dp"
android:layout_height="200dp"
android:text="What is 2+2?"
android:id="#+id/que"
android:width="255dp"
android:textSize="30dp"
android:layout_margin="50dp"
android:textStyle="italic"
android:gravity="center" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/typeh"
android:layout_gravity="center_horizontal"
android:text="Type Here" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Check Answer"
android:id="#+id/check"
android:layout_gravity="center_horizontal" />
</LinearLayout>
activity_level.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="30dp"
android:layout_weight="1"
android:onClick="moveToOneActivity"
android:background="#drawable/one" />
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="30dip"
android:layout_weight="1"
android:onClick="moveToTwoActivity"
android:background="#drawable/two" />
<Button
android:id="#+id/button3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="30dip"
android:layout_weight="1"
android:onClick="moveToThreeActivity"
android:background="#drawable/three" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:id="#+id/button4"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="30dp"
android:layout_weight="1"
android:onClick="moveToFourActivity"
android:background="#drawable/four" />
<Button
android:id="#+id/button5"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="30dip"
android:layout_weight="1"
android:onClick="moveToFiveActivity"
android:background="#drawable/five" />
<Button
android:id="#+id/button6"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="30dip"
android:layout_weight="1"
android:onClick="moveToSixActivity"
android:background="#drawable/six" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:id="#+id/button7"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="30dp"
android:layout_weight="1"
android:onClick="moveToSevenActivity"
android:background="#drawable/seven" />
<Button
android:id="#+id/button8"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="30dip"
android:layout_weight="1"
android:onClick="moveToEightActivity"
android:background="#drawable/eight" />
<Button
android:id="#+id/button9"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="30dip"
android:layout_weight="1"
android:onClick="moveToNineActivity"
android:background="#drawable/nine" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:id="#+id/button10"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="30dp"
android:layout_weight="1"
android:onClick="moveToTenActivity"
android:background="#drawable/ten" />
<Button
android:id="#+id/button11"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="30dip"
android:layout_weight="1"
android:onClick="moveToElevenActivity"
android:background="#drawable/eleven" />
<Button
android:id="#+id/button12"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="30dip"
android:layout_weight="1"
android:onClick="moveToTwelveActivity"
android:background="#drawable/twelve" />
</LinearLayout>
</LinearLayout>
if(Answer.equals("4") || (Answer.equals("four")))
{
//Create a Toast because it's correct
Toast.makeText(OneActivity.this, "Correct!",
Toast.LENGTH_LONG).show();
//Here create intent to the new activity - for example
//If you wish the user will have time to see the toast, you can use a Handler with post delayed
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent newLevel= new Intent(OneActivity.this, TwoActivity.class);
startActivity(newLevel);
finish(); //finish the activity of the current level
}
}, 3000); //the code inside run() will be executed after 3 seconds so the user can see the toast
}
else
{
//It's not the correct answer
Toast.makeText(OneActivity.this, "Wrong! Try Again",
Toast.LENGTH_LONG).show();
}
To go to the second level you should add this Intent inside your correct Toast as follows :
Intent i = new Intent(OneActivity.this, TwoActivity.class);
startActivity(i);
finish();
This should be your code :
check.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
//Here you must get the text on your EditText
String Answer = (String) typeh.getText().toString(); //here you have the text typed by the user
//You can make an if statement to check if it's correct or not
if(Answer.equals("4") || (Answer.equals("four")))
{
//Create a Toast because it's correct
Toast.makeText(OneActivity.this, "Correct! Going to Level 2...",
Toast.LENGTH_LONG).show();
Intent i = new Intent(OneActivity.this, TwoActivity.class);
startActivity(i);
finish();
}
else{
//It's not the correct answer
Toast.makeText(OneActivity.this, "Wrong! Try Again",
Toast.LENGTH_LONG).show();
}
}
});
EDIT
This edit will cancel the Toast when you are on your TwoActivity.class, you have to change some stuff, I'll exaplain to you.
1.- Create a global Toast variable.
private Toast toast;
2.- Initialize it on your onCreate() like this :
toast = Toast.makeText(OneActivity.this, "", Toast.LENGTH_SHORT);
3.- Then change your two Toast messages to this :
//Correct Toast
toast.setText("Correct! Going to Level 2...");
toast.show();
//Incorrect Toast
toast.setText("Wrong! Try Again");
toast.show();
4.- You want to make a finish() to avoid the back button to return to OneActivity() so you will call it, and it calls onDestroy() so you have to add this method aswell to cancel the Toast
#Override
protected void onDestroy() {
super.onDestroy();
if(toast!= null) {
toast.cancel();
}
}
You can use intents to switch to another activity.
Intent myIntent = new Intent(this, MyActivity.class);
startActivity(myIntent);
You could simply have an if statement. If the answer is correct, create an intent and start activity two, otherwise reloop in activity one or do whatever other behaviour you want to do if the answer is wrong.
In my XML, I have a relative layout with a toggle button, and 2 groups of radio buttons.
Right now it's set so that when the radio button "spells" in the first radio button group is selected, it should bring the radio button group "spellButtons" up to the front.
However, that only works if I have touched the toggle button at least once. Ideally, I shouldn't have to touch the toggle button for my onClick code to work, especially since I intend to make the toggle button a pause button eventually.
Here's my XML:
RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
>
<ToggleButton
android:id="#+id/pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Toggle Yo" />
<RadioGroup
android:id="#+id/combatSwitchButtons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/spells"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:background="#drawable/radio"
android:button="#null"
android:textColor="#android:color/black" />
<RadioButton
android:id="#+id/summons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:background="#drawable/radio"
android:button="#null"
android:textColor="#android:color/black" />
<RadioButton
android:id="#+id/power"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:background="#drawable/radio"
android:button="#null"
android:textColor="#android:color/black" />
</RadioGroup>
<RadioGroup
android:id="#+id/spellButtons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/spell1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="hi"
android:textColor="#android:color/black"/>
<RadioButton
android:id="#+id/spell2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" " />
<RadioButton
android:id="#+id/spell3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" " />
<RadioButton
android:id="#+id/spell4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" " />
<RadioButton
android:id="#+id/drone1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" " />
<RadioButton
android:id="#+id/drone2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" " />
</RadioGroup>
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/combatSwitchButtons"
android:layout_centerVertical="true" >
</RadioGroup>
</RelativeLayout>
And here's my code
findViewById(R.id.combatSwitchButtons).bringToFront();
findViewById(R.id.pause).bringToFront();
//this sets up the toggle button which will become a pause button
findViewById(R.id.pause).setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
//TODO: Pause the game
}
});
//This is for if we click spells on the switch interface. It'll make the spell buttons appear
findViewById(R.id.spells).setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
//change the mode
game.spells=false;
game.power=false;
game.summons=true;
//add the spells buttons and the drones
if(findViewById(R.id.spellButtons).isSelected())
{
findViewById(R.id.spellButtons).bringToFront();
System.out.println("brought it to the front");
}
else{
findViewById(R.id.spellButtons).setVisibility(View.INVISIBLE);
}
//TODO: remove other buttons
}
});
In your onClickListener for spells your checking if your RadioGroup spellButtons isSelected().
If you want it to show up when you click on the spells RadioButton you dont need that if loop. Instead of using bringToFront why dont you use setVisibility()?
Something like this:
findViewById(R.id.spells).setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
//change the mode
game.spells=false;
game.power=false;
game.summons=true;
//add the spells buttons and the drones
((RadioGroup) findViewById(R.id.spellButtons)).setVisibility(View.VISIBLE);
System.out.println("brought it to the front");
}
});
And if you want to hide it when another radiobutton is clicked just setOnClickListener for that and make spellButtons visibility Invisible or Gone
Apparently I needed to bring the spellButton radio button group up to the front and set it to invisible before I ever entered the onclick listener. In the onclick listener, I could use the setVisibility(View.Visible).
My code ended up looking like
findViewById(R.id.combatSwitchButtons).bringToFront();
findViewById(R.id.pause).bringToFront();
findViewById(R.id.spellButtons).bringToFront();
findViewById(R.id.spellButtons).setVisibility(View.GONE);
//this sets up what each button does.
findViewById(R.id.pause).setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
//TODO: Pause the game
}
});
/*ALLL the on click listeners*/
//This is for if we click spells on the switch interface. It'll make the spell buttons appear
findViewById(R.id.spells).setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
//change the mode
game.spells=false;
game.power=false;
game.summons=true;
//add the spells buttons and the drones
findViewById(R.id.spellButtons).setVisibility(View.VISIBLE);
//TODO: remove other buttons
}
});