Example usage for android.widget ListView ListView

List of usage examples for android.widget ListView ListView

Introduction

In this page you can find the example usage for android.widget ListView ListView.

Prototype

public ListView(Context context) 

Source Link

Usage

From source file:com.wms.opensource.images3android.activity.ImageListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (layout != null) {
        ViewGroup parent = (ViewGroup) layout.getParent();
        parent.removeView(layout);/*from   ww  w  .  j a  v  a  2  s. c  o  m*/
        return layout;
    }

    if (listView == null) {
        layout = new RelativeLayout(getActivity());
        listView = new ListView(getActivity());
        layout.addView(listView);

        progressBar = new ProgressBar(getActivity(), null, android.R.attr.progressBarStyleLarge);

        // Center a view in relative layout
        RelativeLayout.LayoutParams progressBarParams = new RelativeLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        progressBarParams.addRule(RelativeLayout.CENTER_IN_PARENT);
        progressBar.setLayoutParams(progressBarParams);
        progressBar.setVisibility(View.INVISIBLE);
        layout.addView(progressBar);

        // Before reloading videos, display videos if they have been saved before
        String imagesFilePath = "";
        imagesFilePath = StorageUtil.getTempDirectory(this.getActivity()) + "/"
                + PersistFileNameUtil.getImagesPersistFileName(getString(R.string.imagePlantId), page);

        boolean imagesFileExists = FileUtil.fileExist(imagesFilePath);
        if (imagesFileExists) {
            loadCachedImagesTask = new LoadCachedImagesTask(getActivity(), loadImagesHandler, progressBar,
                    getActivity().getString(R.string.ImageS3ServiceURL),
                    getActivity().getString(R.string.imagePlantId), page);
            loadCachedImagesTask.execute();
        } else {
            NetworkStatus networkStatus = NetworkUtil.getNetworkStatus(getActivity());
            if (networkStatus.equals(NetworkStatus.WIFI_CONNECTED)
                    || networkStatus.equals(NetworkStatus.MOBILE_CONNECTED)) {
                String pageToken = page == 1 ? "" : ImageListFragmentActivity.pageTokens.get(page - 1);
                loadImagesTask = new LoadImagesTask(getActivity(), loadImagesHandler,
                        getActivity().getString(R.string.ImageS3ServiceURL),
                        getActivity().getString(R.string.imagePlantId), pageToken, page);
                loadImagesTask.execute();
            } else {
                Toast.makeText(getActivity(), getString(R.string.noNetworkAvailable), Toast.LENGTH_LONG).show();
            }
        }
    }
    return layout;
}

From source file:com.klinker.android.twitter.settings.SettingsActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        onBackPressed();//w  w w . j av a 2s  .c o  m
        return true;
    case R.id.menu_whats_new:
        final Context context = this;
        final ListView list = new ListView(this);
        list.setDividerHeight(0);

        new AsyncTask<Spanned[], Void, Spanned[]>() {
            @Override
            public Spanned[] doInBackground(Spanned[]... params) {
                return XmlChangelogUtils.parse(context);
            }

            @Override
            public void onPostExecute(Spanned[] result) {
                list.setAdapter(new ChangelogAdapter(context, result));
            }
        }.execute();

        new AlertDialog.Builder(this).setTitle(R.string.changelog).setView(list)
                .setPositiveButton(R.string.ok, null).show();
        return true;
    case R.id.menu_rate_it:
        Uri uri = Uri.parse("market://details?id=" + getPackageName());
        Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);

        try {
            startActivity(goToMarket);
        } catch (ActivityNotFoundException e) {
            Toast.makeText(this, "Couldn't launch the market", Toast.LENGTH_SHORT).show();
        }
        return true;
    case R.id.menu_get_help:
        showSettings(7, getString(R.string.get_help_settings));
        return true;
    case R.id.menu_other_apps:
        showSettings(8, getString(R.string.other_apps));
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.github.michalbednarski.intentslab.bindservice.SystemServicesDialog.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ListView listView = new ListView(getActivity());
    Utils.fixListViewInDialogBackground(listView);
    listView.setAdapter(//from   ww w  .j a v a2  s  . c o  m
            new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, mServices));
    listView.setOnItemClickListener(this);
    return listView;
}

From source file:net.gaast.giggity.ChooserActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //this.setTheme(android.R.style.Theme_Holo);

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    requestWindowFeature(Window.FEATURE_PROGRESS);

    /*//test stuff//from   w  ww . ja v  a 2 s .c  o  m
    Vibrator v = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
    long[] pattern = {  };
    v.vibrate(pattern, -1);
    */

    Giggity app = (Giggity) getApplication();
    db = app.getDb();
    pref = PreferenceManager.getDefaultSharedPreferences(app);

    refreshSeed(false);

    list = new ListView(this);
    list.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
            DbSchedule item = (DbSchedule) lista.getItem(position);
            if (item != null) {
                openSchedule(item, false);
            }
        }
    });
    list.setLongClickable(true);
    list.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
        @Override
        public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
            AdapterContextMenuInfo mi = (AdapterContextMenuInfo) menuInfo;
            DbSchedule sched = (DbSchedule) lista.getItem((int) mi.id);
            if (sched != null) {
                menu.setHeaderTitle(sched.getTitle());
                menu.add(ContextMenu.NONE, 0, 0, R.string.refresh);
                menu.add(ContextMenu.NONE, 3, 0, R.string.unhide);
                menu.add(ContextMenu.NONE, 1, 0, R.string.remove);
                menu.add(ContextMenu.NONE, 2, 0, R.string.show_url);
            }
        }
    });

    /* Filling in the list in onResume(). */
    refresher = new SwipeRefreshLayout(this);
    refresher.setOnRefreshListener(this);
    refresher.addView(list);

    LinearLayout cont = new LinearLayout(this);
    cont.setOrientation(LinearLayout.VERTICAL);
    cont.addView(refresher, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1));

    setContentView(cont);
}

From source file:org.solovyev.android.games.game2048.PreferenceListFragment.java

@Override
public final View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final LayoutInflater themeInflater;

    if (themeResId == NO_THEME) {
        themeContext = getActivity();/*  ww w  . ja  va  2  s .c om*/
        themeInflater = inflater;
    } else {
        themeContext = new ContextThemeWrapper(getActivity(), themeResId);
        themeInflater = LayoutInflater.from(themeContext);
    }

    if (layoutResId == NO_LAYOUT) {
        final FrameLayout frameLayout = new FrameLayout(themeContext);
        final ListView listView = new ListView(themeContext);
        listView.setId(android.R.id.list);
        frameLayout.addView(listView, new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
        root = frameLayout;
    } else {
        root = themeInflater.inflate(layoutResId, null);
    }

    final ListView lv = (ListView) root.findViewById(android.R.id.list);
    prepareListView(lv);

    onCreateView(themeContext, themeInflater, root, container, savedInstanceState);

    return root;
}

From source file:com.github.jvanhie.discogsscrobbler.RecentlyPlayedFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    //setup list view
    mList = new ListView(getActivity());
    mList.setId(android.R.id.list);//  w  w w  .  ja v a  2s  .c  om

    mList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            onListItemClick(view, i, l);
        }
    });

    //create superframe for adding list and empty view
    FrameLayout superFrame = new FrameLayout(getActivity());
    FrameLayout.LayoutParams layoutparams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    superFrame.setLayoutParams(layoutparams);
    View emptyView = inflater.inflate(R.layout.fragment_empty, container, false);
    ((TextView) emptyView.findViewById(R.id.empty_heading)).setText("No recently played albums");
    ((TextView) emptyView.findViewById(R.id.empty_text)).setText(
            "Your recently played list is empty. Once you start registering your played records they'll end up here");

    /*initialize list with local discogs collection*/
    if (mDiscogs == null)
        mDiscogs = Discogs.getInstance(getActivity());
    loadList();

    superFrame.addView(emptyView);
    mList.setEmptyView(emptyView);
    superFrame.addView(mList);

    return superFrame;
}

From source file:net.yama.android.views.contentfactory.EventInfoContentFactory.java

private View getWhosComingView()
        throws ApplicationException, JSONException, IllegalAccessException, InstantiationException {

    LoadingView view = new LoadingView(context) {

        @SuppressWarnings("unchecked")
        @Override//from ww w  .  ja  v a2 s .c om
        public View getResultsView() throws ApplicationException {
            ListView rsvpList = null;
            List<Rsvp> allRsvps = DataManager.getAllRsvps(eventId);
            rsvpList = new ListView(context);
            Map<RsvpResponse, List<Rsvp>> splitRsvpMap = Helper.splitRsvps(allRsvps);
            rsvpList.setAdapter(new RsvpListAdapter(splitRsvpMap, context));
            return rsvpList;
        }
    };

    return view;
}

From source file:org.dpadgett.timer.WorldClockFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    uiHandler = new Handler();
    final View rootView = inflater.inflate(R.layout.world_clock, container, false);
    finder = ResourceFinders.from(rootView);
    context = rootView.getContext();//from   w  w  w  .  ja  va2  s .  co m
    final Button addClockButton = (Button) finder.findViewById(R.id.addClockButton);
    addClockButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View view) {
            uiHandler.post(new Runnable() {
                @Override
                public void run() {
                    newClockDialog(-1);
                }
            });
        }
    });

    clockList.clear();
    final SharedPreferences prefs = context.getSharedPreferences("WorldClocks", Context.MODE_PRIVATE);
    final int numClocks = prefs.getInt("numClocks", -1);
    if (numClocks >= 0) {
        for (int idx = 0; idx < numClocks; idx++) {
            final String clock = prefs.getString("clock" + idx, null);
            if (clock != null) {
                clockList.add(clock);
            }
        }
    } else {
        addNewClock(TimeZone.getDefault().getID(), -1);
    }

    final ListView clocksList = (ListView) finder.findViewById(R.id.clocksList);
    clocksList.setAdapter(clocksListAdapter);
    clocksList.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(final AdapterView<?> parent, final View view, final int position,
                final long id) {
            newClockDialog(position);
        }
    });

    // hack to get the bottom divider to be the same as the listview dividers
    final Drawable divider = new ListView(context).getDivider();
    ((org.dpadgett.compat.LinearLayout) rootView).setDividerDrawable(divider);

    // forcefully pre-render content so it is cached
    rootView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
            MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            rootView.layout(0, 0, rootView.getMeasuredWidth(), rootView.getMeasuredHeight());
            rootView.draw(new Canvas(Bitmap.createBitmap(rootView.getMeasuredWidth(),
                    rootView.getMeasuredHeight(), Bitmap.Config.ARGB_8888)));
        }
    }, 1000);

    return rootView;
}

From source file:com.github.jvanhie.discogsscrobbler.ReleaseVersionsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    //setup list view
    mList = new ListView(getActivity());
    mList.setId(android.R.id.list);//from   w ww  . j av  a2s  . c  o m

    mList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            onListItemClick(view, i, l);
        }
    });

    //create superframe for adding list and empty view
    FrameLayout superFrame = new FrameLayout(getActivity());
    FrameLayout.LayoutParams layoutparams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    superFrame.setLayoutParams(layoutparams);
    View emptyView = inflater.inflate(R.layout.fragment_empty, container, false);
    ((TextView) emptyView.findViewById(R.id.empty_heading)).setText("No versions found");
    ((TextView) emptyView.findViewById(R.id.empty_text)).setText(
            "No alternative versions of this release were found, this could also mean Discogs did not add a master id to this release");

    /*initialize list with local discogs collection*/
    if (mDiscogs == null)
        mDiscogs = Discogs.getInstance(getActivity());
    if (mRelease == null) {
        mDiscogs.getRelease(getArguments().getLong(ARG_ITEM_ID, 0), new Discogs.DiscogsDataWaiter<Release>() {
            @Override
            public void onResult(boolean success, Release data) {
                if (success) {
                    mRelease = data;
                    loadList();
                }
            }
        });
    } else {
        loadList();
    }

    superFrame.addView(emptyView);
    mList.setEmptyView(emptyView);
    superFrame.addView(mList);

    return superFrame;
}

From source file:com.wms.opensource.ezchannel.activity.VideoListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (layout != null) {
        // We need to remove layout from its parent first. Otherwise, adding layout to different viewgroup will result in error 
        ViewGroup parent = (ViewGroup) layout.getParent();
        parent.removeView(layout);//from www  .  ja va2s.  c  om
        return layout;
    }

    if (listView == null) {
        layout = new RelativeLayout(getActivity());
        listView = new ListView(getActivity());
        layout.addView(listView);

        imageViewStandardThumbnail = new ImageView(getActivity());
        RelativeLayout.LayoutParams imageViewParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        imageViewParams.addRule(RelativeLayout.CENTER_IN_PARENT);
        imageViewStandardThumbnail.setLayoutParams(imageViewParams);
        imageViewStandardThumbnail.setVisibility(View.INVISIBLE);
        imageViewStandardThumbnail.setBackgroundResource(R.drawable.border);
        imageViewStandardThumbnail.setOnClickListener(new ImageView.OnClickListener() {

            @Override
            public void onClick(View v) {
                // Dismiss the image view
                v.setVisibility(View.INVISIBLE);
                Animation myAnim = AnimationUtils.loadAnimation(VideoListFragment.this.getActivity(),
                        R.anim.fadeout);
                v.startAnimation(myAnim);
            }

        });
        layout.addView(imageViewStandardThumbnail);

        progressBar = new ProgressBar(getActivity(), null, android.R.attr.progressBarStyleLarge);

        // Center a view in relative layout
        RelativeLayout.LayoutParams progressBarBarams = new RelativeLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        progressBarBarams.addRule(RelativeLayout.CENTER_IN_PARENT);
        progressBar.setLayoutParams(progressBarBarams);
        progressBar.setVisibility(View.INVISIBLE);
        layout.addView(progressBar);

        // Before reloading videos, display videos if they have been saved before.            
        String videosFilePath = "";
        if (VideoListFragmentActivity.videoSource == YouTubeVideoSource.Playlist) {
            videosFilePath = StorageUtil.getTempDirectory(this.getActivity()) + "/"
                    + PersistFileNameProvider.getYouTubePlaylistPersistFileName(playlistID, page);
        } else {
            videosFilePath = StorageUtil.getTempDirectory(this.getActivity()) + "/" + PersistFileNameProvider
                    .getYouTubeSearchListPersistFileName(getActivity().getString(R.string.appID), page);
        }

        boolean videosFileExists = FileUtil.fileExist(videosFilePath);
        if (videosFileExists) {
            loadPlaylistVideosFromLocalTask = new LoadCachedVideosTask(getActivity(), loadVideosHandler,
                    VideoListFragmentActivity.videoSource, progressBar, playlistID, page);
            loadPlaylistVideosFromLocalTask.execute();
        } else {
            NetworkStatus networkStatus = NetworkUtil.getNetworkStatus(getActivity());
            if (networkStatus.equals(NetworkStatus.WIFI_CONNECTED)
                    || networkStatus.equals(NetworkStatus.MOBILE_CONNECTED)) {
                String pageToken = page == 1 ? null : VideoListFragmentActivity.pageTokens.get(page - 1); // page start from 1
                if (VideoListFragmentActivity.videoSource == YouTubeVideoSource.Playlist) {
                    loadVideosTask = new LoadVideosTask(getActivity(), loadVideosHandler,
                            YouTubeVideoSource.Playlist, playlistID, pageToken, page);
                } else {
                    loadVideosTask = new LoadVideosTask(getActivity(), loadVideosHandler,
                            YouTubeVideoSource.Search, queryTerm, pageToken, page);
                }
                loadVideosTask.execute();
            } else {
                Toast.makeText(getActivity(), getString(R.string.noNetworkAvailable), Toast.LENGTH_LONG).show();
            }
        }
    }
    return layout;
}