Browse Source

Handle weights properly

master
Chris Smith 14 years ago
parent
commit
06576a39a9

BIN
code/ContextHome/dist/ContextHome.apk View File


+ 4
- 4
code/ContextHome/src/uk/co/md87/android/contexthome/ContextHome.java View File

42
     private LinearLayout layout;
42
     private LinearLayout layout;
43
     private final Module[] modules = new Module[]{
43
     private final Module[] modules = new Module[]{
44
         new SmsModule(), new SmsModule(), new SmsModule(), new SmsModule(),
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
     /** Called when the activity is first created. */
47
     /** Called when the activity is first created. */
52
         super.onCreate(icicle);
50
         super.onCreate(icicle);
53
         
51
         
54
         layout = new LinearLayout(this);
52
         layout = new LinearLayout(this);
55
-        MODULE_PARAMS.weight = (float) 1 / 10;
56
         layout.setOrientation(LinearLayout.VERTICAL);
53
         layout.setOrientation(LinearLayout.VERTICAL);
57
         setContentView(layout);
54
         setContentView(layout);
58
 
55
 
62
     private void initLayout() {
59
     private void initLayout() {
63
         layout.removeAllViews();
60
         layout.removeAllViews();
64
 
61
 
62
+        int i = 0;
65
         for (Module module : modules) {
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 View File

43
     @Override
43
     @Override
44
     public View getView(final Context context, final int weight) {
44
     public View getView(final Context context, final int weight) {
45
         final LinearLayout layout = new LinearLayout(context);
45
         final LinearLayout layout = new LinearLayout(context);
46
-        final TextView text = new TextView(context);
46
+        layout.setOrientation(LinearLayout.VERTICAL);
47
 
47
 
48
         final Cursor cursor = context.getContentResolver().query(INBOX_URI,
48
         final Cursor cursor = context.getContentResolver().query(INBOX_URI,
49
                 new String[] { "_id", "date", "body" }, null, null, "date DESC");
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
             text.setText(cursor.getString(cursor.getColumnIndex("body")));
53
             text.setText(cursor.getString(cursor.getColumnIndex("body")));
54
+            layout.addView(text);
55
+            success = cursor.moveToNext();
52
         }
56
         }
53
         cursor.close();
57
         cursor.close();
54
         
58
         
55
-        layout.addView(text);
56
 
59
 
57
         return layout;
60
         return layout;
58
     }
61
     }

Loading…
Cancel
Save