I have a huge layout for my activity that i set using setContentView()
. In that layout I have a TableLayout
(named tableLayout
in my Activity) that I want to populate. The rows of that TableLayout are customViews in a layout file(let's call that file tablerow_layout.xml
). Inside this layout i have some TextViews and ImageView. What I want to do is change the content of the TextView programatically, when I create the row. This is my code:
LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View newRow = layoutInflater.inflate(R.layout.tablerow_layout, null, false);
TextView name = (TextView) newRow. findViewById(R.id.tablerow_name);
name.setText("THIS LINE");
tableLayout.addView(newRow);
Unfortunately my app crashes when I try to change the content of the TextView. I know that I could do this using a ListView, but I usually have a small number of rows and the overhead of creating another Adapter for the ListView is preatty big.
As @ρяσѕρєя K suggested I also tried newRow.findViewById(...) instead of findViewById(...) without any difference