I'm trying to create a settings page for my app which has the radioGroup for 3 options to help users change the colour of the text in differrent layout/xml file. But in mysettings page I cant call the view from different layout, any idea?
Below are my codes:
Settings.Java
package com.example.sunny.mynote;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
import android.widget.EditText;
/**
* Created by Sunny on 19/04/2015.
*/
public class Settings extends Activity {
private RadioGroup RadioGroup1;
private RadioButton rdbRed, rdbBlue, rdbOrange;
private Button btnSave;
private EditText editText;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
RadioGroup1 = (RadioGroup) findViewById(R.id.RadioGroup1);
RadioGroup1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if(checkedId == R.id.rdbRed)
{
Toast.makeText(getApplicationContext(), "choice: Red",
Toast.LENGTH_SHORT).show();
}
else if(checkedId == R.id.rdbBlue)
{
Toast.makeText(getApplicationContext(), "choice: Blue",
Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(getApplicationContext(), "choice: Orange",
Toast.LENGTH_SHORT).show();
}
}
});
rdbRed = (RadioButton) findViewById(R.id.rdbRed);
rdbBlue = (RadioButton) findViewById(R.id.rdbBlue);
rdbOrange = (RadioButton) findViewById(R.id.rdbOrange);
editText = (EditText) findViewById(R.id.editText);
btnSave = (Button)findViewById(R.id.btn_Save);
btnSave.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int selectedId = RadioGroup1.getCheckedRadioButtonId();
if(selectedId == rdbRed.getId()) {
//textView.setText("You chose 'Sound' option");
} else if(selectedId == rdbBlue.getId()) {
//textView.setText("You chose 'Vibration' option");
} else {
//textView.setText("You chose 'Silent' option");
}
finish();
}
});
}
#Override
public void onBackPressed() {
}
}
and I want to FindViewbyID from this layout, an EditText from this view to be exactly
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<EditText
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/noteText"
android:singleLine="false"
android:gravity="top"
android:inputType="textImeMultiLine"
android:layout_alignParentBottom="true" />
</RelativeLayout>
I think you can create an intent with extras like this:
Intent i=new Intent(context,Class.class);
i.putExtra("ColorChoice",color);
And then extract this data from your main class with:
intent.getStringExtra("ColorChoice");
You cannot do that in your Settings.java activity if your editText is not in this activity.
You can either use intent with putExtra and getExtra like #user3624383 mentioned. (more on this here)
Or a better way would be to use SharedPreferences to save your settings even if the user exits your app and return to it later
Related
I'm learning now Java with a book "Learning Java by building Android Games" from Packt Publishers by John Horton. I'm really newbie to OOP and I have learned C for one year. I do everything as it is in the book. After I have added setOnClickListener and tried to test my App, I see "the application was closed" instead running new Activity.
Could you please help me to find out what is wrong? The book is a little bit out of a date (Jan 2015) and I had to correct some initial code to make initial errors disappear.
package com.packtpub.mathgame;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.util.Log;
public class MainActivity extends Activity implements View.OnClickListener {
private static final String TAG = MainActivity.class.getSimpleName();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState != null) {
Log.d(TAG, "onCreate() Restoring previous state");
/* restore state */
} else {
Log.d(TAG, "onCreate() No saved state available");
/* initialize app */
}
final Button buttonPlay = (Button)findViewById(R.id.buttonPlay);
buttonPlay.setOnClickListener(this);
}
#Override
public void onClick(View view) {
Intent i;
i = new Intent(this, GameActivity.class);
startActivity(i);
}
}
===============
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Play"
android:id="#+id/buttonPlay"
android:layout_marginTop="28dp"
android:layout_below="#+id/imageView"
android:layout_alignRight="#+id/button2"
android:layout_alignEnd="#+id/button2"
android:layout_alignLeft="#+id/button2"
android:layout_alignStart="#+id/imageView" />
1) You need to register the GameActivity In you AndroidManifest.xml like this
<activity
android:name=".GameActivity" />
inside the application tag
Just a note if these views arn't available your layout will look very wierd ;)
android:layout_below="#+id/imageView"
android:layout_alignRight="#+id/button2"
android:layout_alignEnd="#+id/button2"
android:layout_alignLeft="#+id/button2"
android:layout_alignStart="#+id/imageView"
Did you register GameActivity in your AndroidManifest.xml file ?
You should getId of your button onClick method only thn you can identity on which button you have click on , now you one
#Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.buttonPlay:
//write your implementation here
Toast.makeText(this, "dsfdf", Toast.LENGTH_LONG).show();
break;
case R.id.buttonPlay1:
Toast.makeText(this, "sdsdsdsd", Toast.LENGTH_LONG).show();
break;
}
}
change this:
final Button buttonPlay = (Button)findViewById(R.id.buttonPlay);
buttonPlay.setOnClickListener(this);
}
#Override
public void onClick(View view) {
Intent i;
i = new Intent(this, GameActivity.class);
startActivity(i);
}
in this:
final Button buttonPlay = (Button)findViewById(R.id.buttonPlay);
buttonPlay.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i;
i = new Intent(this, GameActivity.class);
startActivity(i);
}
});
I have just gone through the android "first app" tutorial located Here, and I want to start experimenting on my own with the stuff that tutorial taught me.
What I want to do is take the message the user writes in the first activity, and display it in a TextView element, which i have defined in the XML file for the second activity. How do I edit the properties of a text view using the java code? I have no idea how to edit any of the properties of the element, even though I know its android:id . Can anyone give me any insight into this?
TextView textView = (TextView) findViewById(R.id.id_of_the_textview);
textView.setText(yourNewText);
What I want to do is take the message the user writes in the first activity
I assume you'll use an EditText in your FirstActivity, so you have to get the text from this widget and pass it as an extra in your intent used to switch to the second activity.
In your FirstActivity onCreate method it will look like :
EditText myEditText = (EditText) findViewById(R.id.yourEditTextId);
Intent i = new Intent(this, ToClass.class);
i.putExtra("myText", myEditText.getText().toString());
startActivity(i);
And in your SecondActivity onCreate methode :
Intent intent = getIntent();
String text = intent.getExtras().getString("myText");
TextView myTextView = (TextView) findViewById(R.id.yourTextViewId);
myTextView.setText(text);
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.EditText;
public class MainActivity extends Activity {
Button button1;
String text;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
}
public void addListenerOnButton() {
button1 = (Button) findViewById(R.id.buttoncalculate);
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
EditText editText = (EditText)findViewById(R.id.editText1);
String text = editText.getText().toString();
Intent myIntent = new Intent(view.getContext(),Calculated.class);
myIntent.putExtra("mytext",text);
startActivity(myIntent);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
Calculated.java
public class Calculated extends Activity {
TextView mTextview;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.calculated);
mTextview = (TextView)findViewById(R.id.textView1);
mTextview.setText(getIntent().getStringExtra("mytext"));
}
calculated.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="42dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
Hi I currently made a game and just wish to add a simple menu for it, the are two buttons on the main menu was says English and the Other says French I have managed to get the English button working which takes me to my EnglishVersion.class but I cant seem to get my French button to work. can any one help please.
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;
public class MainMenu extends Activity {
Button English;
Button French;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_menu);
addListenerOnButton();
}
public void addListenerOnButton(){
final Context context = this;
English = (Button) findViewById(R.id.engbtn);
French = (Button) findViewById(R.id.frenbtn);
English.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View arg0) {
Intent intent = new Intent(context, EnglishVersion.class);
startActivity(intent);
}
});
}
I have tried to do this and getting and im getting an error
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;
public class MainMenu extends Activity {
Button English;
Button French;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_menu);
English.setOnClickListener(mButtonClickListener);
French.setOnClickListener(mButtonClickListener);
}
private View.OnClickListener mButtonClickListener = new View.OnClickListener() {
#Override
public void onClick(View view) {
if (view.getId()==R.id.engbtn) {
Intent intent = new Intent(context, EnglishVersion.class);
startActivity(intent);
} else if (view.getId()==R.id.frenbtn) {
Intent intent = new Intent(context, FrenchVersion.class);
startActivity(intent);
}
}
}
}
add this:
French.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(context, FrenchVersion.class);
startActivity(intent);
}
});
By the way, it's not a good way to do the internationalization.
Try to read little about it here
Supporting Different Languages
You can just create various files strings-XX.XML in your res/ directory, where XX is given language symbol like FR or EN. It will even work with your default one. So if phone user has French defined as a language, your application will take it as its.
Either use the onClick property in XML like this (for both buttons);
<Button
android:id="#+id/engbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"/>
<Button
android:id="#+id/frenbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"/>
then populate the onClick method in the activity;
public void onClick(View view) {
if (view.getId()==R.id.engbtn) {
//do something
} else if (view.getId()==R.id.frenbtn) {
//do something else
}
}
OR set the onClickListeners for both button like this;
English.setOnClickListener(mButtonClickListener);
French.setOnClickListener(mButtonClickListener);
and then define the shared click listener;
private View.OnClickListener mButtonClickListener = new View.OnClickListener() {
#Override
public void onClick(View view) {
if (view.getId()==R.id.engbtn) {
//do something
} else if (view.getId()==R.id.frenbtn) {
//do something else
}
}
}
Hope this helps!
I have an app that contains a ListView in its menu which I want to link to one activity with the same layout style but the content inside should be different after being clicked on.
The ListView contains a list of songs, and the layout of an individual item when clicked contains a Title (TextView), Lyrics (TextView), a "next_button" button, a "previous_button" button to move between songs, a "back_button" button to get back to the ListView and a "play_tune" button which plays audio for that specific song. Not all of the songs contain audio, but where the "play_tune" button lies, I would like the app icon ic_launcher-web.png showing there instead.
The XML file I would like to show (for a song with audio) is shown below:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/song"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".ScoutSongs" >
<TextView
android:id="#+id/Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:textColor="#FFFFFF"
android:textSize="20sp" />
<ImageButton
android:id="#+id/play_tune"
android:src="#drawable/play_tune"
android:contentDescription="#string/play_tune"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/Title"
android:layout_alignTop="#+id/Title" />
<ScrollView
android:id="#+id/LyricsView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/back_button"
android:layout_alignLeft="#+id/Title"
android:layout_alignRight="#+id/play_tune"
android:layout_below="#+id/play_tune" >
<TextView
android:id="#+id/Lyrics"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF" />
</ScrollView>
<Button
android:id="#+id/back_button"
android:layout_width="65dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignRight="#+id/LyricsView"
android:text="#string/back"
android:textColor="#FFFFFF" />
<Button
android:id="#+id/previous_button"
android:layout_width="95dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/back_button"
android:layout_alignBottom="#+id/back_button"
android:layout_alignLeft="#+id/LyricsView"
android:text="#string/previous"
android:textColor="#FFFFFF" />
<Button
android:id="#+id/next_button"
android:layout_width="95dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/previous_button"
android:layout_alignBottom="#+id/previous_button"
android:layout_toRightOf="#+id/previous_button"
android:text="#string/next"
android:textColor="#FFFFFF" />
My current SongActivity.java file is shown below:
package com.lmarshall1995.scoutsongs;
import com.lmarshall1995.scoutsongs.R;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.Toast;
public class SongActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.song);
Intent i = getIntent();
String Title = i.getStringExtra("Title");
String Lyrics = i.getStringExtra("Lyrics");
String TuneToast = i.getStringExtra("TuneToast");
String Tune = i.getStringExtra("Tune");
setupNavigationButton();
Toast toast = Toast.makeText(this, TuneToast , Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
final Button back = (Button) findViewById(R.id.back_button);
back.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
finish();
}
});
final Button previous = (Button) findViewById(R.id.previous_button);
previous.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent previousIntent = new Intent(SongActivity.this, SongActivity.class);
SongActivity.this.startActivity(previousIntent);
finish();
}
});
final Button next = (Button) findViewById(R.id.next_button);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent nextIntent = new Intent(SongActivity.this, SongActivity.class);
SongActivity.this.startActivity(nextIntent);
finish();
}
});
final ImageButton play_tune = (ImageButton) findViewById(R.id.play_tune);
play_tune.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ImageButton play_tune = (ImageButton) findViewById(R.id.play_tune);
play_tune.setOnClickListener(new View.OnClickListener() {
MediaPlayer mp = MediaPlayer.create(SongActivity.this, Tune);
public void onClick(View arg0) {
if (mp.isPlaying()) {
mp.stop();
mp.prepareAsync();
mp.seekTo(0);
} else {
mp.start();
}
}
});
}
});
}
private void setupNavigationButton() {}
}
And my Menu.java for my ListView is here:
package com.lmarshall1995.scoutsongs;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ListView;
public class Menu extends ListActivity{
String classes[] = {"Song_AliceTheCamel_Activity", "Song_Bingo_Activity",
"Song_CampfiresBurning_Activity", "Song_DownAtTheStation_Activity",
"Song_EverywhereWeGo_Activity", "Song_FeFi_Activity",
"Song_GingGangGooly_Activity", "Song_HeadShouldersKneesToes_Activity",
"Song_IfYoureHappyAndYouKnowIt_Activity", "Song_JoesButtonFactory_Activity",
"Song_Kumbaya_Activity", "Song_LittleGreenFrog_Activity",
"Song_Meatball_Activity", "Song_NationalAnthem_Activity",
"Song_OldMacDonald_Activity", "Song_PizzaHut_Activity",
"Song_QuartermastersStores_Activity", "Song_RowRowRowYourBoat_Activity",
"Song_ShineUpYourButtons_Activity", "Song_ThreeBlindJellyfish_Activity",
"Song_Underwear_Activity", "Song_Valerie_Activity", "Song_Worms_Activity",
"Song_XCommissionersInTheTown_Activity", "Song_YogiBear_Activity",
"Song_ZipADeeDooDah_Activity"};
String items[] = {"Alice The Camel", "Bingo", "Campfire\'s Burning", "Down At The Station",
"Everywhere We Go", "Fe Fi", "Ging Gang Gooly", "Head, Shoulders, Knees & Toes",
"If You\'re Happy And You Know It", "Joe\'s Button Factory", "Kumbaya",
"Little Green Frog", "Meatball", "National Anthem (UK)", "Old MacDonald", "Pizza Hut",
"Quartermaster\'s Stores", "Row, Row, Row Your Boat", "Shine Up Your Buttons",
"Three Blind Jellyfish", "Underwear", "Valerie", "Worms",
"X-Commissioner\'s In The Town", "Yogi Bear", "Zip A Dee Doo Dah"};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
final ImageButton settings = (ImageButton) findViewById(R.id.settings_button);
settings.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent settingsIntent = new Intent(Menu.this, Settings.class);
Menu.this.startActivity(settingsIntent);
}
});
final ImageButton back = (ImageButton) findViewById(R.id.exit_button);
back.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
finish();
}
});
setListAdapter(new ArrayAdapter<String>(Menu.this, android.R.layout.simple_list_item_1, items));
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Intent i = new Intent(Menu.this, SongActivity.class);
i.putExtra("Title", "Song_" + classes + "_Title");
i.putExtra("Lyrics", "Song_" + classes + "_Lyrics");
i.putExtra("TuneToast", "To be sung in the tune of \n" + classes);
startActivity(i);
}
}
All of my Titles and Lyrics are currently in my Values\strings.xml file.
How can I make all my songs be in one "SongActivity" class after being selected in ListView? I believe that if you have to write anything out more than once, there should be an easier way to do it.
Edit: How can I make MediaPlayer mp = MediaPlayer.create(SongActivity.this, Tune); and String Tune = i.getStringExtra("Tune"); work together?
When selecting a list item, call your SongActivity with extras in the intent, such as SongName and other params you need. Then read it and populate the fields accordingly.
onItemSelected method:
Intent i = new Intent(this, SongActivity.class);
i.putExtra("songName", "Song name here"); //get song name from the item selected
....
startActivity(i);
In your SongActivity class:
onCreate(...){
Intent i = getIntent();
String songName = i.getStringExtra("songName");
...
}
Edit: this way all other fixed text can be included in SongActivity, just send the song to that activity
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
String song = l.getItemAtPosition(position).toString(); //this is the selected song
Intent i = new Intent(Menu.this, SongActivity.class);
i.putExtra("Song", song);
startActivity(i);
}
I use example from http://startandroid.ru/uroki/vse-uroki-spiskom/128-urok-67-dialogi-progressdialog.html
We have two buttons.
onClick first button - show some progress dialog.
onClick second button - show some progress dialog.
If I click fast on first button after that on second button then it is showing two progress dialogs. How to disable this posibility?(Is it good to disable this two buttons when is clicked one of them, or disable LinearLayout, ...)
strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="dflt">Обычный</string>
<string name="horiz">Горизонтальный</string>
<string name="app_name">ProgressDialog</string>
</resources>
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<Button
android:id="#+id/btnDefault"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/dflt"
android:onClick="onclick">
</Button>
<Button
android:id="#+id/btnHoriz"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/horiz"
android:onClick="onclick">
</Button>
</LinearLayout>
MainActivity.java:
package ru.startandroid.develop.p0671progressdialog;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
public class MainActivity extends Activity {
ProgressDialog pd;
Handler h;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void onclick(View v) {
switch (v.getId()) {
case R.id.btnDefault:
pd = new ProgressDialog(this);
pd.setTitle("Title");
pd.setMessage("Message");
// добавляем кнопку
pd.setButton(Dialog.BUTTON_POSITIVE, "OK", new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
pd.show();
break;
case R.id.btnHoriz:
pd = new ProgressDialog(this);
pd.setTitle("Title");
pd.setMessage("Message");
// меняем стиль на индикатор
pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
// устанавливаем максимум
pd.setMax(2148);
// включаем анимацию ожидания
pd.setIndeterminate(true);
pd.show();
h = new Handler() {
public void handleMessage(Message msg) {
// выключаем анимацию ожидания
pd.setIndeterminate(false);
if (pd.getProgress() < pd.getMax()) {
// увеличиваем значения индикаторов
pd.incrementProgressBy(50);
pd.incrementSecondaryProgressBy(75);
h.sendEmptyMessageDelayed(0, 100);
} else {
pd.dismiss();
}
}
};
h.sendEmptyMessageDelayed(0, 2000);
break;
default:
break;
}
}
}
Instead of disabling views just create a boolean variable that you set to true when a dialog is clicked. In your onClick function you can check if there is already an active dialog. Then you can add an onDismissListener to your dialogs and reset the boolean variable.
Are you saying when clicking another button, you want the current progress dialog to go away before showing the new one? I think you would need to dismiss the dialog if it is showing then with a simple check in your onClick()
public void onclick(View v) {
if (pd != null) {
pd.dismiss();
}
switch (v.getId()) {
case R.id.btnDefault:
....