List of usage examples for android.widget ListView setAdapter
@Override public void setAdapter(ListAdapter adapter)
From source file:com.example.ramesh.p2pfileshare.FileSend.java
private void showDir(String targetDirectory) { setCurrentPathText("Current Selection: " + currentPath); targets = new ArrayList<String>(); paths = new ArrayList<String>(); File f = new File(targetDirectory); File[] directoryContents = f.listFiles(); if (!targetDirectory.equals(root)) {//from w w w . j a v a 2s . com targets.add(root); paths.add(root); targets.add("../"); paths.add(f.getParent()); } for (File target : directoryContents) { paths.add(target.getPath()); if (target.isDirectory()) { targets.add(target.getName() + "/"); } else { targets.add(target.getName()); } } ListView fileBrowserListView = (ListView) findViewById(R.id.file_browser_listview); ArrayAdapter<String> directoryData = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, targets); fileBrowserListView.setAdapter(directoryData); fileBrowserListView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> arg0, View view, int pos, long id) { File f = new File(paths.get(pos)); if (f.isFile()) { currentPath = paths.get(pos); setCurrentPathText("Current Selection: " + f.getPath() + "/" + f.getName()); //returnTarget(); need to send confirm with send button //Return target File to activity } else { //f must be a dir if (f.canRead()) { currentPath = paths.get(pos); showDir(paths.get(pos)); } } } // TODO Auto-generated method stub }); /* final AlertDialog.Builder dialog = new AlertDialog.Builder(this); dialog.setTitle("WiFi Direct File Transfer"); */ }
From source file:com.example.weewilfred.sunshine.ForecastFragment.java
@Override //This "onCreateView" method is where the UI gets initialized public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { /*String[] data = {/*from w ww . ja v a 2s . c o m*/ "Monday - Sunny - 14/24", "Tuesday - Cloudy - 10/19", "Wednesday - Solar Flares - -45/134", "Thursday - Everyone is Dead - ?", "Friday - Everyone gone - gone.. gone", "Saturday - Glowing Green - 22/24", "Sunday - Excellent weather for Zombies" }; DUMMY DATA List<String> weekForecast = new ArrayList<String>(Arrays.asList(data)); DUMMY DATA*/ // Get a reference to the ListView, and attach this adapter to it. mForecastAdapter = new ArrayAdapter<String>( //The current context (This fragments parent activity) getActivity(), //ID of list item layout style R.layout.list_item_forecast, //ID of the textview to populate the layout R.id.list_item_forecast_textview, // Pass in Forecast Data To populate the text new ArrayList<String>()); View rootView = inflater.inflate(R.layout.fragment_main, container); //Set the mForecast Adapter to send its adapted info to the listview ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast); listView.setAdapter(mForecastAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { String forecast = mForecastAdapter.getItem(position); //Toast.makeText(getActivity(), forecast, Toast.LENGTH_SHORT).show(); Intent DetailIntent = new Intent(getActivity(), DetailActivity.class).putExtra(Intent.EXTRA_TEXT, forecast); startActivity(DetailIntent); } }); return rootView; }
From source file:com.example.jim.app1.ForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Create some dummy data for the ListView. Here's a sample weekly forecast String[] data = { "Mon 6/23- Sunny - 31/17", "Tue 6/24 - Foggy - 21/8", "Wed 6/25 - Cloudy - 22/17", "Thurs 6/26 - Rainy - 18/11", "Fri 6/27 - Foggy - 21/10", "Sat 6/28 - TRAPPED IN WEATHERSTATION - 23/18", "Sun 6/29 - Sunny - 20/7" }; List<String> weekForecast = new ArrayList<String>(Arrays.asList(data)); // Now that we have some dummy forecast data, create an ArrayAdapter. // The ArrayAdapter will take data from a source (like our dummy forecast) and // use it to populate the ListView it's attached to. mForecastAdapter = new ArrayAdapter<String>(getActivity(), // The current context (this activity) R.layout.list_item_forecast, // The name of the layout ID. R.id.list_item_forecast_textview, // The ID of the textview to populate. weekForecast);//from ww w . ja va 2 s .com View rootView = inflater.inflate(R.layout.fragment_main, container, false); // Get a reference to the ListView, and attach this adapter to it. ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast); listView.setAdapter(mForecastAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { /* @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { String forecast = mForecastAdapter.getItem(position); Toast.makeText(getActivity(), forecast, Toast.LENGTH_SHORT).show(); } */ @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { String forecast = mForecastAdapter.getItem(position); Intent i = new Intent(getActivity(), DetailActivity.class).putExtra(Intent.EXTRA_TEXT, forecast); startActivity(i); } }); return rootView; }
From source file:com.lingeringsocket.mobflare.Main.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);/* w w w . jav a 2 s .c o m*/ emptyMessage = getString(R.string.empty_message); ListView flareListView = (ListView) findViewById(R.id.flare_list); flareList = new ArrayList<String>(); arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, flareList); flareListView.setAdapter(arrayAdapter); flareListView.setOnItemClickListener(new ListView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String flareName = flareList.get((int) id); if (flareName.equals(emptyMessage)) { onCreateClicked(view); return; } Intent i = new Intent(Main.this, WaitFlare.class); i.putExtra(FlareTimer.FLARE_NAME, flareName); startActivity(i); } }); rpcCoordinator = new RpcCoordinator(this); refresh(); }
From source file:com.arantius.tivocommander.MyShows.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle bundle = getIntent().getExtras(); if (MindRpc.init(this, bundle)) { return;//from ww w. j a va 2 s .c o m } if (bundle != null) { mFolderId = bundle.getString("folderId"); setTitle(bundle.getString("folderName")); } else { mFolderId = null; setTitle("My Shows"); } Utils.log(String.format("MyShows: folderId:%s", mFolderId)); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.list_my_shows); if (mFolderId != null) { findViewById(R.id.sort_button).setVisibility(View.GONE); } mListAdapter = new ShowsAdapter(this); final ListView lv = getListView(); lv.setAdapter(mListAdapter); lv.setOnItemClickListener(mOnClickListener); lv.setLongClickable(true); lv.setOnItemLongClickListener(this); mDetailCallback = new MindRpcResponseListener() { public void onResponse(MindRpcResponse response) { setProgressIndicator(-1); String itemId = "recordingFolderItem"; if ("deleted".equals(mFolderId)) { itemId = "recording"; } final JsonNode items = response.getBody().path(itemId); ArrayList<Integer> slotMap = mRequestSlotMap.get(response.getRpcId()); MindRpc.saveBodyId(items.path(0).path("bodyId").asText(), MyShows.this); for (int i = 0; i < items.size(); i++) { int pos = slotMap.get(i); JsonNode item = items.get(i); mShowData.set(pos, item); mShowStatus.set(pos, ShowStatus.LOADED); } mRequestSlotMap.remove(response.getRpcId()); mListAdapter.notifyDataSetChanged(); } }; mIdSequenceCallback = new MindRpcResponseListener() { public void onResponse(MindRpcResponse response) { JsonNode body = response.getBody(); if ("error".equals(body.path("status").asText())) { Utils.log("Handling mIdSequenceCallback error response by " + "finishWithRefresh()"); finishWithRefresh(); return; } if (!body.has("objectIdAndType")) { Utils.log("Handling mIdSequenceCallback empty response by " + "finishWithRefresh()"); finishWithRefresh(); return; } setProgressIndicator(-1); mShowIds = (ArrayNode) body.findValue("objectIdAndType"); if (mFolderId == null) { mShowIds.add("deleted"); } if (mShowIds != null) { // e.g. "Suggestions" can be present, but empty! for (int i = 0; i < mShowIds.size(); i++) { mShowData.add(null); mShowStatus.add(ShowStatus.MISSING); } } mListAdapter.notifyDataSetChanged(); } }; startRequest(); }
From source file:com.achep.acdisplay.ui.fragments.dialogs.SetupPermissionsDialog.java
@NonNull @Override//www . j a v a2s . c o m public Dialog onCreateDialog(Bundle savedInstanceState) { Context context = getActivity(); assert context != null; View view = new DialogBuilder(context).setTitle(R.string.permissions_dialog_title) .setView(R.layout.dialog_permissions).createSkeletonView(); // Make title more red TextView title = (TextView) view.findViewById(R.id.title); title.setTextColor(title.getCurrentTextColor() & 0xFFFF3333 | 0xFF << 16); ListView listView = (ListView) view.findViewById(R.id.list); mAdapter = new Adapter(context, new ArrayList<Item>()); listView.setAdapter(mAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Adapter adapter = (Adapter) parent.getAdapter(); Item item = adapter.getItem(position); item.run(); } }); return new AlertDialog.Builder(context).setView(view).setNeutralButton(R.string.later, null).create(); }
From source file:com.mohammedsazidalrashid.android.sunshine.ForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View rootView = inflater.inflate(R.layout.fragment_forecast, container, false); mSwipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe_refresh_layout); mSwipeRefreshLayout.setOnRefreshListener(this); mSwipeRefreshLayout.setColorSchemeResources(R.color.light_blue_500, R.color.orange_500, R.color.teal500, R.color.green_500);/*from w w w .j a va 2 s . com*/ mForecastAdapater = new ArrayAdapter<>(getActivity(), R.layout.list_item_forecast, R.id.list_item_forecast_textview, new ArrayList<String>()); final ListView listviewForecast = (ListView) rootView.findViewById(R.id.listview_forecast); listviewForecast.setAdapter(mForecastAdapater); listviewForecast.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { String forecast = mForecastAdapater.getItem(position); MainActivity.bundleForFragments.putString(EXTRA_FORECAST, forecast); getActivity().getFragmentManager().beginTransaction().addToBackStack(null) .setCustomAnimations(R.animator.enter_anim, R.animator.exit_anim, R.animator.enter_anim_reverse, R.animator.exit_anim_reverse) .replace(R.id.container, new DetailsFragment()).commit(); } }); listviewForecast.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { int topRowVerticalPosition = (listviewForecast == null || listviewForecast.getChildCount() == 0) ? 0 : listviewForecast.getChildAt(0).getTop(); mSwipeRefreshLayout.setEnabled(topRowVerticalPosition >= 0); } }); return rootView; }
From source file:br.unisinos.evertonlucas.passshelter.app.UsersNewGroupActivity.java
public void loadListAdapter(ListView listView, List<ParseUser> emailList, int resource) { String[] from = { "email" }; int[] to = { R.id.txt_user_new_group }; SimpleAdapter adapter = new SimpleAdapter(this, listResources(emailList), resource, from, to); listView.setAdapter(adapter); }
From source file:com.example.droidcodin.popularmdb.MovieDetailFragment.java
private void fetchMovieReviews(String movieID) { RestClient restclient = new RestClient(); restclient.getApiService().getReview(movieID, apiKey, new Callback<ReviewList>() { @Override// w w w . j a v a 2s .c om public void success(ReviewList reviewList, Response response) { reviewlist = reviewList.getReviews(); //get the name of each movie in the list and add it to movies_names list List<String> listOfReviews = new ArrayList<>(); for (Review review : reviewlist) { listOfReviews.add(review.getContent()); listOfReviews.add(review.getAuthor()); } mReviewAdapter = new ArrayAdapter<String>(getActivity(), // The current context (this activity) R.layout.list_item_review, // The name of the layout ID. R.id.list_item_review_textview, // The ID of the textview to populate. listOfReviews); ListView listView = (ListView) getView().findViewById(R.id.listview_review); listView.setAdapter(mReviewAdapter); } @Override public void failure(RetrofitError error) { Toast.makeText(getActivity(), "Connection failed", Toast.LENGTH_LONG).show(); } }); }
From source file:com.springsource.greenhouse.events.sessions.EventSessionDetailsActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.event_session_details); final ListView listView = (ListView) findViewById(R.id.event_session_details_menu); String[] menu_items = getResources().getStringArray(R.array.event_session_details_options_array); ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, R.layout.menu_list_item, menu_items); listView.setAdapter(arrayAdapter); listView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { switch (position) { case 0: new UpdateFavoriteTask().execute(); break; case 1: startActivity(new Intent(view.getContext(), EventSessionRatingActivity.class)); break; case 2: startActivity(new Intent(view.getContext(), PostTweetActivity.class)); break; case 3: startActivity(new Intent(view.getContext(), EventSessionTweetsActivity.class)); break; default: break; }/*from ww w . j av a2 s . c om*/ } }); }