Note: this shouldn't have anything to do with libraries, I just include them for details
Problem: There is a layout called FlingContainer from this library https://github.com/Diolor/Swipecards. It takes another layout as a parameter(the card to be flinged), Inside the card I have a button to add tags to the card. In the CustomAdapter used for the Fling Container I have this code in the GetView method. I know it works because I can see the TVs getting added in debug mode, they just arent showing up.
What I've tried: I tried doing this in just an activity with no flingContainer and the views are added instantly with no problems. I tried searching for R.id.addTag from the mainActivity however I get a nullPointer exception, I think this is because addTag is embedded in another layout
Conclusion: Any idea what is going wrong here? how can I get get addView to work in the card?
Thanks
EDIT: here is entire getView
public View getView(int position, View convertView, final ViewGroup parent) {
final View vi = inflater.inflate(layoutResource, parent, false);
TextView tv = (TextView) vi.findViewById(R.id.card_one_line);
flowLayout = (FlowLayout) vi.findViewById(R.id.flow_container);
final TextView typeTag = new TextView(getContext());
final TextView typeTag2 = new TextView(getContext());
TextView addTag = (TextView) vi.findViewById(R.id.addTag);
typeTag.setText(lines.get(position).getType());
typeTag.setBackgroundColor(getContext().getResources().getColor(R.color.nice_blue));
typeTag.setTextColor(getContext().getResources().getColor(R.color.lightening_yellow));
typeTag.setTextSize(25);
typeTag.setPadding(5, 5, 5, 5);
flowLayout.addView(typeTag);
addTag.setOnClickListener(new View.OnClickListener() {
int i = 0;
@Override
public void onClick(View v) {
TextView tv = new TextView(getContext());
tv.setBackgroundColor(getContext().getResources().getColor(R.color.nice_blue));
tv.setTextColor(getContext().getResources().getColor(R.color.lightening_yellow));
String text = "Goofy"+i++;
tv.setText(text);
tv.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
flowLayout.addView(tv);
parent.invalidate();
parent.requestLayout();
Toast.makeText(getContext(), "heyheyhey", Toast.LENGTH_SHORT).show();
}
});
tv.setText((lines.get(position).getLine()));
return vi;
}
In this pic i am hitting the + button inside the flingcontainer, the g is the default type added outside of the onClick, trying to get onclick to work here