javaandroidgetview

TextView is null


I'm having a problem with TextView. After pressing a button I want to append something to that TextView but apparently is null all the time.

fragment_one.xml

....
<TextView
    android:id="@+id/reply"
    android:layout_below="@+id/test"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/reply"/>
<Button android:text="@string/_0"
        android:id="@+id/_0"
        android:onClick="handleButtons"/>
....

ActivityTwo.java

....
public void handleButtons(View v){
    setContentView(R.layout.fragment_one);
    TextView tv = (TextView) v.findViewById(R.id.reply);
    if(v.getId() == R.id._0){
        tv.append("hi");
    }
....

I want to append some text to the reply TextView but apparently, it returns NullPointerException all the time. I am lost, I don't know what is failing.


Solution

  • Not use v.findViewById, but this.findViewById