List of usage examples for android.widget ListView setAdapter
@Override public void setAdapter(ListAdapter adapter)
From source file:com.linkedin.android.eventsapp.EventFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final String eventNameArg = getArguments().getString(EXTRA_EVENT_NAME); final long eventDateArg = getArguments().getLong(EXTRA_EVENT_DATE); final String eventLocationArg = getArguments().getString(EXTRA_EVENT_LOCATION); int pictureIdArg = getArguments().getInt(EXTRA_PICTURE_ID); boolean isAttendingArg = getArguments().getBoolean(EXTRA_EVENT_ATTENDING); Person[] attendeesArg = (Person[]) getArguments().getParcelableArray(EXTRA_EVENT_ATTENDEES); SimpleDateFormat dateFormat = new SimpleDateFormat("E dd MMM yyyy 'at' hh:00 a"); final String dateString = dateFormat.format(new Date(eventDateArg)); View v = inflater.inflate(R.layout.layout_event_fragment, container, false); boolean accessTokenValid = LISessionManager.getInstance(getActivity()).getSession().isValid(); if (!accessTokenValid) { ViewStub linkedinLogin = (ViewStub) v.findViewById(R.id.connectWithLinkedInStub); linkedinLogin.inflate();/*from w ww . j ava 2s. c o m*/ Button loginButton = (Button) v.findViewById(R.id.connectWithLinkedInButton); loginButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.i(TAG, "clicked login button"); LISessionManager.getInstance(getActivity()).init(getActivity(), Constants.scope, new AuthListener() { @Override public void onAuthSuccess() { Intent intent = new Intent(getActivity(), MainActivity.class); startActivity(intent); getActivity().finish(); } @Override public void onAuthError(LIAuthError error) { } }, false); } }); } TextView eventNameView = (TextView) v.findViewById(R.id.eventName); eventNameView.setText(eventNameArg); TextView eventLocationAndDateView = (TextView) v.findViewById(R.id.eventLocationAndDate); eventLocationAndDateView.setText(eventLocationArg + " " + dateString); TextView eventAttendeeCount = (TextView) v.findViewById(R.id.attendeeCount); eventAttendeeCount.setText("Other Attendees (" + attendeesArg.length + ")"); ImageView eventImageView = (ImageView) v.findViewById(R.id.eventImage); eventImageView.setImageResource(pictureIdArg); final Button attendButton = (Button) v.findViewById(R.id.attendButton); final Button declineButton = (Button) v.findViewById(R.id.declineButton); if (isAttendingArg) { attendButton.setText("Attending"); attendButton.setEnabled(false); declineButton.setText("Decline"); declineButton.setEnabled(true); } attendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ((Button) v).setText("Attending"); v.setEnabled(false); declineButton.setText("Decline"); declineButton.setEnabled(true); if (LISessionManager.getInstance(getActivity()).getSession().isValid()) { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); alertDialogBuilder.setTitle("Share on LinkedIn?"); alertDialogBuilder.setCancelable(true) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { JSONObject shareObject = new JSONObject(); try { JSONObject visibilityCode = new JSONObject(); visibilityCode.put("code", "anyone"); shareObject.put("visibility", visibilityCode); shareObject.put("comment", "I am attending " + eventNameArg + " in " + eventLocationArg + " on " + dateString); } catch (JSONException e) { } APIHelper.getInstance(getActivity()).postRequest(getActivity(), Constants.shareBaseUrl, shareObject, new ApiListener() { @Override public void onApiSuccess(ApiResponse apiResponse) { Toast.makeText(getActivity(), "Your share was successful!", Toast.LENGTH_LONG); } @Override public void onApiError(LIApiError apiError) { Log.e(TAG, apiError.toString()); Toast.makeText(getActivity(), "Your share was unsuccessful. Try again later!", Toast.LENGTH_LONG); } }); } }).setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); } } }); declineButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ((Button) v).setText("Declined"); v.setEnabled(false); attendButton.setText("Attend"); attendButton.setEnabled(true); } }); ListView attendeesListView = (ListView) v.findViewById(R.id.attendeesList); AttendeeAdapter adapter = new AttendeeAdapter(getActivity(), R.layout.attendee_list_item, attendeesArg, accessTokenValid); attendeesListView.setAdapter(adapter); attendeesListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { ArrayAdapter adapter = (ArrayAdapter) parent.getAdapter(); Person person = (Person) adapter.getItem(position); Intent intent = new Intent(getActivity(), ProfileActivity.class); Bundle extras = new Bundle(); extras.putParcelable("person", person); intent.putExtras(extras); startActivity(intent); } }); return v; }
From source file:abanoubm.dayra.main.Main.java
private void sign() { String inpath;//from w w w . j a v a2 s . com if (android.os.Build.VERSION.SDK_INT >= 17) { inpath = getApplicationContext().getApplicationInfo().dataDir + "/databases/"; } else { inpath = "/data/data/" + getApplicationContext().getPackageName() + "/databases/"; } File folder = new File(inpath); File[] listOfFiles = folder.listFiles(); if (listOfFiles == null || listOfFiles.length == 0) { Toast.makeText(getApplicationContext(), R.string.msg_no_dayra, Toast.LENGTH_SHORT).show(); } else { ArrayList<String> names = new ArrayList<>(listOfFiles.length); for (File file : listOfFiles) { if (!file.getName().contains("journal")) names.add(file.getName()); } LayoutInflater li = LayoutInflater.from(getApplicationContext()); View signView = li.inflate(R.layout.dialogue_signin, null, false); final AlertDialog ad = new AlertDialog.Builder(Main.this).setCancelable(true).create(); ad.setView(signView, 0, 0, 0, 0); ad.show(); ListView nameslv = (ListView) signView.findViewById(R.id.databases_lv); nameslv.setAdapter(new ArrayAdapter<>(getApplicationContext(), R.layout.item_string, R.id.item, names)); nameslv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String str = (String) parent.getItemAtPosition(position); new SignTask().execute(str); ad.dismiss(); } }); } }
From source file:com.blueverdi.rosietheriveter.MoreFragment.java
@Override public void onResume() { super.onResume(); mapView.onResume();/*from ww w . jav a2 s . c o m*/ ListView listview = (ListView) listLayout.findViewById(R.id.siteListView); SiteArrayAdapter saa = new SiteArrayAdapter(sites); listview.setAdapter(saa); }
From source file:com.pgmacdesign.lacunacompanion.fragments.MailFragment.java
public void refreshMail() { JSONObject hashOptions = new JSONObject(); if (pageNum != 1) JsonParser.put(hashOptions, "page_number", pageNum); if (filterTag != "") JsonParser.put(hashOptions, "tags", filterTag); ClientSide.setContext(getActivity()); JSONObject result = ClientSide.send(new Object[] { hashOptions }, "/inbox", "view_inbox"); if (result != null) { JSONArray messages = JsonParser.getJA(result, "messages"); List<Map<String, String>> mailList = new ArrayList<Map<String, String>>(); ArrayList<String> mailIds = new ArrayList<String>(24); // Max numbers on each page is 25. boolean hasMail = false; // By default, so that there's no way to screw up. if (messages.length() > 0) { for (int i = 0; i < messages.length(); i++) { JSONObject message = JsonParser.getJO(messages, i); Map<String, String> datum = new HashMap<String, String>(2); datum.put("from", JsonParser.getS(message, "from")); datum.put("subject", JsonParser.getS(message, "subject")); mailList.add(datum);/*from w ww .j av a 2 s . c o m*/ mailIds.add(JsonParser.getS(message, "id")); hasMail = true; } } else { Map<String, String> datum = new HashMap<String, String>(2); datum.put("from", "No new Mail available."); datum.put("subject", "Sorry. :("); mailList.add(datum); hasMail = false; } // Let the UI refresh when there's no mails. ListView mails = (ListView) getActivity().findViewById(R.id.mails); SimpleAdapter adapter = new SimpleAdapter(getActivity(), mailList, android.R.layout.simple_list_item_2, new String[] { "from", "subject" }, new int[] { android.R.id.text1, android.R.id.text2 }); mails.setAdapter(adapter); if (hasMail == true) { final Object[] MAIL_IDS = mailIds.toArray(); //spinnerReset = System.currentTimeMillis(); mails.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> a, View v, int pos, long id) { //if (System.currentTimeMillis() - spinnerReset < 1000) { //Nothing! //} //else if (System.currentTimeMillis() - spinnerReset > 1000) { String mailId = MAIL_IDS[pos].toString(); Intent intent = new Intent(getActivity(), com.pgmacdesign.lacunacompanion.module.inbox.ViewMail.class); intent.putExtra("mailId", mailId); getActivity().startActivity(intent); //} } }); // Populate the pages Spinner. ArrayAdapter<String> pagesSpinnerAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); Spinner mailPages = (Spinner) getActivity().findViewById(R.id.mailPage); double pages = (double) Math.ceil(JsonParser.getL(result, "message_count") / 25); for (int i = 1; i < pages; i++) { pagesSpinnerAdapter.add("" + i); } mailPages.setAdapter(pagesSpinnerAdapter); mailPages.recomputeViewAttributes(mailPages); mailPages.setSelection(pageNum - 1); } } }
From source file:de.nico.asura.Main.java
private void setList() { ListView list = (ListView) findViewById(R.id.listView_main); ListAdapter adapter = new SimpleAdapter(this, downloadList, android.R.layout.simple_list_item_1, new String[] { TAG_NAME }, new int[] { android.R.id.text1 }); list.setAdapter(adapter); // Do nothing when there is no Internet if (!(Utils.isNetworkAvailable(this))) { return;//w w w .ja va 2 s. com } // React when user click on item in the list list.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View v, int pos, long id) { Uri downloadUri = Uri.parse(downloadList.get(pos).get(TAG_URL)); String title = downloadList.get(pos).get(TAG_NAME); file = new File(Environment.getExternalStorageDirectory() + "/" + localLoc + "/" + downloadList.get(pos).get(TAG_FILENAME) + ".pdf"); Uri dest = Uri.fromFile(file); if (file.exists()) { Intent pdfIntent = new Intent(Intent.ACTION_VIEW); pdfIntent.setDataAndType(dest, "application/pdf"); pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); try { startActivity(pdfIntent); } catch (ActivityNotFoundException e) { Utils.makeLongToast(Main.this, noPDF); Log.e("ActivityNotFoundException", e.toString()); } return; } // Download PDF Request request = new Request(downloadUri); request.setTitle(title).setDestinationUri(dest); downloadID = downloadManager.enqueue(request); } }); }
From source file:com.rvl.android.getnzb.LocalNZB.java
public void listLocalFiles() { Log.d(Tags.LOG, "- localnzb.listLocalFiles()"); setContentView(R.layout.localnzb);//w w w .j av a2s . c om SharedPreferences prefs = GetNZB.preferences; String preferredMethod = prefs.getString("preferredUploadMethod", ""); TextView statusbar = (TextView) findViewById(R.id.hellaStatus); statusbar.setText("Local files. Click to upload to " + preferredMethod + ", long click for options:"); Log.d(Tags.LOG, "Opening database."); Log.d(Tags.LOG, "Files dir: " + getFilesDir()); LocalNZBMetadata.openDatabase(); Cursor cur; // -- Bind the itemlist to the itemarray with the arrayadapter ArrayList<String> items = new ArrayList<String>(); ArrayAdapter<String> localFilesArrayAdapter = new LocalNZBRowAdapter(this, items); ListView localFilesListView = (ListView) findViewById(R.id.localFileList); localFilesListView.setCacheColorHint(00000000); localFilesListView.setAdapter(localFilesArrayAdapter); registerForContextMenu(localFilesListView); localFilesListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View v, int position, long id) { String localFilesArray[] = fileList(); SharedPreferences prefs = GetNZB.preferences; String preferredMethod = prefs.getString("preferredUploadMethod", ""); if (preferredMethod.equals("HellaNZB")) { Log.d(Tags.LOG, "itemclik(): uploading with HellaNZB."); uploadLocalFileHellaNZB(localFilesArray[position]); return; } if (preferredMethod.equals("FTP")) { Log.d(Tags.LOG, "itemclick(): uploading with FTP."); uploadLocalFileFTP(localFilesArray[position]); return; } } }); // Retrieve files from disc, retrieve metadata from DB, // combine this data and send it to the arrayadapter. Log.d(Tags.LOG, "Retrieving file metadata and building LocalNZB list."); String age = ""; String size = ""; String category = ""; String fileinfo = ""; String localFilesArray[] = fileList(); for (int c = 0; c < localFilesArray.length; c++) { cur = LocalNZBMetadata.myDatabase.query("file", new String[] { "_id", "name" }, "name = '" + localFilesArray[c] + "'", null, null, null, null); if (cur.moveToFirst()) { //if there is a hit, retrieve metadata int idIndex = cur.getColumnIndex("_id"); int file_id = cur.getInt(idIndex); cur = LocalNZBMetadata.myDatabase.query("meta", new String[] { "age", "size", "category" }, "file_id ='" + file_id + "'", null, null, null, null); if (cur.moveToFirst()) { int ageIndex = cur.getColumnIndex("age"); int sizeIndex = cur.getColumnIndex("size"); int catIndex = cur.getColumnIndex("category"); age = cur.getString(ageIndex); size = cur.getString(sizeIndex); category = cur.getString(catIndex); } else { // If there is no metadata for file set dummy metadata info. age = "???"; size = "???"; category = "???"; } } else { // If there is no file info in database set dummy info. age = "???"; size = "???"; category = "???"; } fileinfo = age + "#" + size + "#" + localFilesArray[c] + "#" + category; items.add(fileinfo); } Log.d(Tags.LOG, "Number of files in list: " + localFilesArray.length); localFilesArrayAdapter.notifyDataSetChanged(); LocalNZBMetadata.close(); }
From source file:com.anand.music.PlaylistFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mPlaylistExpanded = false;/* w w w .j ava2 s .c o m*/ // Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_playlist, container, false); mSeekBar = (SeekBar) view.findViewById(R.id.seekBar); mPlayPauseButton = (ImageButton) view.findViewById(R.id.button_play); mPreviousButton = (ImageButton) view.findViewById(R.id.button_previous); mNextButton = (ImageButton) view.findViewById(R.id.button_next); mFullscreenButton = (ImageButton) view.findViewById(R.id.button_fullscreen); mArtistNameView = (TextView) view.findViewById(R.id.artist_name); mSongNameView = (TextView) view.findViewById(R.id.song_name); mPlayPauseButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (mMediaPlayerService.isPlaying()) { pause(); mPlayPauseButton.setImageResource(R.drawable.ic_action_play); } else { play(); mPlayPauseButton.setImageResource(R.drawable.ic_action_pause); } } }); mNextButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (mMediaPlayerService.isPlaying()) { mMediaPlayerService.next(); } } }); mPreviousButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (mMediaPlayerService.isPlaying()) { mMediaPlayerService.previous(); } } }); // Create a callback to toggle maximizing the playlist fragment in the parent container. // In this sample, we assume the fragment exists in a parent activity that has its // views contained in a scroll view. mFullscreenButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ImageButton button = (ImageButton) view; View scrollView = getActivity().findViewById(R.id.artist_scroll_view); View playlistDetailView = getActivity().findViewById(R.id.playlist_detail); ActionBar actionBar = ((ActionBarActivity) getActivity()).getSupportActionBar(); if (!mPlaylistExpanded) { scrollView.setVisibility(View.GONE); playlistDetailView.setVisibility(View.VISIBLE); button.setImageResource(R.drawable.ic_action_return_from_full_screen); actionBar.hide(); ListView playlistView = (ListView) getActivity().findViewById(R.id.playlist); ArrayAdapter adapter = new ArrayAdapter<MediaPlayerService.PlaylistEntry>(getActivity(), android.R.layout.simple_list_item_1, mMediaPlayerService.getSongs()); playlistView.setAdapter(adapter); mPlaylistExpanded = true; } else { scrollView.setVisibility(View.VISIBLE); playlistDetailView.setVisibility(View.GONE); button.setImageResource(R.drawable.ic_action_full_screen); mPlaylistExpanded = false; actionBar.show(); } } }); return view; }
From source file:ca.ualberta.cs.shoven_habittracker.MainActivity.java
public void updateScreen() { ListView listView = (ListView) findViewById(R.id.mainHabitsListView); final ArrayList<Habit> habitList = controller.getDailySchedule(dayOfWeek).getHabits(); final ArrayAdapter<Habit> habitAdapter = new ArrayAdapter<Habit>(MainActivity.this, android.R.layout.simple_list_item_1, habitList); listView.setAdapter(habitAdapter); listView.setOnItemClickListener(MainActivity.this); WeeklyScheduleController.getWeeklySchedule().addListener(new Listener() { @Override/*from w w w .ja va 2 s . co m*/ public void update() { habitAdapter.notifyDataSetChanged(); } }); }
From source file:li.klass.fhem.appwidget.view.widget.base.otherWidgets.OtherWidgetsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.other_widgets_list, container, false); ListView listView = (ListView) view.findViewById(R.id.list); listView.setOnItemClickListener(new OnItemClickListener() { @Override/*from ww w. ja v a2 s . co m*/ public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { WidgetType widgetType = (WidgetType) view.getTag(); OtherWidgetsFragment.this.onClick(widgetType); } }); OtherWidgetsAdapter adapter = new OtherWidgetsAdapter(getActivity()); listView.setAdapter(adapter); LinearLayout emptyView = (LinearLayout) view.findViewById(R.id.emptyView); fillEmptyView(emptyView, R.string.widgetNoOther, container); return view; }
From source file:com.example.meind.meinders_habittracker.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/* w ww . j a va 2 s . co m*/ DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); //getting list of habits ListView listview = (ListView) findViewById(R.id.HabitList); final ArrayList<Habit> habitsArrayList = HabitListController.getHabitList().getAllHabits(); final ArrayAdapter<Habit> HabitAdapter = new ArrayAdapter<Habit>(this, android.R.layout.simple_list_item_1, habitsArrayList); listview.setAdapter(HabitAdapter); //added observer HabitListController.getHabitList().addListener(new Listener() { @Override public void update() { HabitAdapter.notifyDataSetChanged(); } }); //deleting habit with long click listview.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> adapterView, View view, int position, long id) { AlertDialog.Builder adb = new AlertDialog.Builder(MainActivity.this); adb.setMessage( "Delete " + HabitListController.getHabitList().getHabit(position).HabittoString() + "?"); adb.setCancelable(true); final int finalPosition = position; adb.setPositiveButton("Delete", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Habit habit = habitsArrayList.get(finalPosition); HabitListController.getHabitList().removeHabit(habit); } }); adb.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); adb.show(); return false; } }); //taken to singular activity when clicked using intent listview.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { HabitListController.setViewHabit(position); Intent intent = new Intent(MainActivity.this, SingularHabit.class); startActivity(intent); } }); }