Example usage for android.widget ListView getAdapter

List of usage examples for android.widget ListView getAdapter

Introduction

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

Prototype

@Override
public ListAdapter getAdapter() 

Source Link

Document

Returns the adapter currently in use in this ListView.

Usage

From source file:com.sftoolworks.nfcoptions.SelectActivity.java

@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {

    super.onRestoreInstanceState(savedInstanceState);
    ListView list = (ListView) findViewById(R.id.listView1);
    if (list.getCount() == 0)
        return;/*from   w  ww  .j a va  2s. c o  m*/

    if (savedInstanceState.containsKey(CHECKBOX_STATE)) {
        boolean[] checkboxes = savedInstanceState.getBooleanArray(CHECKBOX_STATE);
        ((OptionListAdapter) (list.getAdapter())).restoreCheckState(checkboxes);
    }
    if (savedInstanceState.containsKey(KEY_STATE)) {
        selectKey = savedInstanceState.getString(KEY_STATE);
    }

}

From source file:uk.ac.horizon.artcodes.activity.NavigationActivity.java

private void updateAccounts() {
    final Menu menu = binding.navigation.getMenu();
    final MenuItem libraries = menu.findItem(R.id.nav_libraries);
    final SubMenu subMenu = libraries.getSubMenu();

    while (subMenu.size() > 0) {
        subMenu.removeItem(subMenu.getItem(0).getItemId());
    }//  ww  w  .j  ava 2 s  .co  m

    final List<Account> accounts = getServer().getAccounts();
    for (int index = 0; index < accounts.size(); index++) {
        final Account account = accounts.get(index);
        final MenuItem menuItem = subMenu.add(R.id.navigation, index, Menu.NONE, account.getDisplayName());
        if (account.getId().equals("local")) {
            menuItem.setIcon(R.drawable.ic_folder_24dp);
        } else {
            menuItem.setIcon(R.drawable.ic_cloud_24dp);
        }
        menuItem.setCheckable(true);
    }

    final MenuItem menuItem = subMenu.add(R.id.navigation, R.id.nav_addaccount, Menu.NONE,
            R.string.nav_addaccount);
    menuItem.setIcon(R.drawable.ic_add_24dp);

    for (int i = 0, count = binding.navigation.getChildCount(); i < count; i++) {
        final View child = binding.navigation.getChildAt(i);
        if (child != null && child instanceof ListView) {
            final ListView menuView = (ListView) child;
            final HeaderViewListAdapter adapter = (HeaderViewListAdapter) menuView.getAdapter();
            final BaseAdapter wrapped = (BaseAdapter) adapter.getWrappedAdapter();
            wrapped.notifyDataSetChanged();
        }
    }

    getServer().loadRecent(new LoadCallback<List<String>>() {
        @Override
        public void loaded(List<String> item) {
            final MenuItem recent = menu.findItem(R.id.nav_recent);
            if (recent != null) {
                recent.setVisible(!item.isEmpty());
            }
        }

        @Override
        public void error(Throwable e) {
            GoogleAnalytics.trackException(e);
        }
    });
    getServer().loadStarred(new LoadCallback<List<String>>() {
        @Override
        public void loaded(List<String> item) {
            final MenuItem starred = menu.findItem(R.id.nav_starred);
            if (starred != null) {
                starred.setVisible(!item.isEmpty());
            }
        }

        @Override
        public void error(Throwable e) {
            GoogleAnalytics.trackException(e);
        }
    });
}

From source file:net.named_data.nfd.FaceListFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    if (m_callbacks != null) {
        FaceStatus faceStatus = (FaceStatus) l.getAdapter().getItem(position);
        m_callbacks.onFaceItemSelected(faceStatus);
    }//from w  w  w. j a v a2  s  . c  o m
}

From source file:com.hemou.android.ui.base._ItemListFragment.java

/**
 * Configure list after view has been created
 * //from w  ww.  j  av a  2 s.  c  o  m
 * @param activity
 * @param listView
 */
protected void configureList(Activity activity, ListView listView) {
    Log.d(TAG, "configureList() got called to set adapter to _HeaderFooterListAdapter...");
    listView.setAdapter(createAdapter());
    Adapter adapter = listView.getAdapter();
    Log.d(TAG, "The adapter become " + adapter.getClass().getSimpleName() + " afater configureList");
    if (adapter instanceof HeaderViewListAdapter) {
        Log.d(TAG, "The wrapped adapter is "
                + ((HeaderViewListAdapter) adapter).getWrappedAdapter().getClass().getSimpleName());
    }
}

From source file:com.hemou.android.ui.base.ItemListFragment.java

/**
 * Configure list after view has been created
 * /*from   w w w  . j  a v a 2s.  com*/
 * @param activity
 * @param listView
 */
protected void configureList(Activity activity, ListView listView) {
    Log.d(TAG, "configureList() got called to set adapter to HeaderFooterListAdapter...");
    listView.setAdapter(createAdapter());
    Adapter adapter = listView.getAdapter();
    Log.d(TAG, "The adapter become " + adapter.getClass().getSimpleName() + " afater configureList");
    if (adapter instanceof HeaderViewListAdapter) {
        Log.d(TAG, "The wrapped adapter is "
                + ((HeaderViewListAdapter) adapter).getWrappedAdapter().getClass().getSimpleName());
    }
}

From source file:de.damdi.fitness.activity.create_workout.ExerciseTypeListFragment.java

@Override
public void onListItemClick(ListView listView, View view, int position, long id) {
    super.onListItemClick(listView, view, position, id);

    // Notify the active callbacks interface (the activity, if the
    // fragment is attached to one) that an item has been selected.
    ExerciseType exercise = (ExerciseType) listView.getAdapter().getItem(position);
    mCallbacks.onItemSelected(exercise);
}

From source file:com.fabernovel.alertevoirie.NewsActivity.java

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // Log.d(Constants.PROJECT_TAG, "onListItemClick : "+l.getAdapter().getItem(position));
    Intent i = new Intent(this, ReportDetailsActivity.class);
    i.putExtra("existing", true);

    JSONObject item = (JSONObject) l.getAdapter().getItem(position);
    i.putExtra("event", item.toString());

    try {/* ww  w .  j a v  a  2 s  . c om*/
        Incident incident = Incident.fromJSONObject(this,
                new JSONObject(((MagicAdapter) getListAdapter()).getItem(position).toString()));

        if (lock.contains(incident.id))
            return;
        /*
         * JSONObject job = (JSONObject) logList.values().toArray()[((MagicAdapter) getListAdapter()).getRealPositionOfItem(position)];
         * if (job != null) {
         * if (JsonData.PARAM_UPDATE_INCIDENT_INVALID.equals(job.getString(JsonData.PARAM_STATUS))
         * || JsonData.PARAM_UPDATE_INCIDENT_RESOLVED.equals(job.getString(JsonData.PARAM_STATUS))) return;
         * } else if (incident.state == 'R') return;
         */

    } catch (JSONException e) {
        Log.e(Constants.PROJECT_TAG, "JSONException in onListItemClick", e);
    }
    startActivityForResult(i, 1);
    // startActivity(i);
    // super.onListItemClick(l, v, position, id);
}

From source file:com.shafiq.mytwittle.view.DirectMessageFeedFragment.java

@Override
public void onJumpToTop() {
    if (mConversationListView != null) {
        ListView listView = mConversationListView.getRefreshableView();
        if (listView != null && listView.getAdapter() != null && listView.getAdapter().isEmpty() == false) {
            listView.setSelection(0);//from w ww. j ava2  s.c  o m
        }
    }
}

From source file:com.probam.updater.activity.GooActivity.java

@SuppressWarnings("deprecation")
@Override//from  ww  w  . j  a  v a  2  s .c om
protected void onCreate(Bundle savedInstanceState) {

    boolean useDarkTheme = ManagerFactory.getPreferencesManager(this).isDarkTheme();
    setTheme(useDarkTheme ? R.style.DarkTheme : R.style.AppTheme);

    super.onCreate(savedInstanceState);

    addPreferencesFromResource(R.layout.empty_pref_screen);

    PreferenceScreen pScreen = getPreferenceScreen();
    mInfos = new HashMap<String, PackageInfo>();

    if (CURRENT_NAVIGATION == null) {

        Preference preference = null;

        preference = new Preference(this);
        preference.getExtras().putBoolean("BROWSING_ALL", false);
        preference.getExtras().putBoolean("FOLDER", true);
        preference.getExtras().putString("PATH", "/devs");
        preference.setKey(Constants.GOO_SEARCH_URL + "/devs&ro_board=" + mDevice);
        preference.setTitle(R.string.goo_browse_all_compatible);
        pScreen.addPreference(preference);

        preference = new Preference(this);
        preference.getExtras().putBoolean("BROWSING_ALL", true);
        preference.getExtras().putBoolean("FOLDER", true);
        preference.getExtras().putString("PATH", "/devs");
        preference.setKey(Constants.GOO_SEARCH_URL + "/devs");
        preference.setTitle(R.string.goo_browse_all);
        pScreen.addPreference(preference);

        preference = new Preference(this);
        preference.getExtras().putBoolean("BROWSING_ALL", false);
        preference.getExtras().putBoolean("FOLDER", false);
        preference.getExtras().putString("PATH", "");
        preference.setKey("watchlist");
        preference.setTitle(R.string.goo_browse_watchlist);
        pScreen.addPreference(preference);

    } else {

        if ("watchlist".equals(CURRENT_FOLDER)) {

            PreferenceCategory category = new PreferenceCategory(this);
            category.setKey("category");
            category.setTitle(
                    getResources().getString(R.string.goo_category_title, new Object[] { CURRENT_FOLDER }));
            pScreen.addPreference(category);
            refreshWatchlist();
        } else {

            PreferenceCategory category = new PreferenceCategory(this);
            category.setTitle(
                    getResources().getString(R.string.goo_category_title, new Object[] { CURRENT_FOLDER }));
            pScreen.addPreference(category);
            try {

                JSONObject object = (JSONObject) new JSONTokener(CURRENT_NAVIGATION).nextValue();
                JSONArray list = object.getJSONArray("list");

                for (int i = 0; i < list.length(); i++) {

                    JSONObject result = list.getJSONObject(i);
                    String fileName = result.optString("filename");

                    if (fileName != null && !"".equals(fileName.trim())) {

                        String path = result.optString("path");

                        if (!BROWSING_ALL && !mDevice.equals(result.optString("ro_board"))) {
                            continue;
                        }

                        GooPackage info = new GooPackage(result, -1);
                        mInfos.put(path, info);

                        Preference preference = new Preference(this);
                        preference.getExtras().putBoolean("FOLDER", false);
                        preference.setKey(path);
                        preference.setTitle(fileName);
                        preference.setSummary(path);
                        category.addPreference(preference);

                    } else {

                        String folder = result.optString("folder");
                        String folderName = folder.substring(folder.lastIndexOf("/") + 1);

                        Preference preference = new FolderPreference(this, folder, false);
                        preference.getExtras().putBoolean("BROWSING_ALL", BROWSING_ALL);
                        preference.getExtras().putBoolean("FOLDER", true);
                        preference.getExtras().putString("PATH", folder);
                        if (!BROWSING_ALL) {
                            preference.setKey(Constants.GOO_SEARCH_URL + folder + "&ro_board=" + mDevice);
                        } else {
                            preference.setKey(Constants.GOO_SEARCH_URL + folder);
                        }
                        preference.setTitle(folderName);
                        preference.setSummary(folder);
                        category.addPreference(preference);
                    }
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                Toast.makeText(this, R.string.goo_browse_error, Toast.LENGTH_LONG).show();
            }
        }
    }
    if (DIALOG != null)
        DIALOG.dismiss();

    DIALOG = null;

    ListView listView = getListView();
    listView.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            ListView listView = (ListView) parent;
            ListAdapter listAdapter = listView.getAdapter();
            Object obj = listAdapter.getItem(position);
            if (obj != null && obj instanceof View.OnLongClickListener) {
                View.OnLongClickListener longListener = (View.OnLongClickListener) obj;
                return longListener.onLongClick(view);
            }
            return false;
        }
    });
}

From source file:org.quantumbadger.redreader.activities.InboxListingActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {

    PrefsUtility.applyTheme(this);
    super.onCreate(savedInstanceState);

    final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    final boolean solidblack = PrefsUtility.appearance_solidblack(this, sharedPreferences)
            && PrefsUtility.appearance_theme(this, sharedPreferences) == PrefsUtility.AppearanceTheme.NIGHT;

    getActionBar().setHomeButtonEnabled(true);
    getActionBar().setDisplayHomeAsUpEnabled(true);

    final String title;

    isModmail = getIntent() != null && getIntent().getBooleanExtra("modmail", false);

    if (!isModmail) {
        title = getString(R.string.mainmenu_inbox);
    } else {//  www.j  a  v a  2s  .  c  o  m
        title = getString(R.string.mainmenu_modmail);
    }

    OptionsMenuUtility.fixActionBar(this, title);

    headerItems = PrefsUtility.appearance_comment_header_items(this, sharedPreferences);
    headerItems.remove(PrefsUtility.AppearanceCommentHeaderItems.SCORE);

    final LinearLayout outer = new LinearLayout(this);
    outer.setOrientation(android.widget.LinearLayout.VERTICAL);

    if (solidblack) {
        outer.setBackgroundColor(Color.BLACK);
    }

    loadingView = new LoadingView(this, getString(R.string.download_waiting), true, true);

    notifications = new LinearLayout(this);
    notifications.setOrientation(android.widget.LinearLayout.VERTICAL);
    notifications.addView(loadingView);

    final ListView lv = new ListView(this);

    lv.setSmoothScrollbarEnabled(false);
    lv.setVerticalFadingEdgeEnabled(false);

    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            final Object item = lv.getAdapter().getItem(position);

            if (item != null && item instanceof RedditPreparedInboxItem) {
                ((RedditPreparedInboxItem) item).handleInboxClick(InboxListingActivity.this);
            }
        }
    });

    adapter = new InboxListingAdapter(this, this);
    lv.setAdapter(adapter);

    registerForContextMenu(lv);

    outer.addView(notifications);
    outer.addView(lv);

    makeFirstRequest(this);

    setContentView(outer);
}