Tag: java

Android layout previewer throws error when adding custom LinearLayout

I’ve defined a custom ViewGroup that extends the functionality of a LinearLayout: public class TestLayout extends LinearLayout { public TestLayout(Context context, AttributeSet attrs) { super(context, attrs); LayoutInflater inflater = (LayoutInflater)context.getSystemService (Context.LAYOUT_INFLATER_SERVICE); inflater.inflate(R.layout.testlayout, this, true); } } The layout it inflates (testlayout.xml) looks like this: <?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” android:gravity=”center”> <Button android:id=”@+id/button1″ […]

How to Parse Date from GMT TimeZone to IST TimeZone and Vice Versa in android

I am working on a project that fetches Date/Time from backend in IST(Indian standard Time) as shown “2013-01-09T19:32:49.103+05:30”. However when i parse it using following DateFormat DateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd’T’HH:mm:ss.SSSZ”); followed by parsing.. Date date = sdf.parse(“2013-01-09T19:32:49.103+05:30”); System.out.println(“XYZ ==============>”+date); its Displaying date in GMT format as output i.e Wed Jan 09 14:02:49 GMT+00:00 2013. […]

Dagger 2 component dependencies

Is it possible to inject something into a module? I have 2 base modules / components: @Component(modules = {OkHttpModule.class}) public interface OkHttpComponent extends AppComponent { OkHttpClient provideOkHttpClient(); } @Module public class OkHttpModule { @Provides OkHttpClient provideOkHttpClient() { return mHttpClient; } } @Component(modules = {GsonModule.class}) public interface GsonComponent extends AppComponent { Gson provideGson(); } @Module public […]

When are ALL the cases when the onSaveInstanceState() method called?

All the sources I read have all mentioned couple of cases and concluded with “a few other cases”. What are ALL the cases when the onSaveInstanceState method called in a View/Activity?

Xamarin C# – Android – Prevent an AlertDialog from closing on PositiveButton click

I’m new to Xamarin and I don’t know how to do the following in c#. I want to prevent an alertdialog from closing when clicking on the Positive/Negative buttons. I need to do some validation on the input first. If the input is correct, the dialog can close, else I will show a message with […]

Creating a ListView with custom list items programmatically in Android – no xml list item layout

As I have seen on previously asked questions, inside the custom adapter class (say, MyAdapter extends ArrayAdapter) they always use an inflated xml list-item layout. What I am hoping to do is create everything entirely using Java and no XML… // for example String[] wordlist = new String[] {a, b, c}; LinearLayout list_item_layout = new […]

ActionBar up button transition effect

I have already created a method for an animation when changing activities when the back button is pressed. The problem is that the actionbar up button has the default transition effect to the previous activity and I can’t find a way to override that animation and use a new one. Any ideas? Thanks in advance […]

How can I get the response code from a VolleyError?

I’m looking for a way to get the response code of a thrown VolleyError. My ErrorListener looks like this: Response.ErrorListener errorListener = new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { error.printStackTrace(); //Get response code here VolleyLog.e(“Error: “, error.toString()); VolleyLog.e(“Error: “, error.getLocalizedMessage()); } }; The 2 lines I send to my VolleyLog print the following: […]

Android how to pass an Activity.class as an argument for a function

I recently moved to Android from python and am stuck here. This is my class declaration to create a common function for an Alert Dialog which accepts necessary parameters public static AlertDialog.Builder getAlertDialog(String strArray[], String strTitle, Activity v) { return new AlertDialog.Builder(v) .setTitle(strTitle).setItems(strArray, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // […]

NDK vs JAVA performance

Is any body have a assumption how fast will be C code with NDK with the same calculations then java code?(if any) lets say I am doing X calculations(the same calculations) in Y seconds in java code. How many X calculations can i do in the same Y seconds through the C code in NDK? […]

Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.