Code example for TableLayout

Methods: getChildAt

0
	 * @param achievement achievement to add 
	 */ 
	protected void addAchievement(Achievement achievement) {
		 
		// get first row 
		TableRow tableRow1 = (TableRow)table.getChildAt(row);
		tableRow1.setVisibility(View.VISIBLE);
		 
		// get imageview 
		ImageView imageView = (ImageView)tableRow1.getChildAt(0);
		imageView.setImageResource(achievement.getIcon());
		 
		// get textview 
		TextView textView1 = (TextView)tableRow1.getChildAt(1);
		textView1.setText(getResources().getString(achievement.getTitle()));
		 
		row++;
 
		// get second row 
		TableRow tableRow2 = (TableRow)table.getChildAt(row);
		tableRow2.setVisibility(View.VISIBLE);
		 
		// set progress bar 
		ProgressBar progressBar = (ProgressBar)tableRow2.getChildAt(0);
		 
		if (achievement.getProgress() > 0) {
			progressBar.setProgress((int)(achievement.getProgress()*100));
		} 
		// progress for num powerups/upgrades/achievements achievements 
		else { 
			if (achievement.equals(Achievements.globalUnlockAllAchievements)) {
				progressBar.setProgress((int)(100.0*Achievements.getNumAchievementsUnlocked()/Achievements.GLOBAL_NUM_ACHIEVEMENTS));
			} else if (achievement.equals(Achievements.globalUnlockAllPowerups)) {
				progressBar.setProgress((int)(100.0*Upgrades.getNumPowerupsAvailable()/Achievements.GLOBAL_NUM_POWERUPS));
			} else if (achievement.equals(Achievements.globalPurchaseAllUpgrades)) {
				progressBar.setProgress((int)(100.0*Upgrades.getNumUpgradesPurchased()/Achievements.GLOBAL_NUM_UPGRADES));
			} 
		} 
 
		row++;
		 
		// get third row 
		TableRow tableRow3 = (TableRow)table.getChildAt(row);
		tableRow3.setVisibility(View.VISIBLE);
		 
		// get textview 
		TextView textView2 = (TextView)tableRow3.getChildAt(0);
		textView2.setText(achievement.getDescription());