Hi All,
I have to design UI such that I can update the screen with different
views.I have created views dynamically in code.Created two function.
1.first view - > firstview()
2.second  view-> secondview()
On start of the activity I am calling API secondview so that screen
gets updated with the second view. I have started timer of 5 sec in
the end of secondview() function and wants the screen to get updated
with the first view i.e through the call of firstview().But observed
that after 5 sec screen is not getting updated with the first
view.Below are my functions.Please guide me to resolve the issue.

private
void secondview(String string, String string2) {
RelativeLayout tl = (RelativeLayout)findViewById
(R.id.
DisplayCells);
RelativeLayout.LayoutParams params =
new RelativeLayout.LayoutParams
(LayoutParams.
WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
TextView author1 =
new TextView(this);
author1.setText(string);
author1.setTextSize(16);
author1.setId(1);
params.addRule(RelativeLayout.
ALIGN_PARENT_LEFT);
params.
height = 130;
params.
width = 230;
params.setMargins(5, 5, 5, 5);
author1.setBackgroundColor(Color.
WHITE);
author1.setTextColor(Color.
BLUE);
author1.setLayoutParams(params);
tl.addView(author1);
TextView title1 =
new TextView(this);
title1.setText(string2);
title1.setTextSize(16);
title1.setId(2);
RelativeLayout.LayoutParams params2 =
new RelativeLayout.LayoutParams
(LayoutParams.
WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params2.addRule(RelativeLayout.
BELOW,1);
params2.
height = 130;
params2.
width = 230;
params2.setMargins(5, 5, 5, 5);
title1.setBackgroundColor(Color.
WHITE);
author1.setTextColor(Color.
BLUE);
title1.setLayoutParams(params2);
tl.addView(title1);
timer.schedule(new TimerTask() {
public void run() {
firstview(
"amar","akbar","anthony","Hero");
}
}, 5000);
}
private
void firstview(String string, String string2,String string3,String
string4) {
RelativeLayout tl1 = (RelativeLayout)findViewById
(R.id.
DisplayCell);
RelativeLayout.LayoutParams params =
new RelativeLayout.LayoutParams
(LayoutParams.
WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
TextView author =
new TextView(this);
author.setText(string);
author.setTextSize(16);
author.setId(1);
params.addRule(RelativeLayout.
ALIGN_PARENT_LEFT);
params.
height = 130;
params.
width = 110;
params.setMargins(5, 5, 5, 5);
author.setBackgroundColor(Color.
WHITE);
author.setTextColor(Color.
BLUE);
author.setLayoutParams(params);
TextView title =
new TextView(this);
title.setText(string2);
title.setTextSize(16);
title.setId(2);
tl1.addView(author);
(Observed that in debugging mode after executing this line control is
not going to the next line.)
RelativeLayout.LayoutParams params2 =
new RelativeLayout.LayoutParams
(LayoutParams.
WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params2.addRule(RelativeLayout.
RIGHT_OF,1);
params2.
height = 130;
params2.
width = 110;
params2.setMargins(5, 5, 5, 5);
title.setBackgroundColor(Color.
WHITE);
author.setTextColor(Color.
BLUE);
title.setLayoutParams(params2);
tl1.addView(title);
RelativeLayout.LayoutParams params3 =
new RelativeLayout.LayoutParams
(LayoutParams.
WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
TextView book =
new TextView(this);
book.setText(string3);
book.setTextSize(16);
params3.addRule(RelativeLayout.
BELOW,2);
params3.addRule(RelativeLayout.
ALIGN_PARENT_RIGHT);
params3.
height = 130;
params3.
width = 110;
params3.setMargins(5, 5, 5, 5);
book.setBackgroundColor(Color.
WHITE);
book.setTextColor(Color.
BLUE);
book.setLayoutParams(params3);
tl1.addView(book);
RelativeLayout.LayoutParams params4 =
new RelativeLayout.LayoutParams
(LayoutParams.
WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
TextView four =
new TextView(this);
four.setText(string4);
four.setTextSize(16);
params4.addRule(RelativeLayout.
BELOW,1);
params4.addRule(RelativeLayout.
ALIGN_PARENT_LEFT);
params4.
height = 130;
params4.
width = 110;
params4.setMargins(5, 5, 5, 5);
four.setBackgroundColor(Color.
WHITE);
four.setTextColor(Color.
BLUE);
four.setLayoutParams(params4);
tl1.addView(four);
}
This is the XML file content:
<?
xml version="1.0" encoding="utf-8"?>
<
FrameLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<
RelativeLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:id = "@+id/DisplayCells"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</
RelativeLayout>
<
RelativeLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:id = "@+id/DisplayCell"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</
RelativeLayout>
</
FrameLayout>

Thanks,
Shekhar

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to