Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.database.Cursor;

import java.util.ArrayList;
import java.util.List;

public class Main {
    private static final int COL_TRAILER_KEY = 6;

    public static String[] getTrailers(Cursor data) {
        List<String> lista = new ArrayList<String>();
        lista.add("Select Trailer");

        data.moveToFirst();
        if (!data.getString(COL_TRAILER_KEY).equalsIgnoreCase("No Trailer Available")) {
            //loop through cursor to get all trailers
            for (int i = 1; i < data.getCount() + 1; i++) {
                if (!lista.contains(data.getString(COL_TRAILER_KEY))) {
                    lista.add(data.getString(COL_TRAILER_KEY));
                    data.moveToNext();
                } else {
                    data.moveToNext();
                }
            }
        }

        String[] ltrailer;
        if (lista.size() < 1) {
            ltrailer = new String[1];
            ltrailer[0] = "No Trailer Available";
        } else {
            ltrailer = lista.toArray(new String[lista.size()]);
        }

        return ltrailer;
    }
}