List of usage examples for android.widget ListView setAdapter
@Override public void setAdapter(ListAdapter adapter)
From source file:com.entertailion.android.launcher.Dialogs.java
/** * Display the list of browser bookmarks. Allow user to load bookmarked web * site.//from w ww. j av a 2s .c om * * @param context */ public static void displayBookmarks(final Launcher context) { final ArrayList<BookmarkInfo> bookmarks = loadBookmarks(context); if (bookmarks.size() > 0) { final Dialog dialog = new Dialog(context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.bookmarks_list); ListView listView = (ListView) dialog.findViewById(R.id.list); Collections.sort(bookmarks, new Comparator<BookmarkInfo>() { @Override public int compare(BookmarkInfo lhs, BookmarkInfo rhs) { return lhs.getTitle().toLowerCase().compareTo(rhs.getTitle().toLowerCase()); } }); listView.setAdapter(new BookmarkAdapter(context, bookmarks)); listView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { BookmarkInfo bookmark = (BookmarkInfo) parent.getAdapter().getItem(position); Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(bookmark.getUrl())); context.startActivity(browserIntent); context.showCover(false); dialog.dismiss(); Analytics.logEvent(Analytics.INVOKE_BOOKMARK); } }); listView.setDrawingCacheEnabled(true); listView.setOnKeyListener(onKeyListener); dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { context.showCover(false); } }); context.showCover(true); dialog.show(); Analytics.logEvent(Analytics.DIALOG_BOOKMARKS); } else { displayAlert(context, context.getString(R.string.dialog_no_browser_bookmarks)); } }
From source file:net.networksaremadeofstring.pulsant.portal.TicketLanding.java
public void onCreate(Bundle savedInstanceState) { API.SessionID = getIntent().getStringExtra("sessionid"); super.onCreate(savedInstanceState); setContentView(R.layout.ticketlanding); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setTitle("Tickets"); final ListView list = (ListView) findViewById(R.id.TicketList); final ProgressDialog dialog = ProgressDialog.show(this, "Pulsant Portal", "Please wait: loading tickets....", true); final Handler handler = new Handler() { public void handleMessage(Message msg) { dialog.dismiss();//ww w . ja v a 2s . c om if (Success.equals("true")) { UpdateErrorMessage(ErrorMessage); OpenTicketsAdaptor adapter = new OpenTicketsAdaptor(TicketLanding.this, listOfTickets, API.SessionID); list.setAdapter(adapter); } else { UpdateErrorMessage(ErrorMessage); } } }; Thread dataPreload = new Thread() { public void run() { try { TicketAPI = API.PortalQuery("tickets", "none"); Success = TicketAPI.getString("success"); } catch (JSONException e) { ErrorMessage = "An unrecoverable JSON Exception occured."; Success = "false"; } if (Success.equals("false")) { try { ErrorMessage = TicketAPI.getString("msg"); } catch (JSONException e) { ErrorMessage = "A JSON parsing error prevented an exact error message to be determined."; } } else { Log.i("APIFuncs", TicketAPI.toString()); try { Tickets = TicketAPI.getJSONArray("tickets"); ErrorMessage = ""; } catch (JSONException e) { ErrorMessage = "There are no open tickets for your account."; } //OK lets actually do something useful //ListView list = (ListView)findViewById(R.id.TicketList); //List<OpenTickets> listOfTickets = new ArrayList<OpenTickets>(); int TicketCount = Tickets.length(); if (TicketCount == 0) { ErrorMessage = "There are no open tickets for your account."; handler.sendEmptyMessage(0); return; } for (int i = 0; i < TicketCount; i++) { JSONObject CurrentTicket = null; try { CurrentTicket = Tickets.getJSONObject(i); } catch (JSONException e1) { Log.e("APIFuncs", e1.getMessage()); } try { listOfTickets.add(new OpenTickets(CurrentTicket.getString("status"), CurrentTicket.getInt("id"), CurrentTicket.getString("server"), CurrentTicket.getString("email"), CurrentTicket.getString("subject"), CurrentTicket.getInt("createdat"), CurrentTicket.getInt("lastupdate"), false)); //CurrentTicket.getBoolean("subscriber"))); } catch (JSONException e) { Log.e("APIFuncs", e.getMessage()); } } } handler.sendEmptyMessage(0); } }; dataPreload.start(); }
From source file:it.evilsocket.dsploit.plugins.mitm.hijacker.Hijacker.java
public void onCreate(Bundle savedInstanceState) { SharedPreferences themePrefs = getSharedPreferences("THEME", 0); Boolean isDark = themePrefs.getBoolean("isDark", false); if (isDark)/*from w ww.j a v a 2 s .c om*/ setTheme(R.style.Sherlock___Theme); else setTheme(R.style.AppTheme); super.onCreate(savedInstanceState); setTitle(System.getCurrentTarget() + " > MITM > " + getString(R.string.session_sniffer)); setContentView(R.layout.plugin_mitm_hijacker); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mHijackToggleButton = (ToggleButton) findViewById(R.id.hijackToggleButton); mHijackProgress = (ProgressBar) findViewById(R.id.hijackActivity); ListView mListView = (ListView) findViewById(R.id.listView); mAdapter = new SessionListAdapter(R.layout.plugin_mitm_hijacker_list_item); mSpoof = new SpoofSession(); mListView.setAdapter(mAdapter); mListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { final Session session = mAdapter.getByPosition(position); if (session != null) { new ConfirmDialog(getString(R.string.hijack_session), mRunning ? getString(R.string.start_hijacking) : getString(R.string.start_hijacking2), Hijacker.this, new ConfirmDialogListener() { @Override public void onConfirm() { if (mRunning) setStoppedState(); System.setCustomData(session); startActivity(new Intent(Hijacker.this, HijackerWebView.class)); } @Override public void onCancel() { } }).show(); } } }); mListView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { final Session session = mAdapter.getByPosition(position); if (session != null) { new InputDialog(getString(R.string.save_session), getString(R.string.set_session_filename), session.getFileName(), true, false, Hijacker.this, new InputDialogListener() { @Override public void onInputEntered(String name) { if (!name.isEmpty()) { try { String filename = session.save(name); Toast.makeText(Hijacker.this, getString(R.string.session_saved_to) + filename + " .", Toast.LENGTH_SHORT).show(); } catch (IOException e) { new ErrorDialog(getString(R.string.error), e.toString(), Hijacker.this) .show(); } } else new ErrorDialog(getString(R.string.error), getString(R.string.invalid_session), Hijacker.this).show(); } }).show(); } return true; } }); mHijackToggleButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mRunning) { setStoppedState(); } else { setStartedState(); } } }); mRequestListener = new RequestListener(); }
From source file:com.anandbibek.notifyme.MainActivity.java
@Override protected void onResume() { super.onResume(); if (!access) { ProgressDialog pDialog = new ProgressDialog(this); pDialog.setMessage(getResources().getString(R.string.main_check_checking)); pDialog.setMax(3000);/* w ww.j a va 2 s .c om*/ pDialog.setCancelable(false); pDialog.show(); stuff = new CheckAccessibilityTask(); stuff.execute(pDialog); return; } ListView mainFilterList = (ListView) this.findViewById(R.id.main_filter_list); String[] filterApps = new String[prefs.getNumberOfFilters() + 1]; for (int i = 0; i < filterApps.length; i++) { if (i == prefs.getNumberOfFilters()) { filterApps[i] = "JOKER"; } else { filterApps[i] = prefs.getFilterApp(i); } } ArrayAdapter<String> adapter = new MainFilterAdapter(this, filterApps); mainFilterList.setAdapter(adapter); mainFilterList.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent editFilterIntent = new Intent(parent.getContext(), EditFilterActivity.class); if (position == prefs.getNumberOfFilters()) { editFilterIntent.setAction("new"); } else { editFilterIntent.setAction("edit"); editFilterIntent.putExtra("filter", position); } startActivity(editFilterIntent); } }); mainFilterList.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { final int filter = position; if (filter == prefs.getNumberOfFilters()) return true; final View finalView = view; AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext()); try { builder.setTitle(getResources().getString(R.string.main_remove_title1) + " " + ((TextView) ((RelativeLayout) view).getChildAt(1)).getText() + " " + getResources().getString(R.string.main_remove_title2)); builder.setIcon(((ImageView) ((RelativeLayout) view).getChildAt(0)).getDrawable()); } catch (Exception e) { } builder.setPositiveButton(R.string.main_remove_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { prefs.removeFilter(filter); startActivity(new Intent(finalView.getContext(), MainActivity.class).setAction("redraw")); } }); builder.setNegativeButton(R.string.main_remove_cancel, null); builder.show(); return true; } }); }
From source file:com.example.fragmentexercise.DetailFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub return super.onCreateView(inflater, // container, savedInstanceState); View view = inflater.inflate(R.layout.detail_fragment, container, false); if (mContactId != null) { // TODO Auto-generated method stub // super.onActivityCreated(savedInstanceState); ListView detailListView = (ListView) view.findViewById(R.id.detail_list_view); String selectionStr = " contact_id = ?"; Cursor cursor = getActivity().getContentResolver().query(CommonDataKinds.Phone.CONTENT_URI, null, selectionStr, new String[] { mContactId }, " contact_id asc"); if (cursor != null && cursor.moveToFirst()) { List<String> listData = new ArrayList<String>(); listData.add("contact_id:" + cursor.getString(cursor.getColumnIndex(Phone.CONTACT_ID))); listData.add("name:" + cursor.getString(cursor.getColumnIndex(Phone.DISPLAY_NAME))); listData.add("phoneNumber:" + cursor.getString(cursor.getColumnIndex(Phone.NUMBER))); detailListView.setAdapter( new ArrayAdapter<String>(getActivity(), android.R.layout.test_list_item, listData)); }/* ww w .j ava2 s . c o m*/ } return view; }
From source file:com.audiokernel.euphonyrmt.SearchActivity.java
/** * This updates a specific ListView for search results. * * @param listView The ListView to update with search results. * @param resultList The List of results to enter into the ListView. * @param noResultsView The View to hide if there are no results. *///from w ww .j ava2s.co m private void update(final ListView listView, final List<? extends Item> resultList, final View noResultsView) { final ListAdapter separatedListAdapter = new SeparatedListAdapter(this, R.layout.search_list_item, new SearchResultDataBinder(), resultList); listView.setAdapter(separatedListAdapter); try { listView.setEmptyView(noResultsView); mLoadingView.setVisibility(View.GONE); } catch (final RuntimeException e) { Log.e(TAG, "Failed to update items.", e); } }
From source file:abanoubm.dayra.main.Main.java
@Override protected void onCreate(Bundle savedInstanceState) { if (Utility.getArabicLang(getApplicationContext()) == 1) { Utility.setArabicLang(getApplicationContext(), 2); Locale myLocale = new Locale("ar"); Resources res = getResources(); DisplayMetrics dm = res.getDisplayMetrics(); Configuration conf = res.getConfiguration(); conf.locale = myLocale;/* w ww.j av a2 s. c o m*/ res.updateConfiguration(conf, dm); finish(); startActivity(new Intent(getIntent())); } super.onCreate(savedInstanceState); setContentView(R.layout.act_main); ((TextView) findViewById(R.id.subhead1)).setText(R.string.app_name); ((TextView) findViewById(R.id.subhead2)).setText(BuildConfig.VERSION_NAME); findViewById(R.id.nav_back).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); ((TextView) findViewById(R.id.footer)).setText("dayra " + BuildConfig.VERSION_NAME + " @" + new SimpleDateFormat("yyyy", Locale.getDefault()).format(new Date()) + " Abanoub M."); if (!Utility.getDayraName(getApplicationContext()).equals("")) { startActivity(new Intent(getApplicationContext(), Home.class)); finish(); } ListView lv = (ListView) findViewById(R.id.home_list); mMenuItemAdapter = new MenuItemAdapter(getApplicationContext(), new ArrayList<>(Arrays.asList(getResources().getStringArray(R.array.sign_menu))), 1); lv.setAdapter(mMenuItemAdapter); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { switch (position) { case 0: sign(); break; case 1: register(); break; case 2: if (Build.VERSION.SDK_INT < 23 || ContextCompat.checkSelfPermission(Main.this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { importDB(); } else { ActivityCompat.requestPermissions(Main.this, new String[] { android.Manifest.permission.READ_EXTERNAL_STORAGE }, IMPORT_REQUEST); } break; case 3: startActivity(new Intent(Intent.ACTION_VIEW).setData( Uri.parse("https://drive.google.com/file/d/0B1rNCm5K9cvwVXJTTzNqSFdrVk0/view"))); break; case 4: startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse( "https://drive.google.com/open?id=1flSRdoiIT_hNd96Kxz3Ww3EhXDLZ45FhwFJ2hF9vl7g"))); break; case 5: { AlertDialog.Builder builder = new AlertDialog.Builder(Main.this); builder.setTitle(R.string.label_choose_language); builder.setItems(getResources().getStringArray(R.array.language_menu), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String temp; if (which == 1) { temp = "en"; Utility.setArabicLang(getApplicationContext(), 0); } else { temp = "ar"; Utility.setArabicLang(getApplicationContext(), 2); } Locale myLocale = new Locale(temp); Resources res = getResources(); DisplayMetrics dm = res.getDisplayMetrics(); Configuration conf = res.getConfiguration(); conf.locale = myLocale; res.updateConfiguration(conf, dm); finish(); startActivity(new Intent(getIntent())); } }); builder.create().show(); } break; case 6: try { getPackageManager().getPackageInfo("com.facebook.katana", 0); startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/453595434816965")) .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)); } catch (Exception e) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/dayraapp")) .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)); } break; case 7: try { getPackageManager().getPackageInfo("com.facebook.katana", 0); startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/1363784786")) .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)); } catch (Exception e) { startActivity( new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/EngineeroBono")) .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)); } break; case 8: Uri uri = Uri.parse("market://details?id=" + getPackageName()); Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri); try { startActivity(goToMarket); } catch (Exception e) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + getPackageName()))); } break; case 9: if (Build.VERSION.SDK_INT < 23 || ContextCompat.checkSelfPermission(Main.this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { Intent intent = new Intent(Intent.ACTION_VIEW).addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); intent.setDataAndType(Uri.fromFile(new File(Utility.getDayraFolder())), "*/*"); startActivity( intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)); } else { ActivityCompat.requestPermissions(Main.this, new String[] { android.Manifest.permission.WRITE_EXTERNAL_STORAGE }, FOLDER_REQUEST); } break; case 10: LayoutInflater li = LayoutInflater.from(getApplicationContext()); final View aboutView = li.inflate(R.layout.dialogue_about, null, false); final AlertDialog ad = new AlertDialog.Builder(Main.this).setCancelable(true).create(); ad.setView(aboutView, 0, 0, 0, 0); ad.show(); ((TextView) aboutView.findViewById(R.id.about)) .setText(String.format(getResources().getString(R.string.copyright), Calendar.getInstance().get(Calendar.YEAR))); ((TextView) aboutView.findViewById(R.id.notice)).setText(GoogleApiAvailability.getInstance() .getOpenSourceSoftwareLicenseInfo(getApplicationContext())); aboutView.findViewById(R.id.btn).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ad.cancel(); } }); break; } } }); }
From source file:edu.csh.coursebrowser.DepartmentActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_departments); // Show the Up button in the action bar. // getActionBar().setDisplayHomeAsUpEnabled(false); this.getActionBar().setHomeButtonEnabled(true); final Bundle b = this.getIntent().getExtras(); map_item = new HashMap<String, Department>(); map = new ArrayList<String>(); Bundle args = this.getIntent().getExtras(); this.setTitle(args.getCharSequence("from")); try {//from w ww. j ava 2s. c om JSONObject jso = new JSONObject(args.get("args").toString()); JSONArray jsa = new JSONArray(jso.getString("departments")); ListView lv = (ListView) this.findViewById(R.id.department_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); Department dept = new Department(obj.getString("title"), obj.getString("id"), obj.getString("code")); addItem(dept); Log.v("Added", dept.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 Department department = map_item.get(s); new AsyncTask<String, String, String>() { ProgressDialog p; protected void onPreExecute() { p = new ProgressDialog(DepartmentActivity.this); p.setTitle("Fetching Info"); p.setMessage("Contacting Server..."); p.setCancelable(false); p.show(); } protected String doInBackground(String... dep) { String params = "action=getCourses&department=" + dep[0] + "&quarter=" + b.getString("qCode"); 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(DepartmentActivity.this, "IO Error!").show(); return; } try { JSONObject jso = new JSONObject(s); JSONArray jsa = new JSONArray(jso.getString("courses")); } catch (JSONException e) { e.printStackTrace(); new AlertError(DepartmentActivity.this, "Invalid JSON From Server").show(); p.dismiss(); return; } Intent intent = new Intent(DepartmentActivity.this, CourseActivity.class); intent.putExtra("title", department.title); intent.putExtra("id", department.id); intent.putExtra("code", department.code); intent.putExtra("args", s); startActivity(intent); p.dismiss(); } }.execute(department.id); } }); } catch (JSONException e) { // TODO Auto-generated catch block new AlertError(this, "Invalid JSON"); e.printStackTrace(); } }
From source file:com.drinviewer.droiddrinviewer.ServerListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the view View view = inflater.inflate(R.layout.serverlist, container, false); // Get the list viewer ListView serverListView = (ListView) view.findViewById(R.id.serverListView); // Get the progress bar discoverServerProgress = (ProgressBar) view.findViewById(R.id.discoverServerProgress); // Instantiate the list adapter if it was not retained if (adapter == null) adapter = new DrinHostAdapter(view.getContext()); // set the list adapter and the OnItemClickListener serverListView.setAdapter(adapter); serverListView.setOnItemClickListener(new OnItemClickListener() { @Override//from ww w. j a v a 2s . c o m public void onItemClick(AdapterView<?> parent, View view, int position, long id) { doPairingToggle(position); } }); // Display this installation generated UUID ((TextView) view.findViewById(R.id.deviceUUID)) .setText(getString(R.string.deviceUUIDlabel) + DrinViewerApplication.getInstallationUUID()); // Sets fragment to be retained setRetainInstance(true); return view; }
From source file:com.example.research.whatis.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); Log.e("CLicked Menu", String.valueOf(id)); Log.e("CLicked action", String.valueOf(R.id.action_settings)); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { TextView view = (TextView) findViewById(R.id.textView); view.setVisibility(View.GONE); ListView lView = (ListView) findViewById(R.id.listView); lView.setVisibility(View.VISIBLE); ArrayList<String> storedWords = dbHelper.getAllWords(); Log.e("SQLite", storedWords.toString()); ArrayAdapter arrayAdapter = new ArrayAdapter(this, R.layout.activity_listview, R.id.wordsLabel, storedWords);//from w w w . ja v a 2 s.c om lView.setAdapter(arrayAdapter); } return super.onOptionsItemSelected(item); }