Skip to content

Instantly share code, notes, and snippets.

Egoitz Gonzalez aldakur

Block or report user

Report or block aldakur

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View TestActivity.java
package com.gunhansancar.android.example.activity;
import android.content.res.Resources;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
import com.gunhansancar.android.example.R;
import com.gunhansancar.android.sdk.helper.LocaleHelper;
import butterknife.Bind;
View MainApplication.java
package com.gunhansancar.android.example.application;
import android.app.Application;
import com.gunhansancar.android.sdk.helper.LocaleHelper;
/**
* When your application is launched this class is loaded before all of your activies.
* And the instance of this class will live through whole application lifecycle.
* <p/>
@aldakur
aldakur / LocaleHelper.java
Created Jun 20, 2016 — forked from gunhansancar/LocaleHelper.java
While developing your awesome application, sometimes you are required to add a language change feature to your app on the fly. However, Android OS does not directly support this behaviour. And therefore, you need to solve this situation in some other ways. For more details see http://gunhansancar.com/change-language-programmatically-in-android/
View LocaleHelper.java
package com.gunhansancar.android.sdk.helper;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.preference.PreferenceManager;
import java.util.Locale;
@aldakur
aldakur / TransferDataBetweenActivities.java
Last active Jun 13, 2016
#android Transfer data between activities
View TransferDataBetweenActivities.java
//First activity (ActivityA). The data is in editText (et1)
Intent i = new Intent(this, ActivityB.class);
i.putExtra("textByUser", et1.getText().toString());
startActivity(i);
//Second activity (ActivityB). Get data
Bundle bundle = getIntent().getExtras();
String data = bundle.getString("textByUser");
@aldakur
aldakur / GetResources.java
Last active Jun 13, 2016
#android Get Resources
View GetResources.java
// String resource. normal method
btnRutas.setText(R.string.rutas);
// Get resources dynamically. When string variable is different in some cases
String variable = ruta.getDescripcion(); //For example, now variable is "car_description"
int intVariableForTranslate = context.getResources().getIdentifier(variable, "string", context.getPackageName());
String descriptionTranslated = context.getString(intVariableForTranslate);
// String resource
String myString = getResources().getString(R.string.mystring)
View #android ActionBarShowHideSample.java
//When the class extends from Activity
ActionBar actionBar = getActionBar();
actionBar.hide(); //hide
actinBar.show(); //Show
//When the class extends from AppCompatActivity
getSupportActionBar().hide(); //hide
getSupportActionBar().show(); //show
//In FragmentActivity, you need to change the FragmentActivity to an ActionBarActivity,
@aldakur
aldakur / #android CheckAndroidVersionSample.java
Last active Jun 13, 2016
Check android version in a condition
View #android CheckAndroidVersionSample.java
// Check the condition as
if (android.os.Build.VERSION.SDK_INT>=11){
//Do something
}
// This is better
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
//Do something
}
You can’t perform that action at this time.