List of usage examples for android.widget ListView setAdapter
@Override public void setAdapter(ListAdapter adapter)
From source file:com.skubit.android.example.SkusFragment.java
public void displaySkus(Context context, ListView view, ArrayList<String> details) throws JSONException { List<Map<String, String>> items = new ArrayList<Map<String, String>>(); for (String detail : details) { Map<String, String> map = new HashMap<String, String>(); JSONObject jo = new JSONObject(detail); map.put("title", jo.getString("title")); map.put("id", jo.getString("productId")); items.add(map);//from w ww. ja v a 2s . com } String[] from = new String[] { "title" }; int[] to = new int[] { android.R.id.text1 }; SimpleAdapter adapter = new SimpleAdapter(context, items, android.R.layout.simple_list_item_1, from, to); view.setAdapter(adapter); }
From source file:com.afrozaar.jazzfestreporting.MainActivity.java
/** * This method renders the ListView explaining what the configurations the * developer of this application has to complete. Typically, these are * static variables defined in {@link Auth} and {@link Constants}. *///from w w w . ja v a2 s.com private void showMissingConfigurations() { List<MissingConfig> missingConfigs = new ArrayList<MissingConfig>(); // Make sure an API key is registered if (Auth.KEY.startsWith("Replace")) { missingConfigs.add(new MissingConfig("API key not configured", "KEY constant in Auth.java must be configured with your Simple API key from the Google API Console")); } // Make sure a playlist ID is registered if (Constants.UPLOAD_PLAYLIST.startsWith("Replace")) { missingConfigs.add(new MissingConfig("Playlist ID not configured", "UPLOAD_PLAYLIST constant in Constants.java must be configured with a Playlist ID to submit to. (The playlist ID typically has a prexix of PL)")); } // Renders a simple_list_item_2, which consists of a title and a body // element ListAdapter adapter = new ArrayAdapter<MissingConfig>(this, android.R.layout.simple_list_item_2, missingConfigs) { @Override public View getView(int position, View convertView, ViewGroup parent) { View row; if (convertView == null) { LayoutInflater inflater = (LayoutInflater) getApplicationContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); row = inflater.inflate(android.R.layout.simple_list_item_2, null); } else { row = convertView; } TextView titleView = (TextView) row.findViewById(android.R.id.text1); TextView bodyView = (TextView) row.findViewById(android.R.id.text2); MissingConfig config = getItem(position); titleView.setText(config.title); bodyView.setText(config.body); return row; } }; // Wire the data adapter up to the view ListView missingConfigList = (ListView) findViewById(R.id.missing_config_list); missingConfigList.setAdapter(adapter); }
From source file:com.example.aitor2.myapplication.DrawerArrowSample.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Fabric.with(this, new Crashlytics()); setContentView(R.layout.home_view);//from w w w . j a v a 2s . c o m final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); final ImageView imageView = (ImageView) findViewById(R.id.drawer_indicator); final Resources resources = getResources(); drawer_adapter adapter = new drawer_adapter(this, icons, titles); ListView lv = (ListView) findViewById(R.id.drawer_listview); lv.setAdapter(adapter); lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { drawer.closeDrawer(START); if (position == 0) { Intent intent = new Intent(DrawerArrowSample.this, DrawerArrowSample.class); startActivity(intent); finish(); } else if (position == 1) { Intent intent = new Intent(DrawerArrowSample.this, misReservas.class); startActivity(intent); finish(); } } }); findViewById(R.id.pink_icon).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(DrawerArrowSample.this, "Clicked pink Floating Action Button", Toast.LENGTH_SHORT) .show(); } }); actionB = (FloatingActionButton) findViewById(R.id.pink_icon); actionB.setStrokeVisible(true); swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.activity_main_swipe_refresh_layout); swipeRefreshLayout.setOnRefreshListener(onRefreshListener); swipeRefreshLayout.setColorSchemeColors(Color.BLACK, Color.GREEN, Color.BLACK, Color.GREEN); drawerArrowDrawable = new DrawerArrowDrawable(resources); drawerArrowDrawable.setStrokeColor(resources.getColor(R.color.light_gray)); imageView.setImageDrawable(drawerArrowDrawable); drawer.setDrawerListener(new DrawerLayout.SimpleDrawerListener() { @Override public void onDrawerSlide(View drawerView, float slideOffset) { offset = slideOffset; // Sometimes slideOffset ends up so close to but not quite 1 or 0. if (slideOffset >= .995) { flipped = true; drawerArrowDrawable.setFlip(flipped); } else if (slideOffset <= .005) { flipped = false; drawerArrowDrawable.setFlip(flipped); } drawerArrowDrawable.setParameter(offset); } }); imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (drawer.isDrawerVisible(START)) { drawer.closeDrawer(START); } else { drawer.openDrawer(START); } } }); final TextView styleButton = (TextView) findViewById(R.id.indicator_style); styleButton.setOnClickListener(new View.OnClickListener() { boolean rounded = false; @Override public void onClick(View v) { styleButton.setText(rounded // ? resources.getString(R.string.rounded) // : resources.getString(R.string.squared)); rounded = !rounded; drawerArrowDrawable = new DrawerArrowDrawable(resources, rounded); drawerArrowDrawable.setParameter(offset); drawerArrowDrawable.setFlip(flipped); drawerArrowDrawable.setStrokeColor(resources.getColor(R.color.light_gray)); imageView.setImageDrawable(drawerArrowDrawable); } }); /////////////////////create expandable listview new expandable().execute(); ////////////////////calendario // Pop up Date picker on pressing the editText }
From source file:com.arcusapp.soundbox.fragment.PlaylistsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_playlists, container, false); ListView listView = (ListView) rootView.findViewById(R.id.playlistsActivityList); listView.setLongClickable(true);// w ww.j av a2 s.c o m listView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int pos, long id) { myAdapter.onPlaylistLongClick(pos); return true; } }); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int pos, long id) { myAdapter.onPlaylistClick(pos); } }); listView.setAdapter(myAdapter); return rootView; }
From source file:com.dedipower.portal.android.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); final ProgressDialog dialog = ProgressDialog.show(this, "DediPortal", "Please wait: loading data....", true);/*w w w. ja v a 2 s .co 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.getLong("date"))); } catch (JSONException e) { Log.e("APIFuncs", e.getMessage()); } } } handler.sendEmptyMessage(0); } }; dataPreload.start(); }
From source file:android.example.com.dictionaryproviderexample.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Get the TextView which will be populated with the Dictionary ContentProvider data. ListView dictListView = (ListView) findViewById(R.id.dictionary_list_view); // Get the ContentResolver which will send a message to the ContentProvider. ContentResolver resolver = getContentResolver(); // Get a Cursor containing all of the rows in the Words table. Cursor cursor = resolver.query(UserDictionary.Words.CONTENT_URI, null, null, null, null); // Set the Adapter to fill the standard two_line_list_item layout with data from the Cursor. SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.two_line_list_item, cursor, COLUMNS_TO_BE_BOUND, LAYOUT_ITEMS_TO_FILL, 0); // Attach the adapter to the ListView. dictListView.setAdapter(adapter); }
From source file:com.cssweb.android.base.BaseActivity.java
private void setAdapter(ListView localListView) { int len = getCustMenus().length; if (Config.mapBitmap != null && Config.mapBitmap.size() > 0) { } else {//from ww w . j a v a 2s. c o m initBitmap(); } adapter = new MenuAdapter(this, len); localListView.setAdapter(adapter); localListView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String menuName = (String) (parent.getItemAtPosition(position)); MenuUtils.toMenu(BaseActivity.this, menuName); openMenu(); } }); }
From source file:com.dat255.ht13.grupp23.activites.MessageActivity.java
public void createAndShowMessageList() { messages = getIntent().getParcelableArrayListExtra("messages"); System.out.print("There is: " + messages.size() + "messages in this marker"); ListView lv = (ListView) findViewById(R.id.list); List<ListViewItem> items = new ArrayList<ListViewItem>(); for (Message msg : messages) { name = msg.getName();/* w w w . jav a 2s . co m*/ text = msg.getText(); date = msg.getDate(); items.add(new ListViewItem() { { ThumbNailResource = 1; Name = name; Title = new SimpleDateFormat("MMMM d 'at' h:mm a").format(date); SubTitle = text; } }); } Collections.reverse(items); adapter = new CustomListViewAdapter(this, items); lv.setAdapter(adapter); // Click event for single list row lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { } }); }
From source file:com.dedipower.portal.android.TicketLanding.java
public void onCreate(Bundle savedInstanceState) { API.SessionID = getIntent().getStringExtra("sessionid"); super.onCreate(savedInstanceState); setContentView(R.layout.ticketlanding); final ListView list = (ListView) findViewById(R.id.TicketList); final ProgressDialog dialog = ProgressDialog.show(this, "DediPortal", "Please wait: loading data....", true);/* w ww. j a v a2s .c om*/ final Handler handler = new Handler() { public void handleMessage(Message msg) { dialog.dismiss(); 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:com.df.app.carCheck.VehicleInfoLayout.java
/** * edit/* ww w . j a va 2s. c o m*/ */ private void showListDialog(int titleId, ArrayAdapter<String> adapter, final Handler handler) { View view1 = ((Activity) getContext()).getLayoutInflater().inflate(R.layout.popup_layout, null); final AlertDialog dialog = new AlertDialog.Builder(getContext()).setView(view1).create(); TableLayout contentArea = (TableLayout) view1.findViewById(R.id.contentArea); final ListView listView = new ListView(view1.getContext()); listView.setAdapter(adapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { handler.sendEmptyMessage(i); dialog.dismiss(); } }); contentArea.addView(listView); setTextView(view1, R.id.title, getResources().getString(titleId)); dialog.show(); }