Code example for TableRow

Methods: addView, setOnClickListener

0
     
    /* 
     * this function add the value to the row 
     */ 
    void addRow(String param,final int i){
    	tr.setOnClickListener(new OnClickListener() {
 
			@Override 
			public void onClick(View v) {				
				 
				String accname = projectStatementGrid.get(i).get(1).toString();
				 
				if(!(accname.equalsIgnoreCase("") ||
						accname.equalsIgnoreCase("Account Name"))){
					//change the row color(black/gray to orange) when clicked 
					View row = projectStatementTable.getChildAt(i+1);
					for (int j = 0; j < ColumnNameList.length; j++) {
						LinearLayout l = (LinearLayout) ((ViewGroup) row)
								.getChildAt(j);
						TextView t = (TextView) l.getChildAt(0);
						ColorDrawable drawable = (ColorDrawable)t.getBackground();
						System.out.println("color:"+drawable.getColor());
 
						ObjectAnimator colorFade = ObjectAnimator.ofObject(t, "backgroundColor", new ArgbEvaluator(), Color.parseColor("#FBB117"),drawable.getColor());
						colorFade.setDuration(100);
						colorFade.start();
					}					 
					 
					acc_name1 = accname;
					Intent intent = new Intent(getApplicationContext(),ledger.class);
					intent.putExtra("flag", "from_projStatement");
					startActivity(intent);
				} 
			} 
    	}); 
    	 
        label = new TextView(this);
        label.setText(param);
        label.setTextSize(18);
        label.setTextColor(Color.WHITE);
        label.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.WRAP_CONTENT));
        label.setPadding(2, 2, 2, 2);
        LinearLayout Ll = new LinearLayout(this);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.MATCH_PARENT);
        params.setMargins(1, 1, 1, 1);
        Ll.addView(label,params);
        tr.addView((View)Ll); // Adding textView to tablerow.
        
    } 
    public void onBackPressed() { 
		 
		MainActivity.nameflag = false;