view and subview

by Jags » Sat, 17 Jul 2010 20:47:05 GMT


Sponsored Links
 is there a way i can create a view and add some textviews into it ?
programmatically ? any sample code ?

regards

--



view and subview

by grace » Mon, 19 Jul 2010 14:28:52 GMT


 hi please check out the sample code for creating views and viewGroups
without a xml


public class tut3 extends Activity {

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);



        ScrollView sv = new ScrollView(this);

        LinearLayout ll = new LinearLayout(this);

        ll.setOrientation(LinearLayout.VERTICAL);

        sv.addView(ll);



        TextView tv = new TextView(this);

        tv.setText("Dynamic layouts ftw!");

        ll.addView(tv);



        EditText et = new EditText(this);

        et.setText("weeeeeeeeeee~!");

        ll.addView(et);



        Button b = new Button(this);

        b.setText("I don't do anything, but I was added
dynamically. :)");

        ll.addView(b);



        for(int i = 0; i < 20; i++) {

                CheckBox cb = new CheckBox(this);

                cb.setText("I'm dynamic!");

                ll.addView(cb);

        }

        this.setContentView(sv);

    }

}





--


Sponsored Links


Other Threads

1. Issue with populating a ViewFlipper child View with a ListView

Hi

I am trying to populate a ViewFlipper with a ListView when a certain
button is clicked...but I only get a NullPointerException for
lv.setAdapter(new ArrayAdapter<String>(this,
R.layout.specialeffectsview, specialEffects));

To be honest I don't really know how to do this, I just learned about
the ViewFlipper today and I haven't fully understood how to use it
yet. If anyone could help me find how what I have done wrong, that
would be great.

Thanks in advance.

Here is the code I use:

public void onClick(View v){
                        if (v == btnExposure){

                                mFlipper.setDisplayedChild(0);

                        }
                        else if (v == btnProperties){
                                mFlipper.setDisplayedChild(1);
                        }

                        else if (v == btnSpecialEffects){
                                mFlipper.setDisplayedChild(2);
                                String[] specialEffects =
getResources().getStringArray(R.array.special_effects_array);
                        lv.setAdapter(new ArrayAdapter<String>(this,
R.layout.specialeffectsview, specialEffects));
                        lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
                        }

                }

-- 

2. LVL Sample application problems

I've followed the instructions for loading the sample LVL application
and it loads up with a bunch of errors. Anywhere that a
"R.layout.main" or "R.*" request is made it says R cannot be resolved.
It suggests importing Android.R but if I do that then it says it can't
find any of the files, including the R.layout.main file which is
definitely there.

What gives? I have had several problems with sample applications so
far, am I doing something wrong? You'd think that all you have to do
is import it from existing source and it should work.

Has anyone else had this issue?

-- 

3. Solved: Static variables cleared in JUnit tests! (???)

4. Droid's Hardware cannot handle mobile hotspot.. says Motorola.. :)

5. isReachable() is about 1000X slower than it should be

6. Jigsaw puzzle image source

7. Create Quick Launch of WAP site