用java来布局activity(贴个代码),动态生成页面,_移动开发_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > 移动开发 > 用java来布局activity(贴个代码),动态生成页面,

用java来布局activity(贴个代码),动态生成页面,

 2011/1/15 7:48:44  serryzhao  http://serryzhao.javaeye.com  我要评论(0)
  • 摘要:虽然功能上实现了但是布局上不够漂亮,很丑啊,考虑用网页的方式来实现,思路如果可以借鉴请借鉴。作用主要是动态生成一些页面控件,大家有好的思路也可以提供给我啊。或者修改这段代码,layout.xml方式暂时不考虑typeindex=0;adindex=0;for(inti=0;i<list.size();i++){finalinttempint=i;Stringflag=list.get(i).getFlg();RelativeLayoutrel=newRelativeLayout(Act
  • 标签:Java 代码 Activity
虽然功能上实现了但是布局上不够漂亮,很丑啊,考虑用网页的方式来实现,思路如果可以借鉴请借鉴。作用主要是动态生成一些页面控件,大家有好的思路也可以提供给我啊。或者修改这段代码,layout.xml方式暂时不考虑

typeindex = 0;
		adindex = 0;
		for(int i = 0; i <list.size();i++){
			final int tempint = i;
			String flag = list.get(i).getFlg();
			RelativeLayout rel = new RelativeLayout(Act.this);
			rel.setGravity(Gravity.CENTER_HORIZONTAL);
			RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
					ViewGroup.LayoutParams.WRAP_CONTENT);
			if("1".equals(flag)){
				TextView t = new TextView(Act.this);
				t.setText("类 型:");
				t.setTextColor(R.color.define_blue);
				t.setTextSize(18);
				t.setId(1);
				RelativeLayout rel2 = new RelativeLayout(Act.this);
				RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
					ViewGroup.LayoutParams.WRAP_CONTENT);
				
				final EditText tt = new EditText(Act.this);
				tt.setBackgroundDrawable(getResources().getDrawable(R.drawable.select_edit));
				tt.setEnabled(false);
				tt.setSingleLine();
				tt.setId(2);
				ImageView image1 = new ImageView(Act.this);
				image1.setImageDrawable(getResources().getDrawable(R.drawable.select));
				image1.setOnClickListener(new OnClickListener() {
					
					@Override
					public void onClick(View v) {
						List<SelectBean> selectList = list.get(tempint).getList();
						final String[] names = new String[selectList.size()];
						final String[] ids = new String[selectList.size()];
						for(int i=0;i<selectList.size();i++){
							names[i] = selectList.get(i).getName();
							ids[i] = selectList.get(i).getId();
						}
						
						dialog =	 new AlertDialog.Builder(Act.this)
		                .setTitle("请选择类型")
		                .setSingleChoiceItems(names, typeindex, new DialogInterface.OnClickListener() {
		                    public void onClick(DialogInterface dialog, int whichButton) {
								typeindex = whichButton;
		                    }
		                }).setPositiveButton("确 定", new DialogInterface.OnClickListener() {
		                    public void onClick(DialogInterface dialog, int id) {
		                    	tt.setText(names[typeindex]);
		                    	typeStr = "&"+list.get(tempint).getArg_name()+"="+ids[typeindex];
		                    }
		               })
		               .setNegativeButton("取 消", new DialogInterface.OnClickListener() {
		            	   public void onClick(DialogInterface dialog, int id) {
		            		 
		                   }
		               }).create();
						dialog.show();
					}
				});
				rel2.addView(tt);
				lp2.addRule(RelativeLayout.RIGHT_OF, tt.getId());
				rel2.addView(image1,lp2);
				lp.addRule(RelativeLayout.RIGHT_OF,t.getId());
				
				rel.addView(t);
				rel.addView(rel2,lp);
			}else if("2".equals(flag)){
				TextView t = new TextView(Act.this);
				t.setText("前 缀:");
				t.setTextColor(R.color.define_blue);
				t.setTextSize(18);
				t.setId(1);
				RelativeLayout rel2 = new RelativeLayout(Act.this);
				RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
					ViewGroup.LayoutParams.WRAP_CONTENT);
				
				final EditText tt = new EditText(Act.this);
				tt.setBackgroundDrawable(getResources().getDrawable(R.drawable.select_edit));
				tt.setEnabled(false);
				tt.setSingleLine();
				tt.setId(2);
				ImageView image1 = new ImageView(Act.this);
				image1.setImageDrawable(getResources().getDrawable(R.drawable.select));
				image1.setOnClickListener(new OnClickListener() {
					
					@Override
					public void onClick(View v) {
						List<SelectBean> selectList1 = list.get(tempint).getList();
						final String[] namess = new String[selectList1.size()];
						final String[] idss = new String[selectList1.size()];
						for(int i=0;i<selectList1.size();i++){
							namess[i] = selectList1.get(i).getName();
							idss[i] = selectList1.get(i).getId();
						}
						
						dialog =	 new AlertDialog.Builder(Act.this)
		                .setTitle("前 缀:")
		                .setSingleChoiceItems(namess, adindex, new DialogInterface.OnClickListener() {
		                    public void onClick(DialogInterface dialog, int whichButton) {
		                    	adindex = whichButton;
		                    }
		                }).setPositiveButton("确 定", new DialogInterface.OnClickListener() {
		                    public void onClick(DialogInterface dialog, int id) {
		                    	tt.setText(namess[adindex]);
		                    	adStrx = namess[adindex];
		                    	adStr = "&"+list.get(tempint).getArg_name()+"="+idss[adindex];
		                    }
		               })
		               .setNegativeButton("取 消", new DialogInterface.OnClickListener() {
		            	   public void onClick(DialogInterface dialog, int id) {
		            	
		                   }
		               }).create();
						dialog.show();
					}
				});
				rel2.addView(tt);
				lp2.addRule(RelativeLayout.RIGHT_OF, tt.getId());
				rel2.addView(image1,lp2);
				lp.addRule(RelativeLayout.RIGHT_OF,t.getId());
				
				rel.addView(t);
				rel.addView(rel2,lp);
			}else if("3".equals(flag)){
				TextView t = new TextView(Act.this);
				t.setText("号 :");
				t.setTextColor(R.color.define_blue);
				t.setTextSize(18);
				t.setId(1);
				tt3 = new EditText(Act.this);
				tt3.setBackgroundDrawable(getResources().getDrawable(R.drawable.text));
				lp.addRule(RelativeLayout.RIGHT_OF,t.getId());
				rel.addView(t);
				rel.addView(tt3,lp);
			}else if("4".equals(flag)){
				TextView t = new TextView(Act.this);
				t.setText(" 号:");
				t.setTextColor(R.color.define_blue);
				t.setTextSize(18);
				t.setId(1);
				tt4 = new EditText(Act.this);
				tt4.setBackgroundDrawable(getResources().getDrawable(R.drawable.text));
				lp.addRule(RelativeLayout.RIGHT_OF,t.getId());
				rel.addView(t);
				rel.addView(tt4,lp);
			}else if("5".equals(flag)){
				TextView t = new TextView(Act.this);
				t.setText("代 码:");
				t.setTextColor(R.color.define_blue);
				t.setTextSize(18);
				t.setId(1);
				tt5 = new EditText(Act.this);
				tt5.setBackgroundDrawable(getResources().getDrawable(R.drawable.text));
				lp.addRule(RelativeLayout.RIGHT_OF,t.getId());
				rel.addView(t);
				rel.addView(tt5,lp);
			}else if("6".equals(flag)){
				TextView t = new TextView(Act.this);
				t.setText("编 号:");
				t.setTextColor(R.color.define_blue);
				t.setTextSize(18);
				t.setId(1);
				tt6 = new EditText(Act.this);
				tt6.setBackgroundDrawable(getResources().getDrawable(R.drawable.text));
				lp.addRule(RelativeLayout.RIGHT_OF,t.getId());
				rel.addView(t);
				rel.addView(tt6,lp);
			}else if("9".equals(flag)){
				TextView t = new TextView(Act.this);
				t.setText("号: ");
				t.setTextColor(R.color.define_blue);
				t.setTextSize(18);
				t.setId(1);
				tt9 = new EditText(Act.this);
				tt9.setBackgroundDrawable(getResources().getDrawable(R.drawable.text));
				lp.addRule(RelativeLayout.RIGHT_OF,t.getId());
				rel.addView(t);
				rel.addView(tt9,lp);
			}
			
			linear.addView(rel);
		}
	}


发表评论
用户名: 匿名