I am adding few TextViews to a RelativeLayout. I have extended RelativeLayout. I could add the TextView in the constructor definition. I could see the item on the viw. But the same code, when I use in onPostExecute of AyncTask or use post() method, TextView is not seen added to the layout. Same coe is executed both place. I just changed the top margin.
Here is my code
TextView tv = new TextView(context);
addView(tv);
tv.setHeight(49);
tv.setWidth(100);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.leftMargin = (int) 0;
params.topMargin = (int) 600;
tv.setLayoutParams(params);
================ Implementation ================================
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
DateDetailsScrollView sc = new DateDetailsScrollView(container.getContext());
new SyncInThread().execute(sc);
return sc;
}
================= AsyncTask ===================================
private static class SyncInThread extends AsyncTask<Object, Void, String> {
private ArrayList<EVT> _mEvents = new ArrayList<EVT>();
DateDetailsScrollView _lv = null;
#Override
protected String doInBackground(Object... cal) {
_lv = (DateDetailsScrollView)cal[0];
//The SQL cannot be shared here... Please forgive me.
boolean f = cursor.moveToFirst();
while(f) {
EVT evt = new EVT();
evt.loadFromCursor(cursor);
f = cursor.moveToNext();
_mEvents.add(evt);
cc++;
}
return "";
}
#Override
protected void onPostExecute(String result) {
for(EVT ev : _EVT) {
_lv.addEvent(ev);
}
}
}
public class DateDetailsScrollView extends ScrollView {
private EventRelativeLayout _mEventLayout = null;
public DateDetailsScrollView(Context context) {
super(context);
_mEventLayout = new EventRelativeLayout(context);
ll.addView(_mEventLayout);
LinearLayout ll = new LinearLayout(context);
ll.setOrientation(LinearLayout.HORIZONTAL);
addView(ll);
}
public void addEvent(final VEVENT evt) {
_mEventLayout.addEvent(evt);
invalidate();
this.refreshDrawableState();
}
}
public class EventRelativeLayout extends RelativeLayout {
public EventRelativeLayout(Context context) {
//This works fine.
super(context);
TextView tv = new TextView(context);
addView(tv);
int[] colors = { 0xFF052d42, 0xFF096da0 };
GradientDrawable drawable = new GradientDrawable(
GradientDrawable.Orientation.TOP_BOTTOM, colors);
tv.setBackgroundColor(0xFF290202);
tv.setBackgroundDrawable(drawable);
tv.setHeight(49);
tv.setWidth(100);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.leftMargin = (int) 0;
params.topMargin = (int) 100;
tv.setLayoutParams(params);
}
public void addEvent(EVT evt) {
TextView tv = new TextView(getContext());
addView(tv);
int[] colors = { 0xFF052d42, 0xFF096da0 };
GradientDrawable drawable = new GradientDrawable(
GradientDrawable.Orientation.TOP_BOTTOM, colors);
tv.setBackgroundColor(0xFF290202);
tv.setBackgroundDrawable(drawable);
tv.setHeight(100);
int dm = em -eh;
int dh = eh - sh;
if( dm < 0) {
dm += 60;
dh--;
}
tv.setWidth(100);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.leftMargin = 0;
params.topMargin = 600;
tv.setHeight(49);
tv.setLayoutParams(params);
}
}
I got the issue. It was a programmatic mistake and due to a wrong calculation, the veiw was added to a different page.
Related
I'm creating a ScrollView, nesting in a RelativeLayout (which contains tables). Everything is properly added to the layout. The problem is: vertically scrolling works fine, but horizontal scrolling does NOT work at all. I already tested various combinations of MATCH_PARENT, WRAP_CONTENT and FILL_PARENT. No try even worked close. So my question is: What am I missing here?
Here is the code:
public class PlayerView extends View {
private RelativeLayout relativeLayout;
private TableLayout tableLayout;
private int player_loop;
private int player_count;
public PlayerView(Context context, int player_count){
super(context);
setPlayer_count(player_count);
}
public ScrollView create_scrollView(){
ScrollView scrollView = new ScrollView(getContext());
ScrollView.LayoutParams scroll_params = new ScrollView.LayoutParams(
ScrollView.LayoutParams.MATCH_PARENT,
ScrollView.LayoutParams.MATCH_PARENT
);
scrollView.setLayoutParams(scroll_params);
scrollView.addView(create_relativeLayout());
return scrollView;
}
public RelativeLayout create_relativeLayout(){
relativeLayout = new RelativeLayout(getContext());
RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT
);
relativeLayout.setLayoutParams(relativeParams);
create_Player_Table_Layout();
return relativeLayout;
}
public void create_Player_Table_Layout(){
for(player_loop = 1; player_loop <= player_count; player_loop++){
relativeLayout.addView(player_table(getResources().getString(R.string.dummy_player_name) + player_loop, player_loop));
}
}
public TableLayout player_table(String playername, int playernumber){
tableLayout = new TableLayout(getContext());
tableLayout.setId(playernumber * 1000);
if (playernumber > 1) {
//TABLE PLACEMENT
RelativeLayout.LayoutParams tbl_params_New = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
tbl_params_New.addRule(RelativeLayout.RIGHT_OF, (playernumber - 1) * 1000);
tableLayout.setLayoutParams(tbl_params_New);
}
//Add Playername
TableRow row_playername = new TableRow(getContext());
TextView view_name = new TextView(getContext());
TableRow.LayoutParams view_name_params = new TableRow.LayoutParams();
view_name_params.setMargins(20,20,20,20);
view_name.setLayoutParams(view_name_params);
view_name.setGravity(Gravity.CENTER);
view_name.setText(playername);
view_name.setTextSize(20);
view_name.setId(playernumber * 100);
row_playername.addView(view_name);
tableLayout.addView(row_playername);
//Add Lifepoints
TableRow row_lifepoints = new TableRow(getContext());
TextView view_lifepoints = new TextView(getContext());
TableRow.LayoutParams view_lifepoints_params = new TableRow.LayoutParams();
view_lifepoints_params.setMargins(20, 0, 20, 20);
view_lifepoints.setText("40");
view_lifepoints.setTextSize(40);
view_lifepoints.setGravity(Gravity.CENTER);
view_lifepoints.setId(playernumber * 100 + 10);
view_lifepoints.setLayoutParams(view_lifepoints_params);
row_lifepoints.addView(view_lifepoints);
tableLayout.addView(row_lifepoints);
Log.d("Test", "Player count:" + player_count);
for(int opponent_loop = 1; opponent_loop <= player_count; opponent_loop++){
tableLayout.addView(commander_damage_from_player(player_loop, opponent_loop));
}
return tableLayout;
}
private TableRow commander_damage_from_player(int player_loop, int opponent_loop){
TableRow row = new TableRow(getContext());
TextView textView = new TextView(getContext());
TableRow.LayoutParams layoutParams = new TableRow.LayoutParams();
layoutParams.setMargins(20, 0, 40, 20);
textView.setLayoutParams(layoutParams);
textView.setText("0 | " + getResources().getString(R.string.dummy_player_name)+ " " + opponent_loop);
textView.setTextSize(20);
textView.setId(player_loop + 100 + opponent_loop);
row.addView(textView);
return row;
}
private void setPlayer_count(int player_count){
this.player_count = player_count;
}
}
And for documentation the calling class:
public class Home extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PlayerView playerView = new PlayerView(this, 8);
setContentView(playerView.create_scrollView());
}
}
The only way you can do this is by creating a horizontalscrollview to be the child of the scrollview. If you make the minor modification to your create_relativeLayout() to create a horizontalscroll view then it will work correctly. I have seen this happen in other examples.
public HorizontalScrollView create_relativeLayout(){
HorizontalScrollView horizontalScrollView = new HorizontalScrollView(getContext());
relativeLayout = new RelativeLayout(getContext());
RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT
);
relativeLayout.setLayoutParams(relativeParams);
create_Player_Table_Layout();
horizontalScrollView.addView(relativeLayout);
return horizontalScrollView;
}
I create programmatically few layouts and I need get width one of them, recalculate this value and change. All this action I do in onGlobalLayoutListener. But when I set a new width value, he doesnt change.
private RelativeLayout batteryContainer;
private LinearLayout batteryLeftSide;
private LinearLayout batteryRightSide;
public void drawBattery(){
handler.post(new Runnable() {
#Override
public void run() {
//Контейнер всієї батарейки
batteryContainer = new RelativeLayout(activity);
RelativeLayout.LayoutParams batteryContainerParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
batteryContainerParams.setMargins((int) convertDpToPixel(containerMarginLeft), (int) convertDpToPixel(containerMarginTop), (int) convertDpToPixel(containerMarginRight), (int) convertDpToPixel(containerMarginBottom));
if(layoutBelow != null){
batteryContainerParams.addRule(RelativeLayout.BELOW, layoutBelow.getId());
}
if(layoutAbove != null){
batteryContainerParams.addRule(RelativeLayout.ABOVE, layoutAbove.getId());
}
batteryContainer.setLayoutParams(batteryContainerParams);
batteryContainer.setBackgroundColor(Color.parseColor("#505050"));
batteryContainer.setId(containerId);
int leftWidth = 0;
int rightWidth = 0;
//Ліва частина батарейки
batteryLeftSide = new LinearLayout(activity);
batteryLeftSide.setOrientation(LinearLayout.HORIZONTAL);
RelativeLayout.LayoutParams batteryLeftSideParams = new RelativeLayout.LayoutParams((int)convertDpToPixel(leftWidth), (int)convertDpToPixel(sideHeight));
batteryLeftSideParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
batteryLeftSide.setLayoutParams(batteryLeftSideParams);
batteryLeftSide.setBackgroundColor(Color.parseColor("#900000"));
batteryLeftSide.setId(leftSideId);
//Права частина батарейки
batteryRightSide = new LinearLayout(activity);
batteryRightSide.setOrientation(LinearLayout.HORIZONTAL);
RelativeLayout.LayoutParams batteryRightSideParams = new RelativeLayout.LayoutParams((int)convertDpToPixel(rightWidth), (int)convertDpToPixel(sideHeight));
batteryRightSideParams.addRule(RelativeLayout.RIGHT_OF, batteryLeftSide.getId());
batteryRightSide.setLayoutParams(batteryRightSideParams);
batteryRightSide.setBackgroundColor(Color.parseColor("#009900"));
batteryRightSide.setId(rightSideId);
//Додамо праві та ліві сторони в контейнер
batteryContainer.addView(batteryLeftSide);
batteryContainer.addView(batteryRightSide);
//Додамо контейнер в кореневий Layout на активності
rootLayout.addView(batteryContainer);
//Обчислення яка сторона батарейки займе 50%
ViewTreeObserver observer = rootLayout.getViewTreeObserver();
observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
rootLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
int batteryContainerWidth = batteryContainer.getMeasuredWidth();
int halfPlace = batteryContainerWidth * 50 / 100;
trustFromMe = halfPlace;
if(trustToMe > trustFromMe){
batteryLeftSide.getLayoutParams().width = halfPlace;
}
if(trustToMe < trustFromMe){
batteryRightSide.getLayoutParams().width = halfPlace;
}
if(trustToMe == trustFromMe){
batteryLeftSide.getLayoutParams().width = halfPlace;
batteryRightSide.getLayoutParams().width = halfPlace;
}
}
});
//but width not change
}
});
}
Try adding this to the end of the GlobalLayoutListener:
rootLayout.requestLayout();
This should force the layout to redraw it's size. If this doesn't work you may want to try creating and setting new LayoutParams as well.
I have 3 frameLayout animated within these I have to put the fragments, but the method I use does not work. Where am I doing wrong?
11-28 11:18:41.979: E/AndroidRuntime(2263): java.lang.RuntimeException: Unable to start
activity ComponentInfo{com.eni.mobilewf/com.eni.mobilewf.MenuActivity}:
android.content.res.Resources$NotFoundException: Unable to find resource ID #0x1
MenuActiviyt.java
public class MenuActivity extends FragmentActivity {
static final int NUM_ITEMS = 3;
public static MenuActivity menuActivity = null;
public static ViewPager mPager;
private Interpolator interpolator = new LinearInterpolator();
private int width;
private int panel;
long animationDuration = 1000;
ThreeLayout layout;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
layout = new ThreeLayout(this, 3);
layout.setAnimationDuration(1000);
layout.setId(1234);
layout.fl1.setId(0x11);
layout.fl2.setId(0x22);
layout.fl3.setId(0x33);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();;
Log.i("test", "transaction " +transaction);
MenuFragment menu = new MenuFragment();
ListFragment lista = new ListFragment();
DetailFragment detail = new DetailFragment();
Log.i("test", "id fl1 " +layout.fl1.getId());
//id fl1 1
Log.i("test", "id fl2 " +layout.fl2.getId());
//id fl2 2
Log.i("test", "id fl3 " +layout.fl3.getId());
//id fl3 3
transaction.add(layout.fl1.getId(), menu, "fragment1");
transaction.add(layout.fl2.getId(), lista, "fragment2");
transaction.add(layout.fl3.getId(), detail, "fragment3");
transaction.commit();
setContentView(layout);
setupLayout();
}
ThreeLayout.java
public class ThreeLayout extends RelativeLayout {
private int width;
private int panel;
public FrameLayout fl1;
public FrameLayout fl2;
public FrameLayout fl3;
long animationDuration = 800;
private Interpolator interpolator = new LinearInterpolator();
public ThreeLayout(final Context context, final float leftWeight) {
super(context);
fl1 = new FrameLayout(context);
fl2 = new FrameLayout(context);
fl3 = new FrameLayout(context);
post(new Runnable() {
#Override
public void run() {
width = getWidth();
panel = (int) (width / leftWeight);
_initWithDimentionsPortrait(context);
}
});
}
private void _initWithDimentionsPortrait(Context context) {
RelativeLayout container = new RelativeLayout(context);
LayoutParams containerParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
container.setLayoutParams(containerParams);
containerParams.setMargins(0, 0, -width - panel, 0);
Log.i("test", "la largezza è " +new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
container.addView(fl1);
container.addView(fl2);
container.addView(fl3);
LayoutParams params1 = new LayoutParams(panel, LayoutParams.FILL_PARENT);
LayoutParams params2 = new LayoutParams(width - panel, LayoutParams.FILL_PARENT);
LayoutParams params3 = new LayoutParams(width - panel, LayoutParams.FILL_PARENT);
fl1.setLayoutParams(params1);
params2.addRule(RelativeLayout.RIGHT_OF, fl1.getId());
fl2.setLayoutParams(params2);
params3.addRule(RelativeLayout.RIGHT_OF, fl1.getId());
fl3.setLayoutParams(params3);
addView(container);
}
The fragment are not shown.Thanks in advance
Try to set the resource id of your views as some integer value besides hexa value as below:
layout.fl1.setId(1);
layout.fl2.setId(2);
layout.fl3.setId(3);
I am trying to keep two customviews and i kept fadein fadeout but i am not able to see both custom views am able to see only one custom view if i click on fadein i m able to see only one view but not both. but i am not able to see both views at a time please tell me where i did mistake.
MyView myview;
MyView1 myview1;
RelativeLayout relativeLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
myview=new MyView(this);
myview.setBackgroundColor(color.white);
setContentView(myview);
myview = new MyView(this);
myview.setBackgroundColor(Color.WHITE);
myview1=new MyView1(this);
myview1.setBackgroundColor(color.white);
setContentView(myview1);
myview1 = new MyView1(this);
myview1.setBackgroundColor(Color.WHITE);
RelativeLayout relativeLayout = new RelativeLayout(this);
relativeLayout.setId(0);
relativeLayout.setBackgroundColor(Color.WHITE);
myview = new MyView(this);
myview.setId(004);
RelativeLayout.LayoutParams lp6 = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
myview.setLayoutParams(lp6);
relativeLayout.addView(myview,lp6);
myview1 = new MyView1(this);
myview1.setId(8);
RelativeLayout.LayoutParams lp008 = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
myview1.setLayoutParams(lp008);
relativeLayout.addView(myview1,lp008);
Button button1 = new Button(this);
RelativeLayout.LayoutParams lp1=new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
button1.setText("click");
relativeLayout.addView(button1,lp1);
button1.setOnClickListener(this);
setContentView(relativeLayout);
}
public class MyView extends View {
public MyView(Context c) {
super(c);
}
protected void onDraw(Canvas canvas) {
Bitmap _scratch = BitmapFactory.decodeResource(getResources(),R.drawable.apple);
canvas.drawBitmap(_scratch, 840, 450, null);
}
}
public class MyView1 extends View{
public MyView1(Context context) {
super(context);
}
protected void onDraw(Canvas canvas) {
Bitmap scratch=BitmapFactory.decodeResource(getResources(), R.drawable.ant);
canvas.drawBitmap(scratch, 840, 450, null);
}
}
public void onClick(View v) {
if(myview1.getVisibility() == View.VISIBLE) {
Animation out = AnimationUtils.makeOutAnimation(this, true);
myview1.startAnimation(out);
myview1.setVisibility(View.INVISIBLE);
} else {
Animation in = AnimationUtils.loadAnimation(this, android.R.anim.fade_in);
myview1.startAnimation(in);
myview1.setVisibility(View.VISIBLE);
}
}
}
Use Views setVisibility method
I have a edit text inside an alert Dialog for some user input. But when I click on the edit text it does not show the soft keyboard.
Whereas if the same edit text is placed inside a dialog it show the keyboard when the edit text is focused.
public class LaunchingActivity extends Activity {
Button addSubList = null;
TableLayout tabLayToDoList;
int textViewId = StaticContents.textViewId;
int edtTxtViewId = StaticContents.edtTxtViewId;
int ImgViewId = StaticContents.ImgViewId;
int relLayViewId = StaticContents.relLayViewId;
int count = StaticContents.count;
CustomDialog share;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
System.out.println(textViewId + " " + edtTxtViewId + " " + ImgViewId
+ " " + relLayViewId);
addSubList = (Button) findViewById(R.id.btnAddSubItem);
tabLayToDoList = (TableLayout) findViewById(R.id.tabLayToDoList);
}
public void showSublistDialog() {
Dialog subList = new Dialog(this);
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
.getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
System.out.println("Display Width and Height :" + "width " + width
+ " height " + height);
subList.show();
// rel.setLayoutParams(layoutPrams);
}
#Override
protected void onPostResume() {
addSubList.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
count = 0;
share = new CustomDialog(LaunchingActivity.this);
share.show();
}
});
super.onPostResume();
}
private class CustomDialog extends Dialog {
public CustomDialog(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
RelativeLayout relLayParent;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.addsubitem);
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
.getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
LayoutParams params = getWindow().getAttributes();
if(height>width){
//potrait mode
params.height = height - 150;
params.width = width-60;
}else{
params.height = height - 100;
params.width = width-100;
}
getWindow().setAttributes(
(android.view.WindowManager.LayoutParams) params);
relLayParent = (RelativeLayout) findViewById(R.id.relLayParent);
addDesScription(relLayParent, R.id.relLaySubListContent);
addDesScription(relLayParent, R.id.relLaySubListContent);
}
public void addDesScription(RelativeLayout relParent, int relLayoutId) {
TextView txtDescription = new TextView(LaunchingActivity.this);
EditText edtDescription = new EditText(LaunchingActivity.this);
ImageView imgaddDescription = new ImageView(LaunchingActivity.this);
edtDescription.setInputType(262144);
RelativeLayout relLay = new RelativeLayout(LaunchingActivity.this);
textViewParams(txtDescription);
edttxtDescriptionParams(edtDescription);
imageViewParams(imgaddDescription);
relLaySubListDescription(relLay, relLayoutId);
relLay.addView(txtDescription);
relLay.addView(edtDescription);
relParent.addView(relLay);
if (count != 0) {
relLay.addView(imgaddDescription);
} else {
relLay.setVisibility(View.GONE);
}
incrementIds();
}
public void textViewParams(TextView txtDescription) {
txtDescription.setText("Description:");
txtDescription.setTextColor(getResources().getColor(R.color.Blue));
txtDescription.setId(textViewId);
txtDescription.setMinLines(1);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT,
android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
params.addRule(RelativeLayout.CENTER_VERTICAL);
txtDescription.setLayoutParams(params);
}
public void imageViewParams(ImageView addSubListDescription) {
addSubListDescription
.setImageResource(R.drawable.add_description_icon);
addSubListDescription.setId(ImgViewId);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT,
android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
params.addRule(RelativeLayout.CENTER_VERTICAL);
addSubListDescription.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View arg0, MotionEvent arg1) {
addDesScription(relLayParent, relLayViewId - 1);
return false;
}
});
addSubListDescription.setLayoutParams(params);
}
public void edttxtDescriptionParams(EditText edtDescription) {
edtDescription.setId(edtTxtViewId);
edtDescription.setMinLines(1);
edtDescription.setHint("Description");
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT,
android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.LEFT_OF, ImgViewId);
params.addRule(RelativeLayout.RIGHT_OF, textViewId);
params.addRule(RelativeLayout.CENTER_VERTICAL);
edtDescription.setLayoutParams(params);
}
public void incrementIds() {
ImgViewId++;
textViewId++;
edtTxtViewId++;
relLayViewId++;
count++;
}
public void relLaySubListDescription(
RelativeLayout relLaySubListDescription, int relLayoutId) {
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT,
android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT);
params.width = android.widget.RelativeLayout.LayoutParams.FILL_PARENT;
relLaySubListDescription.setId(relLayViewId);
params.addRule(RelativeLayout.BELOW, relLayoutId);
relLaySubListDescription.setLayoutParams(params);
}
}
}
public class LaunchingActivity extends Activity {
Button addSubList = null;
TableLayout tabLayToDoList;
int textViewId = StaticContents.textViewId;
int edtTxtViewId = StaticContents.edtTxtViewId;
int ImgViewId = StaticContents.ImgViewId;
int relLayViewId = StaticContents.relLayViewId;
int count = StaticContents.count;
CustomDialog share;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
System.out.println(textViewId + " " + edtTxtViewId + " " + ImgViewId
+ " " + relLayViewId);
addSubList = (Button) findViewById(R.id.btnAddSubItem);
tabLayToDoList = (TableLayout) findViewById(R.id.tabLayToDoList);
}
public void showSublistDialog() {
Dialog subList = new Dialog(this);
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
.getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
System.out.println("Display Width and Height :" + "width " + width
+ " height " + height);
subList.show();
// rel.setLayoutParams(layoutPrams);
}
#Override
protected void onPostResume() {
addSubList.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
count = 0;
share = new CustomDialog(LaunchingActivity.this);
share.show();
}
});
super.onPostResume();
}
private class CustomDialog extends Dialog {
public CustomDialog(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
RelativeLayout relLayParent;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.addsubitem);
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
.getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
LayoutParams params = getWindow().getAttributes();
if(height>width){
//potrait mode
params.height = height - 150;
params.width = width-60;
}else{
params.height = height - 100;
params.width = width-100;
}
getWindow().setAttributes(
(android.view.WindowManager.LayoutParams) params);
relLayParent = (RelativeLayout) findViewById(R.id.relLayParent);
addDesScription(relLayParent, R.id.relLaySubListContent);
addDesScription(relLayParent, R.id.relLaySubListContent);
}
public void addDesScription(RelativeLayout relParent, int relLayoutId) {
TextView txtDescription = new TextView(LaunchingActivity.this);
EditText edtDescription = new EditText(LaunchingActivity.this);
ImageView imgaddDescription = new ImageView(LaunchingActivity.this);
edtDescription.setInputType(262144);
RelativeLayout relLay = new RelativeLayout(LaunchingActivity.this);
textViewParams(txtDescription);
edttxtDescriptionParams(edtDescription);
imageViewParams(imgaddDescription);
relLaySubListDescription(relLay, relLayoutId);
relLay.addView(txtDescription);
relLay.addView(edtDescription);
relParent.addView(relLay);
if (count != 0) {
relLay.addView(imgaddDescription);
} else {
relLay.setVisibility(View.GONE);
}
incrementIds();
}
public void textViewParams(TextView txtDescription) {
txtDescription.setText("Description:");
txtDescription.setTextColor(getResources().getColor(R.color.Blue));
txtDescription.setId(textViewId);
txtDescription.setMinLines(1);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT,
android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
params.addRule(RelativeLayout.CENTER_VERTICAL);
txtDescription.setLayoutParams(params);
}
public void imageViewParams(ImageView addSubListDescription) {
addSubListDescription
.setImageResource(R.drawable.add_description_icon);
addSubListDescription.setId(ImgViewId);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT,
android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
params.addRule(RelativeLayout.CENTER_VERTICAL);
addSubListDescription.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View arg0, MotionEvent arg1) {
addDesScription(relLayParent, relLayViewId - 1);
return false;
}
});
addSubListDescription.setLayoutParams(params);
}
public void edttxtDescriptionParams(EditText edtDescription) {
edtDescription.setId(edtTxtViewId);
edtDescription.setMinLines(1);
edtDescription.setHint("Description");
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT,
android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.LEFT_OF, ImgViewId);
params.addRule(RelativeLayout.RIGHT_OF, textViewId);
params.addRule(RelativeLayout.CENTER_VERTICAL);
edtDescription.setLayoutParams(params);
}
public void incrementIds() {
ImgViewId++;
textViewId++;
edtTxtViewId++;
relLayViewId++;
count++;
}
public void relLaySubListDescription(
RelativeLayout relLaySubListDescription, int relLayoutId) {
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT,
android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT);
params.width = android.widget.RelativeLayout.LayoutParams.FILL_PARENT;
relLaySubListDescription.setId(relLayViewId);
params.addRule(RelativeLayout.BELOW, relLayoutId);
relLaySubListDescription.setLayoutParams(params);
}
}
}