简体   繁体   English

在按钮上单击它会更新第二个活动微调器和textviews

[英]on button click it updates the second activity spinner and textviews

I am creating an app which has 2 activities. 我正在创建一个有2个活动的应用程序。 Main activity has three buttons with different movie genre. 主要活动有三个具有不同电影类型的按钮。 On clicking any of the three buttons it should go to the second activity which consists of: 单击三个按钮中的任何一个后,应转到第二个活动,该活动包括:

2 spinners: to display movie name and 1 for movie time 2 textview to display movie rating and casts textview to open calendar 2个微调框:显示电影名称,1个显示电影时间2个textview显示电影等级,并强制textview打开日历

the spinners should be updated depending on the movie genre selected as well as the textviews for movie rating and cast 应根据选定的电影类型以及电影分级和演员表的文本视图来更新微调框

So far i have created the XML for main activity and class to make an arraylist to hold the movie details. 到目前为止,我已经为主要活动和类创建了XML,以创建一个数组列表来保存电影详细信息。 I also did intent to go to next page but i am confused on how to display movies in spinner only for selected genre. 我也确实打算转到下一页,但是我对如何仅在选定类型的转盘中显示电影感到困惑。

The simplest way would be to pass something to the next activity: 最简单的方法是将内容传递给下一个活动:

Intent i = new Intent(context,activity2.class);
i.putExtra("genre", mGenre);  
startActivity(i);  

Then in activity2 on load you can pull the genre: 然后在Activity2载入时,您可以拉流派:

String genre = getintent().getStringExtra("genre");  

Then you fill the lists based off the genre. 然后,您根据类型填充列表。 You could pass an int as well if you dont feel like dealing with strings. 如果您不想处理字符串,也可以传递一个int值。

You should make your movie class Serializable in order to pass it to next Activity. 您应该将影片类设置为Serializable ,以便将其传递给下一个Activity。 There are different ways to achieve that which I have mentioned two in below: 我可以在下面提到的两种方法来实现:

  1. http://www.parcelabler.com/ http://www.parcelabler.com/
  2. https://github.com/johncarl81/parceler https://github.com/johncarl81/parceler

Then you can pass your ArrayList to the second activity. 然后,您可以将ArrayList传递给第二个活动。

FirstActivity FirstActivity

ArrayList<Movie> myMovieList = new ArrayList<>();
...
Intent intent = new Intent(context, secondActivity.class);
i.putExtra("my_movie_list", myMovieList);  
startActivity(i); 

SecondActivity SecondActivity

ArrayList<Movie> myMovieList = getintent().getExtra("my_movie_list");  

Update (Extracting specific movies from movie list): 更新 (从电影列表中提取特定电影):

        List<Movie> selectedMovieList = new ArrayList<>();
        for(int i=0 ; i < movieList.size(); i++ ) {
            if(movieList.get(i).getGenre().equals("selected_genre_name")) {
                selectedMovieList.add(movieList.get(i));
            }
         }

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

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