private void buildView() { ServiceAcctInfo[] tempList = new ServiceAcctInfo[accountList.size()]; final ServiceAcctInfo[] acctList = accountList.toArray(tempList); AcctInfoAdapter adapter = new AcctInfoAdapter(this, acctList); setListAdapter(adapter); ListView lv = getListView(); lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE); lv.setOnItemClickListener( new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int pos, long id) { acctSelected(acctList[pos]); } }); }
public void setMeatToppingsView() { ListView list = (ListView) findViewById(R.id.meatToppingsView); String[] meat = {"Pepperoni", "Chicken", "Ground Beef", "Anchovies", "Bacon Bits"}; List<String> meatList = Arrays.asList(meat); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_checked, meatList); list.setAdapter(adapter); list.setClickable(true); list.setChoiceMode(list.CHOICE_MODE_MULTIPLE); list.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { CheckedTextView item = (CheckedTextView) view; if (item.isChecked()) { numMeatToppings++; } else { numMeatToppings--; } } }); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { setHasOptionsMenu(true); // Instantiate lists tasks = new ArrayList<>(); tempBookList = new ArrayList<>(); swipe = new SwipeRefreshLayout(getActivity()); // Instantiate listview list = new ListView(getActivity()); // Initiate progressbar for loading pb = new ProgressBar(getActivity()); // Init the progressbar pb.setId(1); // Give pb an id pb.setVisibility(View.INVISIBLE); // Set progressbar visibility // Set details list list.setBackgroundColor(Color.WHITE); list.setMultiChoiceModeListener(multiChoiceHandler); list.setOnItemClickListener(onItemClickHandler); list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); swipe.setOnRefreshListener(refreshListener); try { requestData(BookshelfConstants.CONNECTION_URI); } catch (JSONException e) { e.printStackTrace(); } swipe.addView(list); return swipe; }