Example usage for android.widget ListView setAdapter

List of usage examples for android.widget ListView setAdapter

Introduction

In this page you can find the example usage for android.widget ListView setAdapter.

Prototype

@Override
public void setAdapter(ListAdapter adapter) 

Source Link

Document

Sets the data behind this ListView.

Usage

From source file:com.example.android.bluetoothchat.LobbyActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Setup the window
    setContentView(R.layout.activity_device_list);

    // Initialize the button to perform device discovery
    ImageButton scanButton = (ImageButton) findViewById(R.id.button_scan);
    scanButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            doDiscovery();// w w w  .j a  v a  2 s.  co  m
            v.setVisibility(View.GONE);
        }
    });

    // Initialize array adapters. One for already paired devices and
    // one for newly discovered devices
    mNewDevicesArrayAdapter = new ArrayAdapter<String>(this, R.layout.device_name);

    // Find and set up the ListView for newly discovered devices
    ListView newDevicesListView = (ListView) findViewById(R.id.new_devices);
    newDevicesListView.setAdapter(mNewDevicesArrayAdapter);
    newDevicesListView.setOnItemClickListener(mDeviceClickListener);

    // Register for broadcasts when a device is discovered
    IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
    this.registerReceiver(mReceiver, filter);

    // Register for broadcasts when discovery has finished
    filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
    this.registerReceiver(mReceiver, filter);

    // Get the local Bluetooth adapter
    mBtAdapter = BluetoothAdapter.getDefaultAdapter();

    if (mBtAdapter == null)
        return;

    ensureDiscoverable();

}

From source file:net.alchemiestick.katana.winehqappdb.SearchView.java

/** Called when the activity is first created. */
@Override/*from   w  w w .  j  a  v a  2s .c o m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    webData = new ArrayList<NameValuePair>();
    setDefaults();

    input = (EditText) findViewById(R.id.searchInput);
    input.setOnEditorActionListener(inputEnter);

    Button s = (Button) findViewById(R.id.searchSubmit);
    s.setOnClickListener(this.searchClick);

    tvlist = new MyArrayAdapter(this);

    ListView lv = (ListView) findViewById(R.id.list);
    lv.setAdapter(tvlist);

    // send the usage count to the usage metrics store
    Metrics mmc = new Metrics(this);
    mmc.execute(mmc.getCall("http://www.alchemiestick.net/store_user.php"));
}

From source file:com.emartynov.android.app.urlsetter.android.ui.fragment.UrlListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (savedInstanceState != null) {
        title = savedInstanceState.getString(TITLE);
        keyIds = savedInstanceState.getInt(KEYS);
        valuesIds = savedInstanceState.getInt(VALUES);
    }//from w w  w  . ja  v a  2s  .co  m

    View view = inflater.inflate(R.layout.list_fragment, container, false);

    ListView list = (ListView) view.findViewById(android.R.id.list);

    String[] services = getResources().getStringArray(keyIds);
    String[] urls = getResources().getStringArray(valuesIds);

    list.setAdapter(new UrlExampleAdapter(services, urls, inflater));

    return view;
}

From source file:com.skubit.iab.fragments.TransactionsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_wallet_transactions, null);

    TextView balanceLabel = (TextView) view.findViewById(R.id.wallet_balance_label);
    balanceLabel.setTypeface(FontManager.CONDENSED_REGULAR);

    TextView availableLabel = (TextView) view.findViewById(R.id.wallet_available_label);
    availableLabel.setTypeface(FontManager.CONDENSED_REGULAR);

    mBalance = (TextView) view.findViewById(R.id.wallet_balance);
    mAvailable = (TextView) view.findViewById(R.id.wallet_available);

    ListView list = (ListView) view.findViewById(R.id.list);
    list.setAdapter(mAdapter);

    list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override//ww  w . ja  va  2s  .c  om
        public void onItemClick(AdapterView<?> adapter, View arg1, int position, long arg3) {
            TransactionDto transactionDto = (TransactionDto) adapter.getItemAtPosition(position);
            ObjectMapper mapper = new ObjectMapper();
            String value;
            try {
                value = mapper.writeValueAsString(transactionDto);
                startActivity(TransactionDetailsActivity.newIntent(value, getActivity().getPackageName()));
                getActivity().overridePendingTransition(R.anim.pull_in_right, R.anim.none);
            } catch (JsonProcessingException e) {
                e.printStackTrace();
            }
        }

    });

    mSwipe = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh);

    mSwipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            refreshBalance();
            getTransactions();
        }
    });

    return view;
}

From source file:com.achep.base.ui.fragments.dialogs.PermissionsDialog.java

@NonNull
@Override/*from  w  w  w.  ja  v  a  2  s  .c  o m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Context context = getActivity();
    assert context != null;

    MaterialDialog md = new MaterialDialog.Builder(context).title(R.string.permissions_dialog_title)
            .items(new CharSequence[] { "", "" }).negativeText(R.string.later).build();

    // Make title more red
    TextView title = md.getTitleView();
    title.setTextColor(title.getCurrentTextColor() & 0xFFFF3333 | 0xFF << 16);

    ListView listView = md.getListView();
    assert listView != null;
    mAdapter = new PermissionAdapter(context, new ArrayList<Permission>());
    listView.setAdapter(mAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            PermissionAdapter adapter = (PermissionAdapter) parent.getAdapter();
            Permission item = adapter.getItem(position);

            try {
                startActivity(item.getIntentSettings());
            } catch (ActivityNotFoundException e) {
                int msg = item.getErrorResource();
                if (msg != 0)
                    ToastUtils.showLong(getActivity(), msg);
            }
        }
    });

    return md;
}

From source file:com.baidao.realm_threadexample.AsyncQueryFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_async_query, container, false);
    rootView.findViewById(R.id.translate_button).setOnClickListener(this);

    ListView listView = (ListView) rootView.findViewById(android.R.id.list);
    dotAdapter = new DotAdapter(getActivity());
    listView.setAdapter(dotAdapter);
    return rootView;
}

From source file:com.example.hpb.kunlun.player.view.DeviceListDialogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.list_device, container, false);
    getDialog().setTitle("Select Active Device");

    ListView listView = (ListView) view.findViewById(android.R.id.list);
    mArrayAdapter = new DeviceListAdapter(getActivity(), 0);
    listView.setAdapter(mArrayAdapter);
    listView.setOnItemClickListener(selectDeviceListener);

    return view;/*  w ww  . java2 s.  c  om*/
}

From source file:com.example.one.ScheduleSlideFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.schedule, container, false);

    ((TextView) rootView.findViewById(R.id.tvDay)).setText("Page # " + pageNumber);

    final List<ScheduleItem> aa = new ArrayList<ScheduleItem>();
    aa.add(new ScheduleItem("12:30", "Lunch", ItemType.Break));
    aa.add(new ScheduleItem("14:00", "Opening and Presentation of the Awards", ItemType.Separator));
    aa.add(new ScheduleItem("14:00", "Opening(Local Organizers)"));
    aa.add(new ScheduleItem("14:05", "Welcome TUM and LMU"));
    aa.add(new ScheduleItem("14:15", "Welcome BMBF and Presentation of the Bernstein Award 2012",
            ItemType.EventWithContent));
    aa.add(new ScheduleItem("14:15",
            "Enormously large title : Welcome BMBF and Presentation of the Bernstein Award 2012Welcome BMBF and Presentation of the Bernstein Award 2012"));
    aa.add(new ScheduleItem(null, "One more separator", ItemType.Separator));
    aa.add(new ScheduleItem("14:25", "Lecture by Bernstein Award Winner"));
    aa.add(new ScheduleItem("15:05", "Presentation of the Braitenberg Award 2012", ItemType.EventWithContent));
    aa.add(new ScheduleItem("15:10", "Lecture by the Braitenberg Award Winner"));
    aa.add(new ScheduleItem("15:50", "Coffee", ItemType.Break));

    final ListView list = (ListView) rootView.findViewById(R.id.list);
    BinderData bindingData = new BinderData(this.getActivity(), aa);
    list.setAdapter(bindingData);

    list.setOnItemClickListener(new OnItemClickListener() {
        @Override/*from ww w  . j  a va2  s  . c o m*/
        public void onItemClick(AdapterView<?> a, View v, int position, long id) {
            if (aa.get(position).getItemType() == ItemType.Separator
                    || aa.get(position).getItemType() == ItemType.Break
                    || aa.get(position).getItemType() == ItemType.EventWithoutContent)
                return;
            Intent intent = new Intent(ScheduleSlideFragment.this.getActivity(), ContentExtended.class);
            intent.putExtra("title", aa.get(position).getTitle());
            intent.putExtra("content", aa.get(position).getContent());
            startActivity(intent);
        }
    });

    ImageButton ibLeft = (ImageButton) rootView.findViewById(R.id.ibLeft);
    if (pageNumber == 0)
        ibLeft.setVisibility(View.INVISIBLE);
    else
        ibLeft.setVisibility(View.VISIBLE);

    ibLeft.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (pager.getCurrentItem() > 0)
                pager.setCurrentItem(pager.getCurrentItem() - 1, true);
        }
    });

    ImageButton ibRight = (ImageButton) rootView.findViewById(R.id.ibRight);
    if (pageNumber + 1 == PAGE_NUM)
        ibRight.setVisibility(View.INVISIBLE);
    else
        ibRight.setVisibility(View.VISIBLE);

    ibRight.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (pager.getCurrentItem() < PAGE_NUM)
                pager.setCurrentItem(pager.getCurrentItem() + 1, true);
        }
    });

    return rootView;
}

From source file:com.example.android.sunshine.app.ui.ForecastFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    List<String> weekForecast = new ArrayList<String>();

    // 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);/* w w w .  j ava 2 s.co  m*/

    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);
            Bundle b = new Bundle();
            b.putString("forecast", forecast);
            Intent intentDetail = new Intent(getActivity(), DetailActivity.class);
            intentDetail.putExtras(b);
            startActivity(intentDetail);
        }
    });

    return rootView;
}

From source file:com.brq.wallet.lt.activity.ActiveTradesFragment.java

@Override
public void onResume() {
    _tradeSessionAdapter = new TradeSessionsAdapter(getActivity(), new ArrayList<TradeSession>());
    ListView list = (ListView) findViewById(R.id.lvRecentTrades);
    list.setAdapter(_tradeSessionAdapter);
    updateUi();//from ww  w.jav  a2s .c o  m
    _ltManager.subscribe(ltSubscriber);
    super.onResume();
}