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);
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;
}
My MainAactivity starts with a background music( via service) and I have implemented an animation which should start as soon as the activity is launched along with the background music, but the animation starts after 10 seconds of activity launch(music starts with activity launch), even though I have not implemented any start delay. Can someone help me? I am new to android.
I have followed the following tutorial for animation:
https://www.javacodegeeks.com/2012/10/android-leaf-fall-like-animation-using.html
My MainActivity.java:
private int[] PICTURES = {
R.mipmap.f1, R.mipmap.f2, R.mipmap.f3, R.mipmap.f4,
};
private Rect display_Size = new Rect();
private RelativeLayout root_Layout;
private ArrayList<View> all_imageViews = new ArrayList<View>();
private float scale;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent i = new Intent(this,MusicService.class);
startService(i);
Display display = getWindowManager().getDefaultDisplay();
display.getRectSize(display_Size);
DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);
scale = metrics.density;
root_Layout = (RelativeLayout) findViewById(R.id.main_layout);
new Timer().schedule(new ExecTime(),0 , 1000);
}
private Handler handler = new Handler() {
#Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
int viewId = new Random().nextInt(PICTURES.length);
Drawable d = getResources().getDrawable(PICTURES[viewId]);
LayoutInflater inflater = LayoutInflater.from(MainActivity.this);
ImageView imageView = (ImageView) inflater.inflate(R.layout.animated_image_view, null);
imageView.setImageDrawable(d);
root_Layout.addView(imageView);
all_imageViews.add(imageView);
RelativeLayout.LayoutParams animationLayout = (RelativeLayout.LayoutParams) imageView.getLayoutParams();
animationLayout.setMargins(0, (int)(-3000*scale), 0, 0);
animationLayout.width = (int) (50*scale);
animationLayout.height = (int) (50*scale);
startAnimation(imageView);
}
};
public void startAnimation(final ImageView animView) {
animView.setPivotX(animView.getWidth()/2);
animView.setPivotY(animView.getHeight()/2);
final ValueAnimator animator = ValueAnimator.ofFloat(0, 1);
animator.setDuration(15000);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
int angle = 50 + (int)(Math.random() * 101);
int move = new Random().nextInt(display_Size.right);
#Override
public void onAnimationUpdate(ValueAnimator animation) {
float value = (Float) (animation.getAnimatedValue());
animView.setRotation(angle*value);
animView.setTranslationX((move-100)*value);
animView.setTranslationY((display_Size.bottom + (3000*scale))*value);
}
});
animator.start();
}
private class ExecTime extends TimerTask {
#Override
public void run() {
handler.sendEmptyMessage(Constants.EMPTY_MESSAGE);
}
}
When application is launched android creates a new process that during it charge and create a black/white screen based on the application theme or the theme of the activity that is entry point.
This load can be increased if our application is complex and overwrites the application object, which is normally used to initialize the analytics.
Read this article for more info. http://saulmm.github.io/avoding-android-cold-starts
I have a LinearLayout into my PopupView, and a button into this LinearLayout. Event listener of this button works correctly, but animation of pressing (highlighting) is not starting. What I did wrong? Please, gelp!
public class PopupView extends View
{
private PopupWindow popUp;
private Button buttonOk;
private OnClickListener onClick;
private LayoutParams params;
private int popUpWidth = 0;
private int popUpHeight = 0;
private int popUpX, popUpY;
public PopupView(Context context, View parent)
{
super(context);
popUp = new PopupWindow(context);
popUpLayout = new LinearLayout(context);
buttonOk = new Button(context);
buttonOk.setText("OK");
buttonOk.setId(1);
params = new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
popUpLayout.setOrientation(LinearLayout.VERTICAL);
popUp.setContentView(popUpLayout);
onClick = new OnClickListener()
{
public void onClick (View v)
{
switch (v.getId())
{
case 1:
System.out.println("OK pressed!");
break;
case 2:
break;
}
}
};
buttonOk.setOnClickListener(onClick);
popUpLayout.removeAllViews();
popUpLayout.addView(buttonOk, params);
popUpWidth = 200;
popUpHeight = 400;
popUpX = 300;
popUpY = 300;
popUp.showAtLocation(parent, Gravity.NO_GRAVITY, popUpX, popUpY);
popUp.update(popUpX, popUpY, popUpWidth, popUpHeight);
}
}
In default PopupView is not focusble. Need to call method popup.setFocusable(true). Thanks for all!
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.
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);
}
}
}