Explorar el Código

Handle weights properly

master
Chris Smith hace 14 años
padre
commit
06576a39a9

BIN
code/ContextHome/dist/ContextHome.apk Ver fichero


+ 4
- 4
code/ContextHome/src/uk/co/md87/android/contexthome/ContextHome.java Ver fichero

@@ -42,8 +42,6 @@ public class ContextHome extends Activity {
42 42
     private LinearLayout layout;
43 43
     private final Module[] modules = new Module[]{
44 44
         new SmsModule(), new SmsModule(), new SmsModule(), new SmsModule(),
45
-        new SmsModule(), new SmsModule(), new SmsModule(), new SmsModule(),
46
-        new SmsModule(), new SmsModule(),
47 45
     };
48 46
 
49 47
     /** Called when the activity is first created. */
@@ -52,7 +50,6 @@ public class ContextHome extends Activity {
52 50
         super.onCreate(icicle);
53 51
         
54 52
         layout = new LinearLayout(this);
55
-        MODULE_PARAMS.weight = (float) 1 / 10;
56 53
         layout.setOrientation(LinearLayout.VERTICAL);
57 54
         setContentView(layout);
58 55
 
@@ -62,8 +59,11 @@ public class ContextHome extends Activity {
62 59
     private void initLayout() {
63 60
         layout.removeAllViews();
64 61
 
62
+        int i = 0;
65 63
         for (Module module : modules) {
66
-            layout.addView(module.getView(this, 1), MODULE_PARAMS);
64
+            final LayoutParams params = new LayoutParams(MODULE_PARAMS);
65
+            params.weight = (float) ++i / 10;
66
+            layout.addView(module.getView(this, i), params);
67 67
         }
68 68
     }
69 69
 

+ 6
- 3
code/ContextHome/src/uk/co/md87/android/contexthome/modules/SmsModule.java Ver fichero

@@ -43,16 +43,19 @@ public class SmsModule implements Module {
43 43
     @Override
44 44
     public View getView(final Context context, final int weight) {
45 45
         final LinearLayout layout = new LinearLayout(context);
46
-        final TextView text = new TextView(context);
46
+        layout.setOrientation(LinearLayout.VERTICAL);
47 47
 
48 48
         final Cursor cursor = context.getContentResolver().query(INBOX_URI,
49 49
                 new String[] { "_id", "date", "body" }, null, null, "date DESC");
50
-        if (cursor.moveToFirst()) {
50
+        boolean success = cursor.moveToFirst();
51
+        for (int i = 0; i < weight && success; i++) {
52
+            final TextView text = new TextView(context);
51 53
             text.setText(cursor.getString(cursor.getColumnIndex("body")));
54
+            layout.addView(text);
55
+            success = cursor.moveToNext();
52 56
         }
53 57
         cursor.close();
54 58
         
55
-        layout.addView(text);
56 59
 
57 60
         return layout;
58 61
     }

Loading…
Cancelar
Guardar