When is it necessary to use singleTop launchMode in an android widget or application?

I did more reading in Android Docs — I could spend a lifetime reading their docs and find a new subtle detail that breaks my brain 🙂 This explains my multiple-instances that I did not expect, however, I configured to occur. Android Doc on Activity definition for AndroidManifest.xml The “standard” and “singleTop” modes differ from … Read more

How to change default images of CheckBox

Drawable customdrawablecheckbox.xml: <?xml version=”1.0″ encoding=”utf-8″?> <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <item android:state_checked=”false” android:drawable=”@drawable/unchecked_drawable” /> <item android:state_checked=”true” android:drawable=”@drawable/checked_drawable” /> <item android:drawable=”@drawable/unchecked_drawable” /> <!– default state –> </selector> yourcheckbox xml: <CheckBox android:id=”@+id/chk” android:button=”@drawable/customdrawablecheckbox” android:layout_alignParentLeft=”true” android:layout_width=”wrap_content” android:layout_height=”wrap_content” />

Android getMeasuredHeight returns wrong values !

You’re calling measure incorrectly. measure takes MeasureSpec values which are specially packed by MeasureSpec.makeMeasureSpec. measure ignores LayoutParams. The parent doing the measuring is expected to create a MeasureSpec based on its own measurement and layout strategy and the child’s LayoutParams. If you want to measure the way that WRAP_CONTENT usually works in most layouts, call … Read more

How to access resource with dynamic name in my case?

int id = getResources().getIdentifier(imageName, type, package); This will get you the ID of the resource you are looking for. With it, you can then access the resource from the R class. Using only the name parameter: You can also include all the 3 info in the “name” parameter using the following format: “package:type/image_name”, something like: … Read more

Setting attribute of child element of included layout

No, there is no way to pass parameters to the included layout other than the layout params using the <include> directive. You can inflate the layout programatically and add them to your view. Add an id to the container in your main layout: <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:id=”@+id/container” android:layout_width=”fill_parent” android:layout_height=”fill_parent” android:orientation=”vertical” /> Then in … Read more

Example of using Android tabs with Views instead of Activities?

I think in the .setContent method of each tab you pass in the view you wish to use: TabHost.TabSpec spec1 = tabs.newTabSpec(“tag1”); spec1.setContent(R.id.AnalogClock01); spec1.setIndicator(“Analog Clock”); Here’s an example I found awhile back: <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:orientation=”vertical” android:layout_width=”fill_parent” android:layout_height=”fill_parent” > <TabHost android:id=”@+id/TabHost01″ android:layout_width=”wrap_content” android:layout_height=”wrap_content”> <TabWidget android:id=”@android:id/tabs” android:layout_width=”wrap_content” android:layout_height=”wrap_content” /> <FrameLayout android:id=”@android:id/tabcontent” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:paddingTop=”65px”> … Read more

implement android:src=”@drawable/image” programmatically in Android

Try this: ImageButton btn = (ImageButton)findViewById(R.id.button1); btn.setImageResource(R.drawable.newimage); where newimage is the image name in drawable folder. EDITED try this: ImageButton btn = (ImageButton)findViewById(R.id.button1); btn.setImageBitmap(bm); where bm is bitmap extracted from server. EDITED AGAIN I see you receive a Drawable; well, do this: normalImage = Drawable.createFromStream(code); Bitmap bm = ((BitmapDrawable)normalImage).getBitmap(); ImageButton btn = (ImageButton)findViewById(R.id.button1); btn.setImageBitmap(bm);