简体   繁体   English

如何在ViewFlipper中为每个视图分配单独的类?

[英]How can I assign a separate class for each view in a ViewFlipper?

I have a ViewFlipper that presents 3 different views. 我有一个ViewFlipper,可以呈现3种不同的视图。

Is it possible to have 3 classes manage* the 3 different views? 是否可以让3个类管理3个不同的视图? If so, how do I go about doing this? 如果是这样,我该怎么做?

  • For example, if View 1 shows a List of News and View 2 Shows a List of Prices, I want to have a News class that handles the interaction of the listview in News, and a Prices class that handles the interaction of the listview in Prices 例如,如果“视图1”显示“新闻列表”,而“视图2”显示“价格列表”,则我想有一个“新闻”类来处理“新闻”中的列表视图的交互,以及一个“价格”类来处理“价格”中的列表视图的交互。

Why don't you make your News and Prices class contain all of your application logic as you said. 您为什么不让News and Prices类包含您所说的所有应用程序逻辑。 If you make them extend ListView you can then add them to your ViewFlipper and treat them in the same way, but they will have the specific behaviour as dictated by whatever you put in the News and Prices classes. 如果使它们扩展ListView ,则可以将它们添加到ViewFlipper并以相同的方式处理它们,但是它们将具有特定的行为,具体取决于您在NewsPrices类中放置的内容。

Alternatively, just set a different listView.setAdapter() [to populate], and listView.setOnItemSelectedListener() [to alter behaviour] for each ListView you have in your ViewFlipper. 另外,只需为ViewFlipper中的每个ListView设置一个不同的listView.setAdapter()来填充,并设置listView.setOnItemSelectedListener()来改变行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM