android 控件初始化自动生成代码

public static void main(String[] args) {
		
		String s="    private LinearLayout l_collecting, l_project_over;\n" +
	            "    private RelativeLayout r_collect_stoptime, r_repay_interest_starttime, r_project_stoptime;\n" +
	            "    private TextView txt_project_name, txt_rate_year, txt_invest_progress, txt_enable_invest_money, txt_invest_situation,\n" +
	            "            txt_getted_interest, txt_predict_interest, txt_invest_total_money,\n" +
	            "            txt_project_num, txt_collect_starttime, txt_collect_stoptime, txt_repay_starttime, txt_project_stoptime;\n" +
	            "    private TextView txt_income_situation;\n" +
	            "    private ImageView img_special_project;\n" +
	            "    private Button but_re_invest;";
		
		String[] vars = s.replace("    private ", "").replace("    public ", "").replace("\n", "").split(";");
		
		for (String string : vars) {
			String [] controllers = string.split(",");
			
			String type=controllers[0].split(" ")[0];
			String first=controllers[0].split(" ")[1];

			boolean isFirst=true;
			for (String string2 : controllers) {
				
				if(isFirst){
				System.out.println( first + "=("+type+")findViewById(R.id."+first+");");
				isFirst=false;
				}else{
					System.out.println( string2.trim() + "=("+type+")findViewById(R.id."+string2.trim()+");");
				}
			}

			System.out.println();
		}

	}

  

posted on 2016-01-08 13:52  jiezzy  阅读(525)  评论(0)    收藏  举报