Android将ArrayList放入几个TextView中

时间:2013-08-27 04:09:02

标签: android arraylist layout-inflater

在发表任何评论之前,我已经阅读了几个有关此问题的问题:

问题是我目前的活动是扩展YoutubeActivity。到目前为止,这是当前活动的样子:

public class MovieDetailsActivity extends YouTubeBaseActivity  
implements YouTubePlayer.OnInitializedListener, OnEditorActionListener
{
*** SOME INITIALIZATION GOES HERE ***
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.movie_details);

    movieDetails = (Movie) getIntent().getSerializableExtra("details");
    youtubeVideo = movieDetails.trailer;
    castList = movieDetails.castList;

    findAllViewsById();

    detailsTitleMovie.setText(movieDetails.originalName);
    detailsRatingMovie.setText(movieDetails.rating);
    detailsReleaseMovie.setText(movieDetails.released);
    detailsRuntimeMovie.setText(movieDetails.runtime);
    detailsSynopsisMovie.setText(movieDetails.overview);

            *** OBVIOUSLY I NEED TO USE SOME SORT OF ITERATOR HERE ***
            *** CASTLIST IS AN ARRAYLIST OF AN OBJECT ***

    person = castList.get(0);
    detailsFullnameCast.setText(person.castFullName);

            *** END OF PROBLEM ***

    String posterUrl = movieDetails.retrieveThumbnail();
    if(posterUrl != null)
    {
        Bitmap bitmap = fetchBitmapFromCache(posterUrl);
        if(bitmap == null)
        {
            new BitmapDownloaderTask(moviePoster).execute(posterUrl);
        }else{
            moviePoster.setImageBitmap(bitmap);
        }
    }else{
        moviePoster.setImageBitmap(null);
    }

    if(youtubeVideo != null)
    {
        youtubePlayerView.initialize(YOUTUBE_API_KEY, this);
    }else{
        longToast("Aw... snapp....!");
    }

    /* BUTTON LISTENER */
    cineplexButton.setOnClickListener(new OnClickListener(){
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            visitCinemaPage(CINEMA_TYPE_CINE);
        }
    });

    blitzButton.setOnClickListener(new OnClickListener(){
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            visitCinemaPage(CINEMA_TYPE_BLI);
        }
    });

    imdbButton.setOnClickListener(new OnClickListener(){
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            visitImdbMoviePage(movieDetails.imdbId);
        }
    });

    //et = (EditText) findViewById(R.id.eturl);
    //et.setOnEditorActionListener(this);
}
*** REST OF THE CODE OMITTED ***

但我想这样做:

public class MovieDetailsAdapter extends ArrayAdapter<Movie>{

    private ArrayList<Movie> movieDataItems;
    private Activity context;

    public MovieDetailsAdapter(Activity context, int textViewResourceId, ArrayList<Movie> movieDataItems) {
        super(context, textViewResourceId, movieDataItems);
        // TODO Auto-generated constructor stub

        this.context = context;
        this.movieDataItems = movieDataItems;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        View view = convertView;

        if(view == null)
        {
            LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = vi.inflate(layout.movie_details, null);
        }

        Movie movie = movieDataItems.get(position);
        if(movie != null)
        {
            TextView titleTextView = (TextView) view.findViewById(R.id.detail_title_text_view);
            titleTextView.setText(movie.originalName);

            *** AND SO ON ***
        }
        return view;
    }
}

以后上课将在我的活动课程中调用。

这是我的活动布局:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:isScrollContainer="true" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"

        android:gravity="fill_horizontal"
        android:orientation="vertical" >

        <com.google.android.youtube.player.YouTubePlayerView
            android:id="@+id/youtubeplayer"
            android:layout_width="fill_parent"
            android:layout_height="210dp" >
        </com.google.android.youtube.player.YouTubePlayerView>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="top|bottom" >

            <ImageView
                android:id="@+id/detail_thumb_icon"
                android:layout_width="80dip"
                android:layout_height="80dip"
                android:layout_marginRight="5dip"
                android:layout_marginTop="5dip"
                android:src="@drawable/ic_launcher" />

            *** SOME TEXT VIEWS ***
        </RelativeLayout>

        *** MORE TEXT VIEWS ***

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="?android:attr/listPreferredItemHeight"
            android:padding="6dip">

            <ImageView
                android:id="@+id/detail_person_thumb_icon"
                android:layout_width="80dip"
                android:layout_height="fill_parent"
                android:layout_marginRight="6dip"/>

            <LinearLayout
                android:orientation="vertical"
                android:layout_width="0dip"
                android:layout_weight="1"
                android:layout_height="fill_parent">

*** THIS IS WHERE I WANT THE CONTENT FROM ARRAYLIST TO BE POPULATED INTO TEXT VIEW ***

            </LinearLayout>
        </LinearLayout>

        <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:gravity="top|bottom" >

            <TextView
            android:id="@+id/text_check_cinema"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_marginRight="14dp"
            android:layout_marginLeft="5dp"
            android:textSize="20sp"
            android:textStyle="bold"
            android:text="Check on Cinema" />

            <View
                android:id="@+id/view_horizontal_line"
                android:layout_width="fill_parent"
                android:layout_height="2dip"
                android:layout_below="@+id/text_check_cinema"
                android:layout_alignParentRight="true"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="5dp"
                android:background="#000000" />

            <Button
                android:id="@+id/button_cineplex"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="5dp"
                android:layout_alignParentLeft="true"
                android:layout_below="@+id/view_horizontal_line"
                android:text="@string/button_visit_cineplex" />
            <Button
                android:id="@+id/button_imdb"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="5dp"
                android:layout_below="@+id/view_horizontal_line"
                android:layout_toRightOf="@+id/button_blitz"
                android:text="@string/button_visit_imdb" />
            <Button
                android:id="@+id/button_blitz"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="5dp"
                android:layout_below="@+id/view_horizontal_line"
                android:layout_toRightOf="@+id/button_cineplex"
                android:text="@string/button_visit_blitz" />
        </RelativeLayout>
    </LinearLayout>
</ScrollView>

所以基本上,我要问的是如何在同时扩展YoutubeActivity的同时将包含对象列表的数组列表填充到活动中。

感谢您的帮助......

0 个答案:

没有答案