I am tryin to add ten relativeLayouts dynamically by inflating the xml , but the relative layouts getting overlapped. how to change the margins of the inflating xml dynamically via code.
Below is the code reuse.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/aaa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
>
<ImageView
android:id="#+id/image"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="5dp"
android:scaleType="centerCrop"
android:src="#drawable/ballaya" />
<TextView
android:id="#+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:layout_marginLeft="50dp"
android:layout_marginTop="12dp"
android:layout_weight="1"
android:text="Srimannarayana earns Rs 8.65 cr on day 1"
android:textColor="#FFFFFF"
android:textSize="11sp"
android:textStyle="bold" />
<View
android:id="#+id/seperator"
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:layout_below="#+id/image"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:background="#FFFFFF" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:src="#drawable/popover_bg_rghtarw" />
</RelativeLayout>
code of item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#06516E" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="20dp"
android:background="#49C7F9">
<TextView
android:id="#+id/HeadLines"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Latest News"
android:textColor="#FFFFFF"
android:textSize="12sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/newsLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="30dp" >
</RelativeLayout>
</RelativeLayout>
Java Code
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.item);
newsLayout =(RelativeLayout)findViewById(R.id.newsLayout);
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout row[] = new RelativeLayout[10];
TextView text[]= new TextView[10];
for(int i=0;i<10;i++){
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
row[i] = (RelativeLayout) inflater.inflate(R.layout.reuse,null);
params.setMargins(0, 50, 0, 0);
newsLayout.addView(row[i],params);
text[i]= (TextView) row[i].findViewById(R.id.text);
text[i].setText("AAAAAAA");
}
You can use LinearLayout instead of RelativeLayout for newsLayout and make the orientation as VERTICAL.
And instead of newsLayout =(RelativeLayout)findViewById(R.id.newsLayout);
write: newsLayout =(LinearLayout)findViewById(R.id.newsLayout);
And rest of the code will be as it is.
This will solve your problem.
Related
I trying to add margin right to my relative layout. I need to add it in to HorizontalScrollView and bind data through java code. I have created layout file and add that file using layout inflator.
Below is my code:
XML Code:
<HorizontalScrollView
android:id="#+id/propertyListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:background="#color/white"
android:fillViewport="true"
android:measureAllChildren="false"
android:scrollbars="none">
<LinearLayout
android:id="#+id/propertyListViewContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
</LinearLayout>
</HorizontalScrollView>
Below is layout file.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="280dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp">
<ImageView
android:id="#+id/propertyImage"
android:layout_width="280dp"
android:layout_height="190dp"
android:scaleType="fitXY"
android:src="#drawable/image_ad_property" />
<RelativeLayout
android:id="#+id/propertyPriceContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/propertyImage"
android:background="#f2f2f2"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingTop="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="₹ 1.25 cr onwards"
android:textColor="#6a6a6a"
android:textSize="12sp" />
</RelativeLayout>
<TextView
android:id="#+id/propertyName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/propertyPriceContainer"
android:layout_marginTop="10dp"
android:text="Park Royale"
android:textColor="#353535"
android:textSize="14sp" />
<TextView
android:id="#+id/propertyPlace"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/propertyName"
android:layout_marginTop="4dp"
android:text="Gokhale Marg"
android:textColor="#6b6b6b"
android:textSize="13sp" />
<LinearLayout
android:id="#+id/rateContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/propertyPriceContainer"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<ImageView
android:id="#+id/ratingImage1"
android:layout_width="15dp"
android:layout_height="15dp"
android:src="#drawable/icon_rating_selected" />
<ImageView
android:id="#+id/ratingImage2"
android:layout_width="15dp"
android:layout_height="15dp"
android:src="#drawable/icon_rating_selected" />
<ImageView
android:id="#+id/ratingImage3"
android:layout_width="15dp"
android:layout_height="15dp"
android:src="#drawable/icon_rating_selected" />
<ImageView
android:id="#+id/ratingImage4"
android:layout_width="15dp"
android:layout_height="15dp"
android:src="#drawable/icon_rating_normal" />
<ImageView
android:id="#+id/ratingImage5"
android:layout_width="15dp"
android:layout_height="15dp"
android:src="#drawable/icon_rating_normal" />
</LinearLayout>
<LinearLayout
android:id="#+id/varifiedContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/rateContainer"
android:layout_marginTop="4dp"
android:orientation="horizontal">
<ImageView
android:layout_width="12dp"
android:layout_height="10dp"
android:layout_gravity="center"
android:src="#drawable/icon_verified" />
<TextView
android:id="#+id/homeVerified"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:text="Verified"
android:textColor="#6b6b6b"
android:textSize="13sp" />
</LinearLayout>
</RelativeLayout>
Below is java file:
LinearLayout propertyListViewContainer = (LinearLayout) findViewById(R.id.propertyListViewContainer);;
for (int i = 0; i < 10; i++) {
RelativeLayout child = (RelativeLayout) getLayoutInflater().inflate(R.layout.layout_project_details_property_item, null);
final float scale = getResources().getDisplayMetrics().density; //set height and width
int dpWidthInPx = (int) (280 * scale); //set width
RelativeLayout.LayoutParams paramsBuyRent = new RelativeLayout.LayoutParams(dpWidthInPx, RelativeLayout.LayoutParams.WRAP_CONTENT);
paramsBuyRent.setMargins(0, 0, 20, 0);
child.setLayoutParams(paramsBuyRent);
propertyListViewContainer.addView(child);
}
Change :
RelativeLayout.LayoutParams paramsBuyRent = new RelativeLayout.LayoutParams(dpWidthInPx, RelativeLayout.LayoutParams.WRAP_CONTENT);
to:
RelativeLayout.LayoutParams paramsBuyRent = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
OR
RelativeLayout.LayoutParams paramsBuyRent = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
Layout inflater's inflate method has a second parameter that takes root view as a parameter. If you don't provide it the margins will be ignored. So provide container view as the second parameter there. Something like this:
for (int i = 0; i < 10; i++) {
RelativeLayout child = (RelativeLayout) getLayoutInflater().inflate(R.layout.layout_project_details_property_item, propertyListViewContainer);
}
This way there's no need to add the inflated view to the parent layout at the end as it will automatically be attached to the provided layout keeping it's margins intact.
In xml of row_layout I've set a delete button as follows
row_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rowlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="0dp"
android:background="#ffffff"
android:baselineAligned="false"
android:orientation="horizontal"
android:paddingLeft="10sp"
android:weightSum="100" >
<LinearLayout
android:id="#+id/Layout"
android:layout_width="150sp"
android:layout_height="50dp"
android:layout_weight="90"
android:orientation="vertical" >
<TextView
android:id="#+id/firstTextView"
android:layout_width="150sp"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginTop="10sp"
android:gravity="top"
android:text="Activity"
android:textColor="#000" />
<TextView
android:id="#+id/firstTextView2"
android:layout_width="150sp"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:gravity="top"
android:text="Sub-Activity"
android:textColor="#000" />
</LinearLayout>
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:src="#drawable/edit" />
<ImageView
android:id="#+id/delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:onClick="onClickDelete"
android:src="#drawable/neg" />
</LinearLayout>
here is onClickDelete method
public void onClickDelete(View v)
{
ListView lvItems = getListView();
//get the row the clicked button is in
LinearLayout vwParentRow = (LinearLayout)v.getParent();
TextView child = (TextView) vwParentRow.getChildAt(0);
child.setText("Delete Clicked");
}
When i press delete, it shows invocationtargetexception at (TextView child = (TextView) vwParentRow.getChildAt(0);)
Sorry if this is very basic mistake. I am new to android.
Thank you for your reply.
It's better
TextView child = (TextView)findViewById("yourtextfieldIDHere");
child.setText("Delete Clicked");
my xml is like follow I want to add image view and text view programmatically to given xml.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="25dip" >
<TextView
android:id="#+text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="12dip"
android:text="#string/app_name"
android:textSize="24.5sp" />
</LinearLayout>
but I want output like following programmatically ie a linear layout contain image view and old text view and add that linearlayout below to new textview.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="25dip" >
<TextView
android:id="#+name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="12dip"
android:text="#string/app_name"
android:textSize="24.5sp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="25dip" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_marginBottom="12dip"
android:src="#drawable/app_icon_big" />
<TextView
android:id="#+text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="12dip"
android:text="#string/app_name"
android:textSize="24.5sp" />
</LinearLayout>
</LinearLayout>
Try this way,hope this will help you to solve your problem.
main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/outerLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="25dp" >
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:text="#string/app_name"
android:textSize="24.5sp" />
</LinearLayout>
MainActivity.java
public class MyActivity extends Activity {
private LinearLayout outerLinearLayout;
private TextView text1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
outerLinearLayout = (LinearLayout) findViewById(R.id.outerLinearLayout);
text1 = (TextView) findViewById(R.id.text1);
LinearLayout innerLinearLayout = new LinearLayout(this);
ImageView imageView = new ImageView(this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
params.bottomMargin=12;
imageView.setLayoutParams(params);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setImageResource(R.drawable.ic_launcher);
innerLinearLayout.addView(imageView);
TextView textView = new TextView(this);
textView.setTextSize((float) 24.5);
textView.setText("New Text View");
textView.setLayoutParams(params);
outerLinearLayout.removeAllViews();
innerLinearLayout.addView(text1);
outerLinearLayout.addView(textView);
outerLinearLayout.addView(innerLinearLayout);
}
}
change inner layout
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="25dip" >
By
<LinearLayout
android:id="#+id/internal_image_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="25dip"
android:visibility="gone" >
Then whenEver you want to show just
findViewById(R.id.internal_image_textView).setVisibility(View.VISIBLE)
im using custom listview in my main layout from here https://github.com/NikolaDespotoski/DoubleTapListViewHandler/tree/master/src/com/nikola/despotoski/doubletaplistview but problem is this wil create custom programicaly layout but in my code i already set content setContentView(R.layout.bid); so how do i add new custom layout in my main layout?? help me what will i do??
private CustomListView bidlist = null;
public class BidSchema extends BackBaseActivity implements OnItemDoubleTapLister {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.bid);
bidlist = new CustomListView(this);
bidlist.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
setContentView(bidlist);
back = (ImageView) findViewById(R.id.bidback);
bottomlayout = (RelativeLayout)findViewById(R.id.bottom_layout);
scroll_down = (ImageView) findViewById(R.id.down);
scroll_up = (ImageView) findViewById(R.id.up);
Layout XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bg2" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/top_bar1"
android:contentDescription="#string/contentdesc" />
<ImageView
android:id="#+id/bidback"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:layout_marginLeft="3dp"
android:background="#drawable/back_arr"
android:contentDescription="#string/contentdesc" />
<ImageView
android:id="#+id/iconpic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginTop="4dp"
android:layout_centerHorizontal="true"
android:background="#drawable/treasure"
android:contentDescription="#string/contentdesc" />
<TextView
android:id="#+id/bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/imageView1"
android:layout_centerHorizontal="true"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp"
android:background="#drawable/bar"
android:contentDescription="#string/contentdesc"
android:gravity="center"
android:text="Bid"
android:textColor="#000000"
android:textSize="22sp" />
<LinearLayout
android:id="#+id/jobhead"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/bar"
android:layout_marginTop="10dp"
android:layout_marginLeft="10sp"
android:orientation="horizontal" >
<TextView
android:id="#+id/jobDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="20dp"
android:textColor="#ffffff"
android:textSize="22sp"
android:gravity="left"
android:text="Plot"
android:textStyle="bold" />
<TextView
android:id="#+id/jobpick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="right"
android:paddingRight="50dp"
android:text="Job"
android:textColor="#ffffff"
android:textSize="22sp"
android:textStyle="bold" />
</LinearLayout>
<ListView
android:id="#+id/bidlist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/jobhead"
android:layout_marginBottom="10dp"
android:layout_above="#+id/bottomBar"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:background="#drawable/fields_bg"
android:visibility="visible" >
</ListView>
<include
android:id="#+id/bottomBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
layout="#layout/bottom" />
</RelativeLayout>
If you have implement custom Listview then you should change this.
setContentView(R.layout.bid);
bidlist = new CustomListView(this);
bidlist.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
setContentView(bidlist);
to
bidlist = new CustomListView(this);
bidlist.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
setContentView(bidlist);
UPDATE:
RelativeLayout rootLayout = (RelativeLayout) findViewById(R.id.layout);
bidlist = new CustomListView(this);
RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
rootLayout.addView(bidlist, rlp);
Because you can't call setContentView() two times. So you have to add it in your parent Relative Layout. so check that.
Give an id to your parent RelativeLayout as below to add new view to this layout later...
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bg2"
android:id="#+id/layout" >
..........
</RelativeLayout >
Now, add your bidlist to the parent layout as below...
RelativeLayout rootLayout = (RelativeLayout) findViewById(R.id.layout);
bidlist = new CustomListView(this);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
rootLayout.addView(bidlist, lp);
You don't setContentView.
If main activity show posted xml, just make Adapter implements baseAdapter, and then just listview.setAdapter( you make adapter)
I have an xml which contain imageview and textview.Textview is placed toRightOf ImageView , but when i try to inflate the xml imageView and textview is getting overlapped.Any help is appreciated
data.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:paddingBottom="5dp"
android:src="#drawable/payback" />
<TextView
android:id="#+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#+id/img"
android:paddingTop="5dp"
android:text="33%" />
<TextView
android:id="#+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/img"
android:paddingBottom="10dp"
android:text="Important and Urgent" />
</RelativeLayout>
Activity Code
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.check);
content=(LinearLayout)findViewById(R.id.content);
today=(TextView)findViewById(R.id.today);
tomorrow=(TextView)findViewById(R.id.tomorrow);
today.setOnClickListener(new TextView.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
//Toast.makeText(ToDo.this, "Before"+content.getChildCount(), Toast.LENGTH_LONG).show();
content.removeAllViews();
inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
int id=0;
for (int idx = 0; idx < 4; idx++) {
id = idx + 1;
rel = (RelativeLayout) inflater.inflate(R.layout.data, null);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
params.setMargins(0, 50, 0, 0);
txt = (TextView) rel.findViewById(R.id.txt);
txt.setText("AAA"+idx);
img = (ImageView) rel.findViewById(R.id.img);
img.setImageResource(R.drawable.payback);
img.setId(id);
content.addView(rel, params);
}
content.setVisibility(View.VISIBLE);
}
});
}
check.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/whiteboard"
android:layout_width="250dp"
android:layout_height="300dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp"
android:background="#FFFFFF" >
<Button
android:id="#+id/add"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="17dp"
android:layout_marginLeft="20dp"
android:text="Add" />
<View
android:id="#+id/bottomseperator"
android:layout_width="200dp"
android:layout_height="1dp"
android:layout_above="#+id/add"
android:layout_alignLeft="#+id/add"
android:layout_marginBottom="10dp"
android:background="#000000" />
<View
android:id="#+id/topseperator"
android:layout_width="220dp"
android:layout_height="1dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="35dp"
android:background="#000000" />
<TextView
android:id="#+id/day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="20dp"
android:layout_marginTop="8dp"
android:text="Day :"
android:textSize="15sp" />
<TextView
android:id="#+id/today"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/day"
android:layout_alignBottom="#+id/day"
android:layout_toRightOf="#+id/day"
android:text="Today /"
android:textSize="15sp" />
<TextView
android:id="#+id/tomorrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/today"
android:layout_alignBottom="#+id/today"
android:layout_toRightOf="#+id/today"
android:text="Tomorrow /"
android:textSize="15sp" />
<TextView
android:id="#+id/custom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/tomorrow"
android:layout_alignBottom="#+id/tomorrow"
android:layout_toRightOf="#+id/tomorrow"
android:text="Custom"
android:textSize="15sp" />
<ScrollView
android:id="#+id/contenntscroll"
android:layout_width="200dip"
android:layout_height="200dip"
android:layout_alignBottom="#+id/whiteboard"
android:layout_alignTop="#+id/whiteboard"
android:layout_below="#+id/topseperator"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:isScrollContainer="false"
android:scrollbars="none" >
<LinearLayout
android:id="#+id/content"
android:layout_width="200dp"
android:layout_height="300dp"
android:layout_marginTop="30dp"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</RelativeLayout>
</RelativeLayout>
The statement:
img.setId(id);
is causing the problem remove this statement the code would work.