adding Textviews and radio button in code

by automerc » Thu, 05 Mar 2009 10:15:09 GMT

Sponsored Links
 I was wondering how we could add objects such as textview and radio
buttons to the activity through code and not the XML file and still
have it run correctly. I tried adding a simple textview below but I
got an error when I tried to run. Can any1 tell me how I could add the
textview in correctly?

import java.util.ArrayList;

import android.os.Bundle;
import android.widget.ScrollView;
import android.widget.TextView;

public class Q_end extends Activity {
    /** Called when the activity is first created. */
        private ArrayList<String> qs = new ArrayList<String>(10);
        private ArrayList<String[]> as = new ArrayList<String[]>(10);

    public void onCreate(Bundle savedInstanceState) {
        ScrollView we = (ScrollView) findViewById(;
        String[] temp = new String[4];
        temp[0] = "the";
        temp[1] = "the1";
        temp[2] = "the2";
        temp[3] = "the3";
        String temp2 = "the rocks says";
        qs.add("the question is");
        String[] temp3 = new String[1];
        temp3[0] = " ";
        TextView gg = new TextView(null);


adding Textviews and radio button in code

by Mark Murphy » Thu, 05 Mar 2009 10:38:05 GMT


Could you provide us with the error details from the log? Use adb
logcat, Eclipse, or DDMS.

In particular, it would be useful to know what exception occurred and
what line of your source it occurred on.

Mark Murphy (a Commons Guy) 
Android Training in Sweden -- 


Sponsored Links

adding Textviews and radio button in code

by automerc » Fri, 06 Mar 2009 08:54:26 GMT

  think this is what caused the error

03-05 19:50:55.975: DEBUG/dalvikvm(224): VM cleaning up
03-05 19:50:55.975: DEBUG/dalvikvm(224): LinearAlloc 0x0 used 541260
of 4194304 (12%)
03-05 19:50:56.014: ERROR/dalvikvm(224): pthread_setspecific failed,
03-05 19:50:56.045: INFO/jdwp(232): received file descriptor 10 from
03-05 19:50:56.334: DEBUG/AndroidRuntime(232): Shutting down VM
03-05 19:50:56.334: WARN/dalvikvm(232): threadid=3: thread exiting
with uncaught exception (group=0x40010e28)
03-05 19:50:56.346: ERROR/AndroidRuntime(232): Uncaught handler:
thread main exiting due to uncaught exception
03-05 19:50:56.364: ERROR/AndroidRuntime(232):
java.lang.RuntimeException: Unable to start activity ComponentInfo
03-05 19:50:56.364: ERROR/AndroidRuntime(232): at
03-05 19:50:56.364: ERROR/AndroidRuntime(232): at
03-05 19:50:56.364: ERROR/AndroidRuntime(232): at$1800(
03-05 19:50:56.364: ERROR/AndroidRuntime(232): at$H.handleMessage(
03-05 19:50:56.364: ERROR/AndroidRuntime(232): at
03-05 19:50:56.364: ERROR/AndroidRuntime(232): at
03-05 19:50:56.364: ERROR/AndroidRuntime(232): at
03-05 19:50:56.364: ERROR/AndroidRuntime(232): at
java.lang.reflect.Method.invokeNative(Native Method)
03-05 19:50:56.364: ERROR/AndroidRuntime(232): at
03-05 19:50:56.364: ERROR/AndroidRuntime(232): at$
03-05 19:50:56.364: ERROR/AndroidRuntime(232): at
03-05 19:50:56.364: ERROR/AndroidRuntime(232): at
dalvik.system.NativeStart.main(Native Method)
03-05 19:50:56.364: ERROR/AndroidRuntime(232): Caused by:
03-05 19:50:56.364: ERROR/AndroidRuntime(232): at
03-05 19:50:56.364: ERROR/AndroidRuntime(232): at
03-05 19:50:56.364: ERROR/AndroidRuntime(232): at
03-05 19:50:56.364: ERROR/AndroidRuntime(232): at
03-05 19:50:56.364: ERROR/AndroidRuntime(232): at
03-05 19:50:56.364: ERROR/AndroidRuntime(232): at
03-05 19:50:56.364: ERROR/AndroidRuntime(232): at
03-05 19:50:56.364: ERROR/AndroidRuntime(232): ... 11 more
03-05 19:50:56.374: INFO/Process(51): Sending signal. PID: 232 SIG: 3
03-05 19:50:56.405: INFO/dalvikvm(232): threadid=7: reacting to signal
03-05 19:50:56.426: INFO/dalvikvm(232): Wrote stack trace to '/data/
03-05 19:51:05.897: WARN/ActivityManager(51): Launch timeout has
expired, giving up

adding Textviews and radio button in code

by automerc » Sat, 07 Mar 2009 05:22:25 GMT

 re there any examples of adding textviews and radio button through

On Mar 5, 7:54pm, automerc <> wrote:

Other Threads

1. AppWidget updates

I am trying to update an AppWidget manually when a user setting
changes on the device. To do so I use code similar to this:

ComponentName thisWidget = new ComponentName(this, MyAppWidget.class);
AppWidgetManager manager = AppWidgetManager.getInstance(this);
manager.updateAppWidget(thisWidget, updateViews);

I can tell that my AppWidget onUpdate method is being called as a
result since I log some debug strings to logcat in the code. However
the AppWidget itself doesn't change on the screen.

Here comes the interesting part: if I rotate my device and force a
refresh of the home screen (from PORTRAIT to LANDSCAPE or vice-versa)
then finally my AppWidget gets updated. However rotating the device
does not trigger the onUpdate method to be called, so the AppWidget
must be using the RemoteViews provided in the earlier update.

Can somebody explain me what to do to force the home screen redraw of
my AppWidget when it processes an update????



2. Trying to diagnose a Resource Not Found exception

I'm getting the following exception message:
"android.content.res.Resources$NotFoundException: Resource ID
#0x7f070004 type #0x12 is not valid"

First, I'm not sure if this error is due to a bad resource ID or a bad
resource type. The resource that is associated with this error is:, which I verified is equal to #0x7f070004.
The id comes from the following xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/chooseTabelRowLinearLayout"
android:layout_width="fill_parent" android:layout_height="fill_parent"
<TextView android:text="None set" android:id="@+id/
chooseTableRowTextView" android:layout_width="wrap_content"

I'm building a ListView which gets data from an ArrayAdapter. Since
the ArrayAdapter data comes from a remote database query that can take
a long time, I'm building the ArrayAdapter in an AsyncTask then
calling setListAdapter from within AsyncTask.onPostExecute. The
ArrayAdapter is built like this:

tableListAdapter = new

Where tableNames is the actual array of strings returned from the
remote database.

The exception comes sometime after I've done all the setup when the
system is trying to draw the ListView. I'm at a loss how to debug from
here. Any suggestions?


3. Disable default button click sound

4. Reading precomputed vertex arrays in application?

5. stringindexoutofboundsexception in ViewRoot.draw(boolean)

6. Themes and styles

7. Controlling Navigation Volume