Looping thru interface elements

by gimpsta » Thu, 03 Sep 2009 09:23:11 GMT


Sponsored Links
 This is probably a very "newbie" question as i'm relatively new to the
android sdk, but figured this would be good place to ask.

Say you have a layout with several textviews that all have sequential
IDs (ie, tBox1, tBox2, tBox3, etc).  Is it possible to reference each
box in a loop?  Something like:

do {
iCount++;
View tvBox1 = findViewById(R.id.tBox[iCount]);
}
while (iCount < 10);


--~--~---------~--~----~------------~-------~--~----~



Looping thru interface elements

by Mark Murphy » Thu, 03 Sep 2009 09:33:34 GMT


 >

You could create a static array of the IDs and iterate over the array.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
Android App Developer Books:  http://commonsware.com/books.html 



--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Looping thru interface elements

by gimpsta » Thu, 03 Sep 2009 11:05:20 GMT


 Haha I thought of that right after I posted this.  Probably what I
will end up doing for now.

Thanks!



--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Map Example throwing class not found exception

Hi All,

I am trying out to set map view from my class which is shown below but
when I run this app it gives me the class not found for my class which
is extending map activity and I am passing same to create the map
view.

Stack trace is as shown below

01-10 13:41:51.455: ERROR/AndroidRuntime(5654): Uncaught handler:
thread main exiting due to uncaught exception
01-10 13:41:51.593: ERROR/AndroidRuntime(5654):
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.tryst.mapexample/com.tryst.mapexample.MapExample}:
java.lang.ClassNotFoundException: com.tryst.mapexample.MapExample in
loader dalvik.system.pathclassloa...@43367128
01-10 13:41:51.593: ERROR/AndroidRuntime(5654):     at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2068)
01-10 13:41:51.593: ERROR/AndroidRuntime(5654):     at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2156)
01-10 13:41:51.593: ERROR/AndroidRuntime(5654):     at
android.app.ActivityThread.access$1800(ActivityThread.java:112)
01-10 13:41:51.593: ERROR/AndroidRuntime(5654):     at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1580)
01-10 13:41:51.593: ERROR/AndroidRuntime(5654):     at
android.os.Handler.dispatchMessage(Handler.java:88)
01-10 13:41:51.593: ERROR/AndroidRuntime(5654):     at
android.os.Looper.loop(Looper.java:123)
01-10 13:41:51.593: ERROR/AndroidRuntime(5654):     at
android.app.ActivityThread.main(ActivityThread.java:3742)
01-10 13:41:51.593: ERROR/AndroidRuntime(5654):     at
java.lang.reflect.Method.invokeNative(Native Method)
01-10 13:41:51.593: ERROR/AndroidRuntime(5654):     at
java.lang.reflect.Method.invoke(Method.java:515)
01-10 13:41:51.593: ERROR/AndroidRuntime(5654):     at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:739)
01-10 13:41:51.593: ERROR/AndroidRuntime(5654):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497)
01-10 13:41:51.593: ERROR/AndroidRuntime(5654):     at
dalvik.system.NativeStart.main(Native Method)
01-10 13:41:51.593: ERROR/AndroidRuntime(5654): Caused by:
java.lang.ClassNotFoundException: com.tryst.mapexample.MapExample in
loader dalvik.system.pathclassloa...@43367128
01-10 13:41:51.593: ERROR/AndroidRuntime(5654):     at
dalvik.system.PathClassLoader.findClass(PathClassLoader.java:215)
01-10 13:41:51.593: ERROR/AndroidRuntime(5654):     at
java.lang.ClassLoader.loadClass(ClassLoader.java:453)
01-10 13:41:51.593: ERROR/AndroidRuntime(5654):     at
java.lang.ClassLoader.loadClass(ClassLoader.java:421)
01-10 13:41:51.593: ERROR/AndroidRuntime(5654):     at
android.app.Instrumentation.newActivity(Instrumentation.java:1096)
01-10 13:41:51.593: ERROR/AndroidRuntime(5654):     at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2060)
01-10 13:41:51.593: ERROR/AndroidRuntime(5654):     ... 11 more


public class TrystMap extends MapActivity {
    /** Called when the activity is first created. */
        private MapView myMapView;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        myMapView = new MapView(this,
"08fv48heZMWmo_I8z6vrAlroVu_aFZuLULzMV5w");
        GeoPoint p = new GeoPoint((int) (40.689213 * 1000000),
                              (int) (-74.044558 * 1000000));
        MapController mc = myMapView.getController();
        mc.animateTo(p);
        mc.setZoom(22);
        setContentView(myMapView);
        myMapView.setSatellite(true);
    }

Any help in this regard is highly appreciated.
--~--~---------~--~----~------------~-------~--~----~

2. Imageview and ArrayAdapter

Hello,

I'm having the following problem.
I'm trying to populate a ListView with the following:
                twText = (ListView) findViewById(R.id.list_items);
                ArrayAdapter<String> twText_list = new
ArrayAdapter<String>(this, R.layout.list_item, R.id.row_text2,
tw_text);
                twText.setAdapter(twText_list);

and the list_item.xml is this one:

<?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="wrap_content">
    <TextView android:id="@+id/row_text2"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        />
</LinearLayout>


That works perfectly, but once I add an ImageView it crashes:

<?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="wrap_content">
    <imageView android:id="@+id/profile_image_url"
        android:maxWidth="50px"
        android:maxHeight="20px"
         />
    <TextView android:id="@+id/row_text2"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        />
</LinearLayout>


What I don't understand is that if I replace the ImageView with just another
TextView it works.

Any ideas? With an example preferably.. I'm really new on this.
Thanks in advance

--~--~---------~--~----~------------~-------~--~----~

3. Lock phone to control access

4. Dev Phone: Copying restricted files form device to PC

5. my rotated bitmaps "unrotate" immediately after invoking setCenter() method

6. what is the meaning of 'cross compiling'

7. Will the G1 version of android ever see any more updates from Google?