我想向片段添加一個(gè)簡(jiǎn)單的 TextSwitcher,這一切都很好(我認(rèn)為)直到這一行:TextView t = new TextView (TextSwitcherActivity.this);我錯(cuò)過(guò)了為什么它無(wú)法解析符號(hào):TextSwitcherActivity。請(qǐng),如果您有任何建議,我將不勝感激。這是整個(gè) Java 代碼,我相信是書(shū)上的,沒(méi)什么新鮮的。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]); } }); }}
TextSwitcherActivity,無(wú)法解析符號(hào)
翻翻過(guò)去那場(chǎng)雪
2021-12-01 19:41:57