TextSwitcherActivity,无法解析符号

TextSwitcherActivity, cannot resolve symbol

谢谢。 我想将一个简单的 TextSwitcher 添加到片段中,这一切都很好(我认为)直到这一行:

TextView t = new TextView (TextSwitcherActivity.this);

我不知道为什么它无法解析符号:TextSwitcherActivity。 如果您有任何建议,我将不胜感激。

这是完整的Java代码,我相信是书上的,没什么新的。

public class viewOne extends AppCompatActivity {
    TextSwitcher switching;
    Button pre_button, next_button;
    String strTextSwitcher[] = {"Text 1", "Text 2", "Text 3, Text 4", "Text demo 5"};
    int currentIndex = -1;
    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_view_one);
        next_button=(Button)findViewById(R.id.next_button);
        pre_button=(Button)findViewById(R.id.pre_button);
        switching=(TextSwitcher)findViewById(R.id.switching);
        switching.setFactory(new ViewSwitcher.ViewFactory() {

            public View makeView() {

                TextView t = new TextView (TextSwitcherActivity.this);
                t.setGravity(Gravity.TOP|Gravity.CENTER);
                t.setTextSize(36);
                return t;
            }
        });
        switching.setCurrentText("click on the next button to switch text");
        pre_button.setOnClickListener(new View.OnClickListener(){
            @Override
                    public void onClick(View view){
                if (currentIndex>0)
                    switching.setText(strTextSwitcher[currentIndex]);
            }
        });
        next_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (currentIndex<strTextSwitcher.length-1)
                    currentIndex = currentIndex+1;
                switching.setText(strTextSwitcher[currentIndex]);
            }
        });
    }
}

尝试

TextView t = new TextView (this);
//or
TextView t = new TextView (viewOne.this);