Android 使文本切换器中的文本进入数组
我正试图从我的文本切换器中获取文本,并将其放入数组中。基本上,每当单击一个框时,我都希望将textswitcher中的文本添加到列表中。此外,我在listview中显示了此列表。我的代码如下所示:Android 使文本切换器中的文本进入数组,android,arrays,listview,settext,Android,Arrays,Listview,Settext,我正试图从我的文本切换器中获取文本,并将其放入数组中。基本上,每当单击一个框时,我都希望将textswitcher中的文本添加到列表中。此外,我在listview中显示了此列表。我的代码如下所示: protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final List<Strin
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final List<String> where = new ArrayList<String>();
mSwitcher = (TextSwitcher) findViewById(R.id.switcher);
mSwitcher.setFactory(this);
Animation in = AnimationUtils.loadAnimation(this, R.anim.alpha);
Animation out = AnimationUtils.loadAnimation(this, R.anim.beta);
mSwitcher.setInAnimation(in);
mSwitcher.setOutAnimation(out);
mSwitcher.setOnClickListener(this);
ImageView forward = (ImageView) findViewById(R.id.forward);
forward.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
setContentView(R.layout.listview);
setListAdapter(new ArrayAdapter<String>(Main.this,
android.R.layout.simple_list_item_1, where));
}
});
ImageView favorites = (ImageView) findViewById(R.id.favorite);
favorites.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
where.add((String) mSwitcher.getContentDescription());
}
});
}
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
最终列表,其中=new ArrayList();
mSwitcher=(TextSwitcher)findviewbyd(R.id.switcher);
mSwitcher.setFactory(本);
Animation in=AnimationUtils.loadAnimation(this,R.anim.alpha);
动画输出=AnimationUtils.loadAnimation(this,R.anim.beta);
mSwitcher.setInAnimation(in);
mSwitcher.setOutAnimation(输出);
mSwitcher.setOnClickListener(此);
ImageView forward=(ImageView)findViewById(R.id.forward);
forward.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图v){
setContentView(R.layout.listview);
setListAdapter(新阵列适配器)(Main.this,
android.R.layout.simple_list_item_1,其中);
}
});
ImageView收藏夹=(ImageView)findViewById(R.id.favorite);
收藏夹.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图v){
其中.add((字符串)mSwitcher.getContentDescription());
}
});
}
如果有人能解释如何做到这一点以及为什么上面的代码不起作用,那将不胜感激