android中怎么将字符数组依次在同一个textview中显示,例如首先展示str[0],然后点击一下展示str[1],。。
3个回答
展开全部
你要的是这样的效果吗:
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 ++;
}
}
};
}
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 ++;
}
}
};
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询