I'm trying to dynamically add and remove TextView for an android app I'm making but I'm running into difficulty setting and getting the TextView's id. I seem to be getting null pointer exception's for the last two lines of code (et.setText and ll.removeView). Does anyone have any suggestions on how I can dynamically set and get the id of a textview? Apparently .setId doesn't seem to work, or more likely, I'm doing it wrong.
//surrounding non-relevant code removed
EditText et = (EditText) view.findViewById(R.id.edittext_tags);
et.setText("");
TextView nTv = new TextView(view.getContext());
LayoutParams lparams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lparams.setMargins(10, 0, 0, 0);
nTv.setLayoutParams(lparams);
nTv.setId(tag_id);
nTv.setText(str.substring(0, str.length()-1));
nTv.setTextColor(Color.BLUE);
nTv.setTextSize(20);
final LinearLayout linl = (LinearLayout) view.findViewById(R.id.linear_layout_tags);
linl.addView(nTv);
nTv.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
EditText et = (EditText) view.findViewById(R.id.edittext_tags);
TextView t = ((TextView)v);
et.setText(t.getText().toString());
linl.removeView(v);
}
});