android中怎么将字符数组依次在同一个textview中显示,例如首先展示str[0],然后点击一下展示str[1],。。

2024-11-29 04:38:31
推荐回答(1个)
回答1:

你要的是这样的效果吗: public class TestActivity extends Activity { private TextView mTestText = null; private String[] mTestString = null; private int mclick = 1; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mTestText = (TextView)findViewById(R.id.testText); mTestText.setOnClickListener(mOnClick); mTestString = new String[]{"text1" , "text2" , "text3" , "text4" , "text5"}; mTestText.setText(mTestString[0]); } OnClickListener mOnClick = new OnClickListener() { @Override public void onClick(View arg0) { if(mclick < 5){ mTestText.setText(mTestString[mclick]); mclick ++; }else{ mclick = 0; mTestText.setText(mTestString[mclick]); mclick ++; } } }; }