I am trying to load some buttons into a table layout inside a fragment. Why would this not show up. I see that changing the background works (changed from grey to red in onCreateView(......)) but when i call loadAllButtons they do not show up.
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
if(container == null)
return null;
basedView = (TableLayout) inflater.inflate(R.layout.fragment_difficult_sound_syllable, container, false);
currentSyllable = getArguments().getString(StaticValues.DIFFICULT_SOUND_SELECTOR);
basedView.setBackgroundColor(Color.RED);
return basedView;
}
Below is my loadAllButtons, and before anyone asks yes it says that everything is loaded (e.g. buttons and rows added, checked via logcat after row.add() and basedView.add())
private void loadAllButtons()
{
DataBaseHelper tmpHelper = new DataBaseHelper(getActivity().getApplicationContext());
ArrayList<ButtonInfoContainer> tmpArray = null;
if(currentSyllable.contentEquals(StaticValues.CONSONANT))
{
tmpArray = tmpHelper.returnAllConsonants();
Log.i(StaticValues.TAG, "returned all consonants");
}
else
{
tmpArray = tmpHelper.returnAllVowels();
Log.i(StaticValues.TAG, "returned all vowels");
}
if(tmpArray != null)
{
TableRow row = null;
InfoButton tmpButton = null;
//LayoutParams rowParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
//TableRow.LayoutParams equalParams = new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0);
LinearLayout.LayoutParams buttonLayout = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
if(basedView != null)
{
for(int i = 0; i < tmpArray.size(); i++)
{
//adds new row to table if modulus is 0
if(( i % 2 ) == 0)
{
row = (TableRow) getLayoutInflater(getArguments()).inflate(R.layout.table_row, null);
//row.setLayoutParams(rowParams);
basedView.addView(row);
}
tmpButton = (InfoButton) getLayoutInflater(getArguments()).inflate(R.layout.info_button, null);
tmpButton.setBackgroundResource(R.drawable.button_bg);
tmpButton.setLayoutParams(buttonLayout);
//set button Text
tmpButton.setText(tmpArray.get(i).buttonText);
//Obtain extra held info
tmpButton.setExtraInfo(tmpArray.get(i).infoHeld);
//tmpButton.setWidth(buttonWidth);
//tmpButton.setHeight(buttonHeight);
//tmpButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, textSize);
tmpButton.setTextColor(getResources().getColor(R.color.button_text_color));
tmpButton.setTypeface(Typeface.DEFAULT_BOLD);
row.addView(tmpButton);
tmpButton.setOnClickListener(listenerDynamicButton);
}
}
}
}
For some reason even though my logcat outputs show that everything is all good (buttons showing proper names right amount of buttons) they table layout does not get populated.
Figured out the answer in regards to my own problem. everything after
tmpButton = (InfoButton) getLayoutInflter()...
to
row.addView(tmpButton);
had to be deleted except
tmpButton.setText();
and
tmpButton.setExtraInfo(..);
Although I do not know why those killed my layout. So if anyone figures that part out I will gladly accept that answer.