List of usage examples for android.widget ListView setAdapter
@Override public void setAdapter(ListAdapter adapter)
From source file:no.nordicsemi.android.nrftoolbox.dfu.DfuActivity.java
/** * Called when Select File was pressed//from www . j a v a2 s.c o m * * @param view * a button that was pressed */ public void onSelectFileClicked(final View view) { final Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("application/octet-stream"); intent.addCategory(Intent.CATEGORY_OPENABLE); if (intent.resolveActivity(getPackageManager()) != null) { // file browser has been found on the device startActivityForResult(intent, SELECT_FILE_REQ); } else { // there is no any file browser app, let's try to download one final View customView = getLayoutInflater().inflate(R.layout.app_file_browser, null); final ListView appsList = (ListView) customView.findViewById(android.R.id.list); appsList.setAdapter(new FileBrowserAppsAdapter(this)); appsList.setChoiceMode(ListView.CHOICE_MODE_SINGLE); appsList.setItemChecked(0, true); new AlertDialog.Builder(this).setTitle(R.string.dfu_alert_no_filebrowser_title).setView(customView) .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { dialog.dismiss(); } }).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { final int pos = appsList.getCheckedItemPosition(); if (pos >= 0) { final String query = getResources() .getStringArray(R.array.dfu_app_file_browser_action)[pos]; final Intent storeIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(query)); startActivity(storeIntent); } } }).show(); } }
From source file:com.aniruddhc.acemusic.player.Dialogs.BlacklistedElementsDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { mApp = (Common) getActivity().getApplicationContext(); final BlacklistedElementsDialog dialog = this; MANAGER_TYPE = getArguments().getString("MANAGER_TYPE"); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); //Get a cursor with a list of blacklisted elements. if (MANAGER_TYPE.equals("ARTISTS")) { builder.setTitle(R.string.blacklisted_artists); cursor = mApp.getDBAccessHelper().getBlacklistedArtists(); } else if (MANAGER_TYPE.equals("ALBUMS")) { builder.setTitle(R.string.blacklisted_albums); cursor = mApp.getDBAccessHelper().getBlacklistedAlbums(); } else if (MANAGER_TYPE.equals("SONGS")) { builder.setTitle(R.string.blacklisted_songs); cursor = mApp.getDBAccessHelper().getAllBlacklistedSongs(); } else if (MANAGER_TYPE.equals("PLAYLISTS")) { builder.setTitle(R.string.blacklisted_playlists); /*DBAccessHelper playlistsDBHelper = new DBAccessHelper(getActivity()); cursor = playlistsDBHelper.getAllBlacklistedPlaylists();*/ } else {/* ww w .j a v a 2s . c om*/ Toast.makeText(getActivity(), R.string.error_occurred, Toast.LENGTH_LONG).show(); return builder.create(); } //Dismiss the dialog if there are no blacklisted elements. if (cursor.getCount() == 0) { Toast.makeText(getActivity(), R.string.no_blacklisted_items_found, Toast.LENGTH_LONG).show(); return builder.create(); } //Loop through checkboxStatuses and insert "TRUE" at every position by default. for (int i = 0; i < cursor.getCount(); i++) { checkboxStatuses.add(true); } View rootView = this.getLayoutInflater(savedInstanceState).inflate(R.layout.fragment_blacklist_manager, null); TextView blacklistManagerInfoText = (TextView) rootView.findViewById(R.id.blacklist_manager_info_text); ListView blacklistManagerListView = (ListView) rootView.findViewById(R.id.blacklist_manager_list); blacklistManagerInfoText.setTypeface(TypefaceHelper.getTypeface(getActivity(), "RobotoCondensed-Light")); blacklistManagerInfoText.setPaintFlags( blacklistManagerInfoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); blacklistManagerListView.setFastScrollEnabled(true); BlacklistedElementsAdapter adapter = new BlacklistedElementsAdapter(getActivity(), cursor); blacklistManagerListView.setAdapter(adapter); builder.setView(rootView); builder.setNegativeButton(R.string.cancel, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { dialog.dismiss(); } }); builder.setPositiveButton(R.string.done, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //Loop through checkboxStatuses and unblacklist the elements that have been unchecked. for (int i = 0; i < checkboxStatuses.size(); i++) { cursor.moveToPosition(i); if (checkboxStatuses.get(i) == true) { //The item is still blacklisted. continue; } else { //The item has been unblacklisted. if (MANAGER_TYPE.equals("ARTISTS")) { mApp.getDBAccessHelper().setBlacklistForArtist( cursor.getString(cursor.getColumnIndex(DBAccessHelper.SONG_ARTIST)), false); } else if (MANAGER_TYPE.equals("ALBUMS")) { mApp.getDBAccessHelper().setBlacklistForAlbum( cursor.getString(cursor.getColumnIndex(DBAccessHelper.SONG_ALBUM)), cursor.getString(cursor.getColumnIndex(DBAccessHelper.SONG_ARTIST)), false); } else if (MANAGER_TYPE.equals("SONGS")) { mApp.getDBAccessHelper().setBlacklistForSong( cursor.getString(cursor.getColumnIndex(DBAccessHelper.SONG_FILE_PATH)), false); } else if (MANAGER_TYPE.equals("PLAYLISTS")) { /*DBAccessHelper playlistsDBHelper = new DBAccessHelper(getActivity()); playlistsDBHelper.unBlacklistPlaylist(cursor.getString(cursor.getColumnIndex(DBAccessHelper.PLAYLIST_BLACKLIST_STATUS)));*/ } } } dialog.dismiss(); } }); return builder.create(); }
From source file:com.group7.dragonwars.MapSelectActivity.java
@Override protected final void onStart() { super.onStart(); if (mapInfo.size() == 0) { AssetManager assman = getAssets(); ListView mapList = (ListView) this.findViewById(R.id.mapList); try {// www. ja v a2 s. c om String[] files = assman.list("maps"); for (int i = 0; i < files.length; ++i) { String path = "maps/" + files[i]; BasicMapInfo info = MapReader.getBasicMapInformation(path, this); mapInfo.add(info); } String[] displayInfo = new String[mapInfo.size()]; for (Integer i = 0; i < mapInfo.size(); i++) { displayInfo[i] = mapInfo.get(i).getDesc(); } ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, displayInfo); mapList.setAdapter(adapter); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } } }
From source file:com.irccloud.android.activity.UploadsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { if (ColorFormatter.file_uri_template != null) template = UriTemplate.fromTemplate(ColorFormatter.file_uri_template); super.onCreate(savedInstanceState); if (Build.VERSION.SDK_INT >= 21) { Bitmap cloud = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); setTaskDescription(new ActivityManager.TaskDescription(getResources().getString(R.string.app_name), cloud, 0xFFF2F7FC));/*from w w w . j a va 2 s .c o m*/ cloud.recycle(); } if (Build.VERSION.SDK_INT >= 14) { try { java.io.File httpCacheDir = new java.io.File(getCacheDir(), "http"); long httpCacheSize = 10 * 1024 * 1024; // 10 MiB HttpResponseCache.install(httpCacheDir, httpCacheSize); } catch (IOException e) { Log.i("IRCCloud", "HTTP response cache installation failed:" + e); } } setContentView(R.layout.ignorelist); if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeAsUpIndicator(R.drawable.abc_ic_ab_back_mtrl_am_alpha); getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar)); getSupportActionBar().setElevation(0); } if (savedInstanceState != null && savedInstanceState.containsKey("cid")) { cid = savedInstanceState.getInt("cid"); to = savedInstanceState.getString("to"); msg = savedInstanceState.getString("msg"); page = savedInstanceState.getInt("page"); File[] files = (File[]) savedInstanceState.getSerializable("adapter"); for (File f : files) { adapter.addFile(f); } adapter.notifyDataSetChanged(); } footer = getLayoutInflater().inflate(R.layout.messageview_header, null); ListView listView = (ListView) findViewById(android.R.id.list); listView.setAdapter(adapter); listView.addFooterView(footer); listView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView absListView, int i) { } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (canLoadMore && firstVisibleItem + visibleItemCount > totalItemCount - 4) { canLoadMore = false; new FetchFilesTask().execute((Void) null); } } }); listView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { final File f = (File) adapter.getItem(i); AlertDialog.Builder builder = new AlertDialog.Builder(UploadsActivity.this); builder.setInverseBackgroundForced(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB); final View v = getLayoutInflater().inflate(R.layout.dialog_upload, null); final EditText messageinput = (EditText) v.findViewById(R.id.message); messageinput.setText(msg); final ImageView thumbnail = (ImageView) v.findViewById(R.id.thumbnail); v.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (messageinput.hasFocus()) { v.post(new Runnable() { @Override public void run() { v.scrollTo(0, v.getBottom()); } }); } } }); if (f.mime_type.startsWith("image/")) { try { thumbnail.setImageBitmap(f.image); thumbnail.setVisibility(View.VISIBLE); thumbnail.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent i = new Intent(UploadsActivity.this, ImageViewerActivity.class); i.setData(Uri.parse(f.url)); startActivity(i); } }); thumbnail.setClickable(true); } catch (Exception e) { e.printStackTrace(); } } else { thumbnail.setVisibility(View.GONE); } ((TextView) v.findViewById(R.id.filesize)).setText(f.metadata); v.findViewById(R.id.filename).setVisibility(View.GONE); v.findViewById(R.id.filename_heading).setVisibility(View.GONE); builder.setTitle("Send A File To " + to); builder.setView(v); builder.setPositiveButton("Send", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String message = messageinput.getText().toString(); if (message.length() > 0) message += " "; message += f.url; dialog.dismiss(); if (getParent() == null) { setResult(Activity.RESULT_OK); } else { getParent().setResult(Activity.RESULT_OK); } finish(); NetworkConnection.getInstance().say(cid, to, message); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); AlertDialog d = builder.create(); d.setOwnerActivity(UploadsActivity.this); d.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); d.show(); } }); }
From source file:de.geeksfactory.opacclient.frontend.OpacActivity.java
public void selectaccount() { AlertDialog.Builder builder = new AlertDialog.Builder(this); // Get the layout inflater LayoutInflater inflater = getLayoutInflater(); View view = inflater.inflate(R.layout.dialog_simple_list, null); ListView lv = (ListView) view.findViewById(R.id.lvBibs); AccountDataSource data = new AccountDataSource(this); data.open();/*from w w w . j a v a 2 s. c om*/ final List<Account> accounts = data.getAllAccounts(); data.close(); AccountListAdapter adapter = new AccountListAdapter(this, accounts); lv.setAdapter(adapter); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { app.setAccount(accounts.get(position).getId()); adialog.dismiss(); ((AccountSelectedListener) fragment).accountSelected(accounts.get(position)); } }); builder.setTitle(R.string.account_select).setView(view) .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { adialog.cancel(); } }).setNeutralButton(R.string.accounts_edit, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); Intent intent = new Intent(OpacActivity.this, AccountListActivity.class); startActivity(intent); } }); adialog = builder.create(); adialog.show(); }
From source file:edu.csh.coursebrowser.CourseActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_course); // Show the Up button in the action bar. this.getActionBar().setHomeButtonEnabled(false); map_item = new HashMap<String, Course>(); map = new ArrayList<String>(); Bundle args = this.getIntent().getExtras(); this.setTitle(args.getCharSequence("title")); try {/*from w w w. ja v a 2 s . com*/ JSONObject jso = new JSONObject(args.get("args").toString()); JSONArray jsa = new JSONArray(jso.getString("courses")); ListView lv = (ListView) this.findViewById(R.id.course_list); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, map); for (int i = 0; i < jsa.length(); ++i) { String s = jsa.getString(i); JSONObject obj = new JSONObject(s); Course course = new Course(obj.getString("title"), obj.getString("department"), obj.getString("course"), obj.getString("description"), obj.getString("id")); addItem(course); Log.v("Added", course.toString()); } lv.setAdapter(adapter); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { String s = ((TextView) arg1).getText().toString(); final Course course = map_item.get(s); new AsyncTask<String, String, String>() { ProgressDialog p; protected void onPreExecute() { p = new ProgressDialog(CourseActivity.this); p.setTitle("Fetching Info"); p.setMessage("Contacting Server..."); p.setCancelable(false); p.show(); } protected String doInBackground(String... dep) { String params = "action=getSections&course=" + course.id; Log.v("Params", params); URL url; String back = ""; try { url = new URL("http://iota.csh.rit" + ".edu/schedule/js/browseAjax" + ".php"); URLConnection conn = url.openConnection(); conn.setDoOutput(true); OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream()); writer.write(params); writer.flush(); String line; BufferedReader reader = new BufferedReader( new InputStreamReader(conn.getInputStream())); while ((line = reader.readLine()) != null) { Log.v("Back:", line); back += line; } writer.close(); reader.close(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); p.dismiss(); return null; } return back; } protected void onPostExecute(String s) { if (s == null || s == "") { new AlertError(CourseActivity.this, "IO Error!").show(); return; } try { JSONObject jso = new JSONObject(s); JSONArray jsa = new JSONArray(jso.getString("sections")); } catch (JSONException e) { e.printStackTrace(); new AlertError(CourseActivity.this, "Invalid JSON From Server").show(); p.dismiss(); return; } Intent intent = new Intent(CourseActivity.this, SectionsActivity.class); intent.putExtra("title", course.title); intent.putExtra("id", course.id); intent.putExtra("description", course.description); intent.putExtra("args", s); startActivity(intent); p.dismiss(); } }.execute(course.id); } }); } catch (JSONException e) { // TODO Auto-generated catch block new AlertError(this, "Invalid JSON"); e.printStackTrace(); } }
From source file:most.voip.example.ws_config.MainActivity.java
private void initializeGUI() { setContentView(R.layout.activity_main); ListView listView = (ListView) findViewById(R.id.listOperations); ListView buddiesView = (ListView) findViewById(R.id.listBuddies); this.infoArray = new ArrayList<String>(); this.arrayAdapter = new ArrayAdapter<String>(this, R.layout.row, R.id.textViewList, this.infoArray); listView.setAdapter(this.arrayAdapter); buddiesView.setOnItemClickListener(new OnItemClickListener() { @Override//from w w w .j a v a 2 s . co m public void onItemClick(AdapterView<?> parent, View view, int position, long id) { EditText txtExtension = (EditText) findViewById(R.id.txtExtension); txtExtension.setText(buddiesArray.get(position).getExtension()); } }); this.buddiesArray = new ArrayList<IBuddy>(); this.buddyArrayAdapter = new BuddyArrayAdapter(this, R.layout.buddy_row, this.buddiesArray); buddiesView.setAdapter(this.buddyArrayAdapter); this.setupButtons(); //this.addInfoLine("Most Voip Lib Test Example 1"); }
From source file:com.android.calculator2.FloatingCalculatorPageAdapter.java
private void setUpHistory(ListView historyView) { FloatingHistoryAdapter.OnHistoryItemClickListener listener = new FloatingHistoryAdapter.OnHistoryItemClickListener() { @Override/*from w ww . j av a 2s .c om*/ public void onHistoryItemClick(HistoryEntry entry) { int deleteMode = mLogic.getDeleteMode(); if (mDisplay.getText().isEmpty()) { deleteMode = Logic.DELETE_MODE_CLEAR; } mDisplay.insert(entry.getEdited()); mLogic.setDeleteMode(deleteMode); } }; FloatingHistoryAdapter historyAdapter = new FloatingHistoryAdapter(mContext, mHistory); historyAdapter.setOnHistoryItemClickListener(listener); mHistory.setObserver(historyAdapter); historyView.setAdapter(historyAdapter); historyView.setStackFromBottom(true); historyView.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL); }
From source file:net.networksaremadeofstring.pulsant.portal.InvoiceLanding.java
public void onCreate(Bundle savedInstanceState) { API.SessionID = getIntent().getStringExtra("sessionid"); super.onCreate(savedInstanceState); setContentView(R.layout.invoicelanding); final ListView list = (ListView) findViewById(R.id.InvoiceList); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setTitle("Accounting"); final ProgressDialog dialog = ProgressDialog.show(this, "Pulsant Portal", "Please wait: loading data....", true);// w ww . j av a2s.c o m final Handler handler = new Handler() { public void handleMessage(Message msg) { dialog.dismiss(); if (Success.equals("true")) { UpdateErrorMessage(ErrorMessage); InvoiceAdaptor adapter = new InvoiceAdaptor(InvoiceLanding.this, listOfInvoices, API.SessionID); list.setAdapter(adapter); } else { UpdateErrorMessage(ErrorMessage); } } }; Thread dataPreload = new Thread() { public void run() { try { InvoiceAPIReturn = API.PortalQueryHack("invoices", "", ""); Success = InvoiceAPIReturn.getString("success"); } catch (JSONException e) { ErrorMessage = "An unrecoverable JSON Exception occured."; Success = "false"; } if (Success.equals("false")) { Log.i("API", "Success was false"); try { ErrorMessage = InvoiceAPIReturn.getJSONObject("hackReturn").getString("msg"); } catch (JSONException e) { ErrorMessage = "A JSON parsing error prevented an exact error message to be determined."; } } else { int InvoiceCount = 0; Log.i("APIFuncs", InvoiceAPIReturn.toString()); try { Invoices = InvoiceAPIReturn.getJSONObject("hackReturn").getJSONArray("data"); InvoiceCount = Invoices.length(); ErrorMessage = ""; } catch (JSONException e) { ErrorMessage = "There don't appear to be any invoices for your account....."; InvoiceCount = 0; Log.e("API", "There was an eror parsing the array"); Log.e("API", e.getMessage()); } //OK lets actually do something useful if (InvoiceCount == 0) { Success = "false"; ErrorMessage = "There are no invoices for your account."; handler.sendEmptyMessage(0); return; } for (int i = 0; i < InvoiceCount; i++) { JSONObject CurrentInvoice = null; try { CurrentInvoice = Invoices.getJSONObject(i); } catch (JSONException e1) { Log.e("APIFuncs", e1.getMessage()); } try { if (CurrentInvoice.getString("type").equals("invoice")) { listOfInvoices.add(new Invoices(CurrentInvoice.getString("ref"), CurrentInvoice.getDouble("amount"), CurrentInvoice.getString("details"), CurrentInvoice.getString("date"))); } else { Receipts.add(new Receipts(CurrentInvoice.getString("ref"), CurrentInvoice.getDouble("amount"), CurrentInvoice.getString("details"), CurrentInvoice.getString("date"))); } } catch (JSONException e) { Log.e("APIFuncs", e.getMessage()); } } } handler.sendEmptyMessage(0); } }; dataPreload.start(); }
From source file:com.nextgis.forestinspector.activity.MainActivity.java
protected void createSecondStartView(Account account) { setContentView(R.layout.activity_main_second); setToolbar(R.id.main_toolbar);//from w w w .ja v a 2s. c om setTitle(getText(R.string.initialization)); mAdapter = new InitStepListAdapter(this); ListView list = (ListView) findViewById(R.id.stepsList); list.setAdapter(mAdapter); final InitAsyncTask task = new InitAsyncTask(account); Button cancelButton = (Button) findViewById(R.id.cancel); cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { task.cancel(true); } }); task.execute(); }