Reputation: 4427
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);
Upvotes: 1
Views: 132
Reputation: 25
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);
Upvotes: 0
Reputation: 24012
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.
Upvotes: 1