Example usage for android.widget ListView setAdapter

List of usage examples for android.widget ListView setAdapter

Introduction

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

Prototype

@Override
public void setAdapter(ListAdapter adapter) 

Source Link

Document

Sets the data behind this ListView.

Usage

From source file:com.example.ahmed.ui.Welcome.InfoActivity.java

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

    setContentView(R.layout.activity_info);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    if (toolbar != null) {
        setSupportActionBar(toolbar);/*  ww w . j  a  va  2  s .  co  m*/
        getSupportActionBar().setTitle(R.string.title_activity_info);
        getSupportActionBar().setDisplayShowTitleEnabled(true);
        getSupportActionBar().setLogo(R.mipmap.ic_launcher);
    }

    List<Pair<String, String>> data;
    data = new ArrayList();
    data.add(new Pair("Version", BuildConfig.VERSION_NAME));
    data.add(new Pair("Poject", "Theralytics"));
    data.add(new Pair("Authors", "AH & KC & EA"));

    ListView listView = (ListView) findViewById(R.id.info_listview);

    ListAdapter adapter = new PairAdapter(this, data);
    listView.setAdapter(adapter);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            switch (position) {
            case 1:
                showLicenseInfo();
                break;
            default:
                break;
            }
        }
    });
}

From source file:com.chess.genesis.activity.GameListLocalFrag.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    initBaseContentFrag(container);//from  w  ww.  j a  v  a 2s  .  c o m

    final View view = inflater.inflate(R.layout.fragment_gamelist_local, null);

    // set list adapters
    gamelist_adapter = new GameListAdapter(getActivity(), Enums.LOCAL_GAME, Enums.YOUR_TURN);

    final ListView gamelist_view = (ListView) view.findViewById(R.id.game_list);
    gamelist_view.setAdapter(gamelist_adapter);
    gamelist_view.setOnItemClickListener(this);

    // set empty view item
    final View empty = gamelist_adapter.getEmptyView(getActivity());
    ((ViewGroup) gamelist_view.getParent()).addView(empty);
    gamelist_view.setEmptyView(empty);

    registerForContextMenu(gamelist_view);

    return view;
}

From source file:com.plnyyanks.frcnotebook.datafeed.EventListFetcher.java

@Override
protected void onPostExecute(String result) {
    super.onPostExecute(result);
    //Log.d(Constants.LOG_TAG,"Event Data: "+result.toString());

    //LinearLayout eventList = (LinearLayout) listActivity.findViewById(R.id.event_list_to_download);
    ListView eventList = (ListView) listActivity.findViewById(R.id.event_list_to_download);

    adapter = new ListViewArrayAdapter(listActivity, events, keys);
    eventList.setAdapter(adapter);
    eventList.setOnItemClickListener(new EventClickListener(keys));

    //hide the progress bar
    ProgressBar prog = (ProgressBar) listActivity.findViewById(R.id.event_loading_progress);
    prog.setVisibility(View.GONE);
}

From source file:net.idlesoft.android.apps.github.activities.DiffFilesList.java

@Override
public void onCreate(final Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.diff_file_list);

    mPrefs = getSharedPreferences(Hubroid.PREFS_NAME, 0);

    mUsername = mPrefs.getString("username", "");
    mPassword = mPrefs.getString("password", "");

    mGapi.authenticate(mUsername, mPassword);

    ((ImageButton) findViewById(R.id.btn_search)).setOnClickListener(new OnClickListener() {
        public void onClick(final View v) {
            startActivity(new Intent(DiffFilesList.this, Search.class));
        }//w w  w. j  av  a 2 s  . c  o  m
    });

    final Bundle extras = getIntent().getExtras();
    if (extras != null) {
        mRepositoryName = extras.getString("repo_name");
        mRepositoryOwner = extras.getString("repo_owner");
        mType = extras.getString("type");
        try {
            mJson = new JSONObject(extras.getString("json"));
        } catch (final JSONException e) {
            e.printStackTrace();
        }

        try {
            final TextView title = (TextView) findViewById(R.id.tv_page_title);
            if (mType.equals("added")) {
                title.setText("Added Files");
            } else if (mType.equals("removed")) {
                title.setText("Removed Files");
            } else if (mType.equals("modified")) {
                title.setText("Changed Files");
            } else {
                title.setText("Files");
            }

            /*
             * Split JSONArray into a String array so we can populate the
             * list of files
             */
            final String[] filenames = new String[mJson.getJSONArray(mType).length()];
            for (int i = 0; i < filenames.length; i++) {
                if (mType.equals("modified")) {
                    filenames[i] = mJson.getJSONArray("modified").getJSONObject(i).getString("filename");
                } else {
                    filenames[i] = mJson.getJSONArray(mType).getString(i);
                }
                if (filenames[i].lastIndexOf("/") > -1) {
                    filenames[i] = filenames[i].substring(filenames[i].lastIndexOf("/") + 1);
                }
            }

            mAdapter = new ArrayAdapter<String>(DiffFilesList.this, android.R.layout.simple_list_item_1,
                    android.R.id.text1, filenames);

            final ListView file_list = (ListView) findViewById(R.id.lv_diffFileList_list);
            file_list.setAdapter(mAdapter);
            file_list.setOnItemClickListener(mOnFileListItemClick);
        } catch (final JSONException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.fastbootmobile.encore.app.fragments.HistoryFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ListView rootView = (ListView) inflater.inflate(R.layout.fragment_history, container, false);
    mAdapter = new HistoryAdapter(container.getContext());
    rootView.setAdapter(mAdapter);
    rootView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override/*from  w w  w  . j  a va2  s .  com*/
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ListenLogger.LogEntry entry = mAdapter.getItem(position);
            Song song = ProviderAggregator.getDefault().retrieveSong(entry.getReference(),
                    entry.getIdentifier());
            PlaybackProxy.playSong(song);
        }
    });
    return rootView;
}

From source file:com.enadein.carlogbook.ui.LogbookFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    adapter = new LogAdapter(getActivity(), null, getMediator().getUnitFacade());

    ListView carListView = (ListView) view.findViewById(R.id.list);
    carListView.setAdapter(adapter);

    carListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override/*from  ww  w  .  ja v a2s.co m*/
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
            int type = DBUtils.getLogTypeById(getActivity().getContentResolver(), id);
            hideMultiAction();
            getMediator().showModifyLog(type, id);
        }
    });

    final View floatingAdd = view.findViewById(R.id.add);

    if (floatingAdd != null) {
        floatingAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                View groupView = getView().findViewById(R.id.add_group);
                if (groupView.getVisibility() == View.GONE) {
                    groupView.setVisibility(View.VISIBLE);
                } else {
                    groupView.setVisibility(View.GONE);
                }
            }
        });
        view.findViewById(R.id.add_fuel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getMediator().showAddFuelLog();
                hideMultiAction();
            }
        });

        view.findViewById(R.id.add_other).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getMediator().showAddLog();
                hideMultiAction();
            }
        });
    } else {
        //      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        view.findViewById(R.id.add_fuel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getMediator().showAddFuelLog();
                hideMultiAction();
            }
        });

        view.findViewById(R.id.add_other).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getMediator().showAddLog();
                hideMultiAction();
            }
        });
    }

}

From source file:com.example.android.mediabrowserservice.BrowseFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_list, container, false);

    mBrowserAdapter = new BrowseAdapter(getActivity());

    View controls = rootView.findViewById(R.id.controls);
    controls.setVisibility(View.GONE);

    ListView listView = (ListView) rootView.findViewById(R.id.list_view);
    listView.setAdapter(mBrowserAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override/*from  w  ww.  j a v  a2  s  .c  o  m*/
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            MediaBrowserCompat.MediaItem item = mBrowserAdapter.getItem(position);
            try {
                FragmentDataHelper listener = (FragmentDataHelper) getActivity();
                listener.onMediaItemSelected(item);
            } catch (ClassCastException ex) {
                Log.e(TAG, "Exception trying to cast to FragmentDataHelper", ex);
            }
        }
    });

    Bundle args = getArguments();
    mMediaId = args.getString(ARG_MEDIA_ID, null);

    mMediaBrowser = new MediaBrowserCompat(getActivity(), new ComponentName(getActivity(), MusicService.class),
            mConnectionCallback, null);

    return rootView;
}

From source file:com.dena.app.usage.watcher.fragment.UnwatchFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup viewgroup, Bundle bundle) {
    View view = inflater.inflate(R.layout.fragment_unwatch, null);
    mActionBar = getActivity().getActionBar();
    if (null != mActionBar) {
        mActionBar.setTitle(getString(R.string.hidden_apps));
    }//from w ww.  ja  v a2s. co m
    ListView listView = (ListView) view.findViewById(R.id.listView);
    mAdapter = new UnwatchAdapter(getActivity(), R.layout.item_unwatch, new ArrayList());
    listView.setAdapter(mAdapter);
    listView.setOnItemClickListener(this);
    return view;
}

From source file:br.com.hype.medan.ThisFreeFragment.java

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

    // Inflate the layout for this fragment
    //This layout contains your list view
    View view = inflater.inflate(R.layout.fragment_happening, container, false);

    eventList = new ArrayList<Event>();
    new JSONAsyncTask().execute("http://api.hypemedan.id/androidapi/list_event_happening.php");

    //now you must initialize your list view
    ListView listview = (ListView) view.findViewById(R.id.lv_item);

    adapter = new EventAdapter(getActivity(), R.layout.lsv_item_event, eventList);

    listview.setAdapter(adapter);

    //To have custom list view use this : you must define CustomeAdapter class
    // listview.setadapter(new CustomeAdapter(getActivity()));
    //getActivty is used instead of Context
    return view;//from ww  w. j  av a 2  s.  c  o m

}

From source file:com.android.projectz.teamrocket.thebusapp.activities.SettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    this.setTheme(getResources().getIdentifier(SharedPreferencesUtils.getSelectedTheme(this), "style",
            getPackageName()));//from   w w  w  . ja  va 2s  .co  m
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbarSettings);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle(R.string.action_settings);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    TextView t1, t2, t3;
    try {
        t1 = (TextView) findViewById(R.id.versionText);
        t1.setText("Versione: " + getPackageManager().getPackageInfo(getPackageName(), 0).versionName);

        t2 = (TextView) findViewById(R.id.copyrightText);
        t2.setText("App over GNU General Public License");

        t3 = (TextView) findViewById(R.id.teamText);
        t3.setText("Copyright (C) 2016-2017 RockeTeam");
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    String[] settingText = { getResources().getString(R.string.setting_general),
            getResources().getString(R.string.setting_language),
            getResources().getString(R.string.setting_licenses),
            getResources().getString(R.string.action_changelog),
            getResources().getString(R.string.action_about) };

    Drawable[] settingImg = { ContextCompat.getDrawable(this, R.drawable.ic_generals),
            ContextCompat.getDrawable(this, R.drawable.ic_language),
            ContextCompat.getDrawable(this, R.drawable.ic_licenses),
            ContextCompat.getDrawable(this, R.drawable.ic_changelog),
            ContextCompat.getDrawable(this, R.drawable.ic_about) };

    CustomListSettingMain adapter = new CustomListSettingMain(SettingsActivity.this, settingText, settingImg);
    ListView list = (ListView) findViewById(R.id.settings_list);
    list.setAdapter(adapter);
    list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            switch (position) {
            case 0:
                startActivity(new Intent(SettingsActivity.this, SettingGeneralActivity.class));
                SettingsActivity.this.overridePendingTransition(R.anim.anim_slide_in_left,
                        R.anim.anim_slide_out_left);
                break;

            case 1:
                startActivity(new Intent(SettingsActivity.this, SettingLanguageActivity.class));
                SettingsActivity.this.overridePendingTransition(R.anim.anim_slide_in_left,
                        R.anim.anim_slide_out_left);
                break;

            case 2:
                startActivity(new Intent(SettingsActivity.this, ShowLicenceActivity.class));
                SettingsActivity.this.overridePendingTransition(R.anim.anim_slide_in_left,
                        R.anim.anim_slide_out_left);
                break;
            case 3:
                startActivity(new Intent(SettingsActivity.this, ChangelogActivity.class));
                SettingsActivity.this.overridePendingTransition(R.anim.anim_slide_in_left,
                        R.anim.anim_slide_out_left);
                break;
            case 4:
                Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(
                        SharedPreferencesUtils.getWebsiteUrl(getApplicationContext()) + "/web/about.php"));
                startActivity(browserIntent);
                SettingsActivity.this.overridePendingTransition(R.anim.anim_slide_in_left,
                        R.anim.anim_slide_out_left);
                break;
            default:
                Toast.makeText(SettingsActivity.this, "La tua richiesta ha generato un conflitto. Riprova",
                        Toast.LENGTH_SHORT).show();
                break;
            }
        }
    });

}