Java variable initialization in if-then statement - java

I have this code that is suppose to turn off Wifi via a toggle button. I also want to have it so that if the user already had Wifi on before pressing the button, the Wifi would go back on after turning off the toggle button. This is done through the wifiON boolean. However, since the variable is initialized in the first part of the if statement, it won't be used by the else statement. How can I set it so that the else statement can get the value of the boolean from the if statement. Below is the code.
public void airplaneClicked (View view) {
boolean on = ((ToggleButton) view).isChecked();
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
boolean wifiOn;
if (on) {
if (wifi.isWifiEnabled()) {
wifiOn = true;
Log.v("", "" + wifiOn);
wifi.setWifiEnabled(false);
} else {
wifiOn = false;
Log.v("", "" + wifiOn);
}
}
else {
if (wifiOn == true) {
wifi.setWifiEnabled(true);
}
}
}

wifi.setWifiEnabled(!wifi.isWifiEnabled());

If you need the value of wifiOn in both parts of the if-else, move it to be before the if-else.
if (wifi.isWifiEnabled()) {
wifiOn = true;
} else {
wifiOn = false;
}
if (on) {
if (wifi.isWifiEnabled()) {
Log.v("", "" + wifiOn);
wifi.setWifiEnabled(false);
} else {
Log.v("", "" + wifiOn);
}
}
else {
if (wifiOn == true) {
wifi.setWifiEnabled(true);
}
}

//Use additional boolean - wifiState
boolean wifiState = wifi.isWifiEnabled();
if (on) {
if (wifiState) {
wifiState = true;
Log.v("", "" + wifiOn);
wifi.setWifiEnabled(false);
} else {
wifiState = false;
Log.v("", "" + wifiOn);
}
}
else {
if (wifiState) {
wifi.setWifiEnabled(true);
}
}

Related

How to fix TextWatcher on orientation change?

I want to write a validator for multiple editText's using TextWatcher.
I already have method to validate if the data written by user is correct.
And also added validation to check if editText is empty. But here is where it's not working as I would like to.
This TextWatcher is also activated when phone changes orientation and I don't want this to happen. I want it work only when user deletes data from editText.
Here is the code:
#Override
final public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
#Override
final public void onTextChanged(CharSequence s, int start, int before, int count) {}
#Override
final public void afterTextChanged(Editable s) {
String text = textView.getText().toString();
if(textView.getText().toString().isEmpty()){
textView.setError("Can't be empty");
ParametersFrag.isCorrect = false;
} else {
validate(textView, text);
}
}
And the validate part in fragment look like this:
editText2_5.addTextChangedListener(new ParameterValidator(editText2_5) {
#Override
public void validate(TextView textView, String text) {
double parDouble = Double.parseDouble(Tab2Fragment.editText2_5.getText().toString());
if (parDouble < sth_min) {
textView.setError(getString(R.string.err_min_value) + " " + sth_min);
ParametersFrag.isCorrect = false;
} else if (parDouble > sth_max) {
textView.setError(getString(R.string.err_max_value) + " " + sth_max);
ParametersFrag.isCorrect = false;
} else {
ParametersFrag.isCorrect = true;
}
}
});
Question is how can I make it not triggering on orientation change?
Thank You
try this:
#Override
public void onConfigurationChanged(#NotNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks the orientation of the screen
switch (newConfig.orientation) {
case Configuration.ORIENTATION_LANDSCAPE:
editText2_5.addTextChangedListener(null);
break;
case Configuration.ORIENTATION_PORTRAIT:
// editText2_5.addTextChangedListener(null);
// ============= OR =============
// editText2_5.addTextChangedListener(new ParameterValidator(editText2_5) {
// #Override
// public void validate(TextView textView, String text) {
// double parDouble = Double.parseDouble(Tab2Fragment.editText2_5.getText().toString());
// if (parDouble < sth_min) {
// textView.setError(getString(R.string.err_min_value) + " " + sth_min);
// ParametersFrag.isCorrect = false;
// } else if (parDouble > sth_max) {
// textView.setError(getString(R.string.err_max_value) + " " + sth_max);
// ParametersFrag.isCorrect = false;
// } else {
// ParametersFrag.isCorrect = true;
// }
// }
// });
break;
default:
break;
}
}
private var doesDeviceTitled = false
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
doesDeviceTitled = when (newConfig.orientation) {
Configuration.ORIENTATION_LANDSCAPE -> {
true
}
else -> {
false
}
}
}
Note: The above code was in Kotlin
then after wrap validation using this boolean variable.
editText2_5.addTextChangedListener(new ParameterValidator(editText2_5) {
#Override
public void validate(TextView textView, String text) {
if(!doesDeviceTitled){
//Your validation code here.
}
}});
Happy Coding :)
OK, so now as I think, you need to declare android:configChanges="orientation" in your <activity> tag in AndroidManifest.xml and remove this:
public void onConfigurationChanged(#NotNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks the orientation of the screen
switch (newConfig.orientation) {
case Configuration.ORIENTATION_LANDSCAPE:
editText2_5.addTextChangedListener(null);
break;
case Configuration.ORIENTATION_PORTRAIT:
// editText2_5.addTextChangedListener(null);
// ============= OR =============
// editText2_5.addTextChangedListener(new ParameterValidator(editText2_5) {
// #Override
// public void validate(TextView textView, String text) {
// double parDouble = Double.parseDouble(Tab2Fragment.editText2_5.getText().toString());
// if (parDouble < sth_min) {
// textView.setError(getString(R.string.err_min_value) + " " + sth_min);
// ParametersFrag.isCorrect = false;
// } else if (parDouble > sth_max) {
// textView.setError(getString(R.string.err_max_value) + " " + sth_max);
// ParametersFrag.isCorrect = false;
// } else {
// ParametersFrag.isCorrect = true;
// }
// }
// });
break;
default:
break;
}
}

Why all markers show up in the map after entering a query?

I am working on an Android Map application. It usually works fine when I enter a query but sometimes all markers show up unexpectedly.
What correction(s) do I need to make to my code?
This is my code:
mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
private String TAG = getClass().getSimpleName();
#Override
public boolean onQueryTextChange(String queryText) {
Log.d(TAG, "onQueryTextChange = " + queryText);
//Toast.makeText(MapActivity.this, "Change: " + queryText, Toast.LENGTH_SHORT).show();
addMarkers(queryText);
return true;
}
#Override
public boolean onQueryTextSubmit(String queryText) {
Log.d(TAG, "onQueryTextSubmit = " + queryText);
//Toast.makeText(MapActivity.this, "Change: " + queryText, Toast.LENGTH_SHORT).show();
addMarkers(queryText);
if (mSearchView != null) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.hideSoftInputFromWindow(mSearchView.getWindowToken(), 0);
}
mSearchView.clearFocus();
}
return true;
}
});
I guess the situation is when you delete all your query text, the queryText becomes "". Then all the markers show up because they all contain "".
Try to add this code into your methods of the OnQueryTextListener:
if (!queryText.equals("")) addMarkers(queryText);

how to set android hotspot active in background?

I'm working on app which will set hotspot on/off when button is clicked.
If i turn on hotspot with app, when i opened another app or got any notification hotspot automatically going to turn off
My code:
public class WifiAP extends Activity {
private static int constant = 0;
private static final int WIFI_AP_STATE_UNKNOWN = -1;
private static int WIFI_AP_STATE_DISABLING = 0;
private static int WIFI_AP_STATE_DISABLED = 1;
public int WIFI_AP_STATE_ENABLING = 2;
public int WIFI_AP_STATE_ENABLED = 3;
private static int WIFI_AP_STATE_FAILED = 4;
private final String[] WIFI_STATE_TEXTSTATE = new String[] {
"DISABLING","DISABLED","ENABLING","ENABLED","FAILED"
};
private WifiManager wifi;
private String TAG = "WifiAP";
private int stateWifiWasIn = -1;
private boolean alwaysEnableWifi = true; //set to false if you want to try and set wifi state back to what it was before wifi ap enabling, true will result in the wifi always being enabled after wifi ap is disabled
/**
* Toggle the WiFi AP state
* #param wifihandler
*/
public void toggleWiFiAP(WifiManager wifihandler, Context context) {
if (wifi==null){
wifi = wifihandler;
}
boolean wifiApIsOn = getWifiAPState()==WIFI_AP_STATE_ENABLED || getWifiAPState()==WIFI_AP_STATE_ENABLING;
new SetWifiAPTask(!wifiApIsOn,false,context).execute();
}
private int setWifiApEnabled(boolean enabled) {
Log.d(TAG, "*** setWifiApEnabled CALLED **** " + enabled);
WifiConfiguration config = new WifiConfiguration();
config.SSID = "Aqual soul";
config.preSharedKey="aquasoul";
config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
config.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
config.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
//remember wirelesses current state
if (enabled && stateWifiWasIn==-1){
stateWifiWasIn=wifi.getWifiState();
}
/* //disable wireless
if (enabled && wifi.getConnectionInfo() !=null) {
Log.d(TAG, "disable wifi: calling");
wifi.setWifiEnabled(false);
int loopMax = 10;
while(loopMax>0 && wifi.getWifiState()!=WifiManager.WIFI_STATE_DISABLED){
Log.d(TAG, "disable wifi: waiting, pass: " + (10-loopMax));
try {
Thread.sleep(500);
loopMax--;
} catch (Exception e) {
}
}
Log.d(TAG, "disable wifi: done, pass: " + (10-loopMax));
}
*/
//enable/disable wifi ap
int state = WIFI_AP_STATE_UNKNOWN;
try {
Log.d(TAG, (enabled?"enabling":"disabling") +" wifi ap: calling");
wifi.setWifiEnabled(false);
Method method1 = wifi.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class);
//method1.invoke(wifi, null, enabled); // true
method1.invoke(wifi, config, enabled); // true
Method method2 = wifi.getClass().getMethod("getWifiApState");
state = (Integer) method2.invoke(wifi);
} catch (Exception e) {
Log.e(WIFI_SERVICE, e.getMessage());
// toastText += "ERROR " + e.getMessage();
}
//hold thread up while processing occurs
if (!enabled) {
int loopMax = 10;
while (loopMax>0 && (getWifiAPState()==WIFI_AP_STATE_DISABLING || getWifiAPState()==WIFI_AP_STATE_ENABLED || getWifiAPState()==WIFI_AP_STATE_FAILED)) {
Log.d(TAG, (enabled?"enabling":"disabling") +" wifi ap: waiting, pass: " + (10-loopMax));
try {
Thread.sleep(500);
loopMax--;
} catch (Exception e) {
}
}
Log.d(TAG, (enabled?"enabling":"disabling") +" wifi ap: done, pass: " + (10-loopMax));
//enable wifi if it was enabled beforehand
//this is somewhat unreliable and app gets confused and doesn't turn it back on sometimes so added toggle to always enable if you desire
if(stateWifiWasIn==WifiManager.WIFI_STATE_ENABLED || stateWifiWasIn==WifiManager.WIFI_STATE_ENABLING || stateWifiWasIn==WifiManager.WIFI_STATE_UNKNOWN || alwaysEnableWifi){
Log.d(TAG, "enable wifi: calling");
wifi.setWifiEnabled(true);
//don't hold things up and wait for it to get enabled
}
stateWifiWasIn = -1;
} else if (enabled) {
int loopMax = 10;
while (loopMax>0 && (getWifiAPState()==WIFI_AP_STATE_ENABLING || getWifiAPState()==WIFI_AP_STATE_DISABLED || getWifiAPState()==WIFI_AP_STATE_FAILED)) {
Log.d(TAG, (enabled?"enabling":"disabling") +" wifi ap: waiting, pass: " + (10-loopMax));
try {
Thread.sleep(500);
loopMax--;
} catch (Exception e) {
}
}
Log.d(TAG, (enabled?"enabling":"disabling") +" wifi ap: done, pass: " + (10-loopMax));
}
return state;
}
public int getWifiAPState() {
int state = WIFI_AP_STATE_UNKNOWN;
try {
Method method2 = wifi.getClass().getMethod("getWifiApState");
state = (Integer) method2.invoke(wifi);
} catch (Exception e) {
}
if(state>=10){
//using Android 4.0+ (or maybe 3+, haven't had a 3 device to test it on) so use states that are +10
constant=10;
}
//reset these in case was newer device
WIFI_AP_STATE_DISABLING = 0+constant;
WIFI_AP_STATE_DISABLED = 1+constant;
WIFI_AP_STATE_ENABLING = 2+constant;
WIFI_AP_STATE_ENABLED = 3+constant;
WIFI_AP_STATE_FAILED = 4+constant;
Log.d(TAG, "getWifiAPState.state " + (state==-1?"UNKNOWN":WIFI_STATE_TEXTSTATE[state-constant]));
return state;
}
class SetWifiAPTask extends AsyncTask<Void, Void, Void> {
boolean mMode; //enable or disable wifi AP
boolean mFinish; //finalize or not (e.g. on exit)
ProgressDialog d;
public SetWifiAPTask(boolean mode, boolean finish, Context context) {
mMode = mode;
mFinish = finish;
d = new ProgressDialog(context);
}
#Override
protected void onPreExecute() {
super.onPreExecute();
d.setTitle("Turning WiFi AP " + (mMode?"on":"off") + "...");
d.setMessage("...please wait a moment.");
d.show();
}
#Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
try {
d.dismiss();
MainActivity.updateStatusDisplay();
} catch (IllegalArgumentException e) {
};
if (mFinish){
finish();
}
}
#Override
protected Void doInBackground(Void... params) {
setWifiApEnabled(mMode);
return null;
}
}
}

Phone number is set to null at the time of OFFHOOK state of TelephonyManager

I get a phone number at the time of the ringing state, but sometimes, it is set to null at the time of the off hook state. I can't catch the moment where it goes to null.
So, when a call comes (incoming call) it goes to RINGING STATE and the number is set to callno variable. After that when I pick up the call it goes to OFFHOOK STATE and I got null in callno therefore it gives me a NullPointerException.
How do I prevent this situation?
public class CallStateReceiver extends BroadcastReceiver {
private static boolean noCallListenerYet = true;
TelephonyManager telephonyManager;
static MyPhoneStateListener phoneListener;
private static Context context1;
Context context;
private int prevState;
String userId;
String incoming_number = null;
Bundle bundle;
String state;
private static String callno = null;
static SharedPreferences pref;
static int cidvalue;
/*Added to resolve the below bug:
* Bug: At the time of call comes on poped up note and
* below note was not send and new userid not
* replace with older userid.
*/
private static boolean isOnReceive = false;
public static String getCallno() {
return callno;
}
#Override
public void onReceive(Context context, Intent intent) {
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
isOnReceive = true;
if( CallTrackerModel.isRecording() ){
}else{
CallTrackerModel.setCallId("");
try{
if (intent.getAction()
.equals("android.intent.action.NEW_OUTGOING_CALL")) {
if ((bundle = intent.getExtras()) != null) {
callno = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
callno = callno.replaceAll(" ", "");
}
}
}
catch(Exception e){
}
try{
if (noCallListenerYet) {
telephonyManager = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
if (phoneListener == null) {
phoneListener = new MyPhoneStateListener(context);
telephonyManager.listen(phoneListener,
PhoneStateListener.LISTEN_CALL_STATE);
}
noCallListenerYet = false;
}
}catch(Exception e){
isOnReceive = false;
}
context1 = context;
}
}
public static int returncid() {
int cid;
pref = context1.getSharedPreferences("Myprefer", 0);
SharedPreferences.Editor editor = pref.edit();
cid = pref.getInt("currentcid", 0);
if (cid == 0) {
cid = cid + 1;
}
editor.putInt("currentcid", cid);
editor.commit();
pref = context1.getSharedPreferences("Myprefer", 0);
cidvalue = pref.getInt("currentcid", 0);
return cidvalue;
}
private class MyPhoneStateListener extends PhoneStateListener {
Context context;
MyPhoneStateListener(Context c) {
super();
context = c;
}
/**
* Listen call state changes.
*/
public void onCallStateChanged(int state, String incomingNumber) {
CallTrackerModel ctm = new CallTrackerModel(context1);
switch (state) {
// Incoming/Outgoing call over.
case TelephonyManager.CALL_STATE_IDLE:
if (CallTrackerModel.returnRecordStarted()) {
ctm.stopRecording();
userId = RetrieveUserId.getUserId();
}
//For Received calls.
if (prevState == TelephonyManager.CALL_STATE_OFFHOOK) {
try{
cidvalue = pref.getInt("currentcid", 0);
++cidvalue;
pref = context1.getSharedPreferences("Myprefer", 0);
SharedPreferences.Editor editor = pref.edit();
editor.putInt("currentcid", cidvalue);
editor.commit();
prevState = state;
// Start note activity.
Intent i = new Intent(context1, NoteActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
if (userId == null) {
userId = "##";
}
i.putExtra("userId", userId);
i.putExtra("isSend", false);
i.putExtra("incomingNumber", incoming_number);
context1.startActivity(i);
i = null;
}catch(Exception ex){
}
}
//For missed calls.
if(prevState==TelephonyManager.CALL_STATE_RINGING){
prevState=state;
}
break;
//If the caller or receiver picks up the phone
case TelephonyManager.CALL_STATE_OFFHOOK:
try{
if( CallTrackerModel.isRecording() ){
break;
}
if( NoteActivity.getIsStart() ){
NoteActivity.setStop(true);
}
prevState = state;
if (callno.length() == 13) {
incoming_number = callno.substring(3);
} else if (callno.length() == 11) {
incoming_number = callno.substring(1);
} else {
incoming_number = callno;
}
}catch(Exception ex){
isOnReceive = false;
}
try{
if( NoteActivity.getIsStop() ){
if(NoteActivity.getLater()){
NoteActivity.setLater(false);
NoteActivity.setStop(false);
}else{
NoteActivity.later();
}
}
}catch(Exception e){
isOnReceive = false;
}
try{
Intent i = new Intent(context1, RetrieveUserId.class);
i.putExtra("incoming number", incoming_number);
context1.startService(i);
// start recording
ctm.startRecording();
}catch(Exception e){
isOnReceive = false;
}
break;
case TelephonyManager.CALL_STATE_RINGING:
if( CallTrackerModel.isRecording() ){
}else{
prevState = state;
callno = incomingNumber;
callno = callno.replaceAll(" ", "");
}
break;
}
}
}
}
Your Broadast Recevier gets fired each time the Phone State Changes.
What this does is it sets the incoming_no to null after Ringing, each time the state changes.
First the phone Rings. At that moment you are able to get the number. When the Phone number changes state to IDLE or OFF_HOOK, your number gets set to null again, since the BR fires all over again.
String incoming_number = null; is what is setting your number to null. This is the code that is messing it up. Turn it into:
MainActivity:
String incoming_number;
BroadcastReceiver
MainActivity.incomingnumber = XXX-XXX-XXXX ;
//when done with the number clean it
MainActivity.incomingnumber = null;
or you could just delete your call recording app. The call recording apps cause this problem also.

Buttons not working at first and last index?

I am working on an application in which have two navigation button namely 'previous and next' which on tap load stories respectively. When i tap these buttons gently they work fine button when i tap next button to the last index continuously without any break then the previous button does not work or similarly when i start tapping previous button to the very first index i am unable to move forward.
Remember this only happens at the extreme cases, onClick is not called, don't know why.
My code is as follows, please help me out. Thanks in advance.
this the code of onClick, which works fine in all cases except the extreme cases, when buttons are not tapped gently.
public void onClick(View v) {
if (visible == true) {
Log.e("visible", "true");
return;
}
visible = true;
try {
Log.e("Now", "On Click");
pDialog = new ProgressDialog(StoriesListController.this);
pDialog.setIndeterminate(true);
pDialog.setIcon(R.drawable.icon_small);
pDialog.setCancelable(true);
if (isFavoriteList == true) {
pDialog.setMessage("Loading favorites...");
} else {
pDialog.setMessage("Loading data...");
}
pDialog.setTitle("Please wait");
pDialog.setOnCancelListener(new OnCancelListener() {
public void onCancel(DialogInterface arg0) {
if (cancelableHeavyWorker != null) {
cancelableHeavyWorker.setHandler(null);
}
finish();
}
});
pDialog.show();
if (v == next) {
if (ind < items.size() - 1) {
ind++;
loadAndShowNextActivity();
}
} else if (v == previous) {
if (ind > 0) {
ind--;
loadAndShowNextActivity();
}
}
// realeaseMemoryIfneededofStory(ind);
} catch (Exception e) {
Log.e("Error", "--.OnClink Message" + e.toString());
e.printStackTrace();
}
}
Moreover, the boolean variable "visible" is being set to false in the callback function.
The Code of Call Back Function is as follows:
private void fetchTopStoryDetailCallback(Object resultVector) {
System.out.println("fetchTopStoryDetailCallback");
try {
Vector<?> v = (Vector<?>) resultVector;
boolean completedOrFailed = ((Boolean) v.elementAt(0)).booleanValue();
if (completedOrFailed == true) {
boolean slideshow = ((Boolean) v.elementAt(1)).booleanValue();
Object result = v.elementAt(2);
String res[] = (String[]) result;
if (slideshow) {
if (Utils.topStorySlidesArrayList != null && Utils.topStorySlidesArrayList.size() > 0) {
Intent articleActivityIntent = new Intent(this, SlideShowActivity.class);
articleActivityIntent.putExtra("storyData", (String[]) result);
articleActivityIntent.putExtra("back", back);
articleActivityIntent.putStringArrayListExtra("sid", slideids);
// articleActivityIntent.putExtra("contentType", )
articleActivityIntent.putExtra("addkey", ADDS_KEY);
showActivityInContoller(articleActivityIntent);
hidePrgressgingDailog();
} else {
hidePrgressgingDailog();
this.closeActivity = true;
showMessage("Error", "This story encounter an error while opening. Check your Internet Connection and try later");
}
} else {
if (res[3] != null && (!(res[3].equalsIgnoreCase("null")) && (!res[3].equals("")))) {
Intent slideshowActivtyIntent = new Intent(this, ArticleActivity.class);
slideshowActivtyIntent.putExtra("storyData", (String[]) result);
slideshowActivtyIntent.putExtra("back", back);
slideshowActivtyIntent.putExtra("addkey", ADDS_KEY);
showActivityInContoller(slideshowActivtyIntent);
hidePrgressgingDailog();
} else {
hidePrgressgingDailog();
this.closeActivity = true;
showMessage("Error", "This story encounter an error while opening. Check your Internet Connection and try later");
}
}
} else {
showMessage("Error", "This story encounter an error while opening. Check your Internet Connection and try later");
hidePrgressgingDailog();
}
} catch (Exception e) {
Log.e("StoriesController", "Message = " + e.toString());
e.printStackTrace();
}
finally {visible = false; }
}
this is how visiblity of the buttons is set...!!!!
private void adjustButtonsVisibility() {
try {
if (items.size() == 1) {
next.setEnabled(false);
next.setImageResource(R.drawable.navigator_next_disable);
previous.setEnabled(false);
previous.setImageResource(R.drawable.navigator_previous_disable);
//hidePrgressgingDailog();
return;
}
if (ind == 0) {
previous.setEnabled(false);
next.setEnabled(true);
previous.setImageResource(R.drawable.navigator_previous_disable);
next.setImageResource(R.drawable.story_next_arrow);
hidePrgressgingDailog();
} else if (ind > 0 && ind < items.size() - 1) {
previous.setEnabled(true);
next.setEnabled(true);
previous.setImageResource(R.drawable.story_previous_arrow);
next.setImageResource(R.drawable.story_next_arrow);
}
if (ind == items.size() - 1) {
previous.setEnabled(true);
next.setEnabled(false);
previous.setImageResource(R.drawable.story_previous_arrow);
next.setImageResource(R.drawable.navigator_next_disable);
hidePrgressgingDailog();
}
} catch (Exception e) {
Log.e("Error", "--,adjustButtonsVisibility Message = " + e);
e.printStackTrace();
}
}
Do this
if (ind == 0) {
previous.setEnabled(false);
previous.setImageResource(R.drawable.navigator_previous_disable);
next.setImageResource(R.drawable.story_next_arrow);
hidePrgressgingDailog();
}
else if (ind > 0 && ind < items.size() - 1) {
previous.setEnabled(true);
next.setEnabled(true);
previous.setImageResource(R.drawable.story_previous_arrow);
next.setImageResource(R.drawable.story_next_arrow);
}
else if (ind == items.size() - 1) {
previous.setEnabled(true);
next.setEnabled(false);
previous.setImageResource(R.drawable.story_previous_arrow);
next.setImageResource(R.drawable.navigator_next_disable);
hidePrgressgingDailog();
}

Categories

Resources