1

Dynamically i add some checkboxes to my scroll view. It works fine until no of entries is less but when number of checkboxes is more it goes out of the display and i cant scroll it down.

MainActivity.java

private void displayContact() { // TODO Auto-generated method stub ScrollView parent_layout=(ScrollView)findViewById(R.id.r1); LinearLayout contact_layout=new LinearLayout(MainActivity.this); ContentResolver cr=getContentResolver(); Cursor cur=cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); if(cur.getCount()>0){ //Toast.makeText(this, "hi", Toast.LENGTH_LONG).show(); int tm=0; while(cur.moveToNext()){ String id=cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID)); String name=cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); if(Integer.parseInt(cur.getString( cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)))>0){ Cursor pCur=cr.query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID+"=?", new String[]{id}, null); while(pCur.moveToNext()){ String phoneNo=pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); CheckBox c1 = new CheckBox (MainActivity.this); c1.setText(name); LayoutParams lp=new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT); c1.setLayoutParams(lp); contact_layout.addView(c1); //Toast.makeText(this, ""+name+","+phoneNo ,Toast.LENGTH_LONG).show(); } } } } parent_layout.addView(contact_layout); } 

activity_main.xml

 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/r1" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:scrollbarStyle="insideInset" android:scrollbars="vertical" tools:context=".MainActivity" > <Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="24dp" android:text="Button" /> </ScrollView> 

How to enable the scrolling functionality ?

2 Answers 2

1

Define your Scrollview with one direct child.

Sign up to request clarification or add additional context in comments.

3 Comments

i changed my main layout to Scroll View and i created a LinearLayout dynamically. Then i added the checkboxes to the LinearLayout, finally i added the LinearLayout to the ScrollView. but "unfotunately app has bee stopped"
Post your stack trace
working now...i forgot that already there is child in my static design..thanks for that tip only one child in ScrollView
0

You have to place your checkboxes in one LinearLayout which is hosted by the ScrollView.

See here: ScrollView dos not work

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.