1

I have a class that extends View. I want to add it to a ScrollView programmatically. I'm able to add it to a LinearLayout but have no success with a ScrollView. What gives?

sv = (ScrollView)findViewById(R.id.sv);

myview = new MyViewClass(this);
myview.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

sv.addView(myview);
2
  • Are you calling setContentView(sv); ? Commented Aug 24, 2012 at 1:49
  • no, I'm calling setContentView(R.layout.main) which contains the scrollview Commented Aug 24, 2012 at 1:52

2 Answers 2

1

You can add your View to the ScrollView if its the only view in the ScrollView.

Otherwise you will get ScrollView can have only 1 direct child exception.

To add multiple Views to a ScrollView. First add a Linear or Relative Layout in the ScrollView and then add Views to this Layout.

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

Comments

0
jsonUserInfo = actionObject.getUserInfoID(urlsId).getJSONArray("data").getJSONObject(i);
ModeUser userinf=new ModeUser();
userinf.Male=jsonUserInfo.getString("sex");
userinf.userName=jsonUserInfo.getString("first_name");
userinf.UserLastName=jsonUserInfo.getString("last_name");
UserInfoDatInList.add(userinf);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.