Example usage for android.widget AdapterView getContext

List of usage examples for android.widget AdapterView getContext

Introduction

In this page you can find the example usage for android.widget AdapterView getContext.

Prototype

@ViewDebug.CapturedViewProperty
public final Context getContext() 

Source Link

Document

Returns the context the view is running in, through which it can access the current theme, resources, etc.

Usage

From source file:org.kepennar.android.client.social.facebook.FacebookActivity.java

private void showFacebookOptions() {
    String[] options = { "Disconnect", "Profile", "Home Feed", "Wall Post" };
    ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
            options);//from  w  ww .j  a  v  a  2 s  . c o  m
    ListView listView = (ListView) this.findViewById(R.id.facebook_activity_options_list);
    listView.setAdapter(arrayAdapter);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parentView, View childView, int position, long id) {
            Intent intent;
            switch (position) {
            case 0:
                disconnect();
                showConnectOption();
                break;
            case 1:
                intent = new Intent();
                intent.setClass(parentView.getContext(), FacebookProfileActivity.class);
                startActivity(intent);
                break;
            case 2:
                intent = new Intent();
                intent.setClass(parentView.getContext(), FacebookHomeFeedActivity.class);
                startActivity(intent);
                break;
            case 3:
                intent = new Intent();
                intent.setClass(parentView.getContext(), FacebookWallPostActivity.class);
                startActivity(intent);
                break;
            default:
                break;
            }
        }
    });
}

From source file:org.kepennar.android.client.social.twitter.TwitterActivity.java

private void showTwitterOptions() {
    String[] options = { "Disconnect", "View Profile", "Timeline", "Tweet", "Direct Message" };
    ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
            options);/*from  w  w  w.  ja  v  a  2s . co  m*/
    ListView listView = (ListView) this.findViewById(R.id.twitter_activity_options_list);
    listView.setAdapter(arrayAdapter);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parentView, View childView, int position, long id) {
            Intent intent;
            switch (position) {
            case 0:
                disconnect();
                showConnectOption();
                break;
            case 1:
                intent = new Intent();
                intent.setClass(parentView.getContext(), TwitterProfileActivity.class);
                startActivity(intent);
                break;
            case 2:
                intent = new Intent();
                intent.setClass(parentView.getContext(), TwitterTimelineActivity.class);
                startActivity(intent);
                break;
            case 3:
                intent = new Intent();
                intent.setClass(parentView.getContext(), TwitterTweetActivity.class);
                startActivity(intent);
                break;
            case 4:
                intent = new Intent();
                intent.setClass(parentView.getContext(), TwitterDirectMessageActivity.class);
                startActivity(intent);
                break;
            default:
                break;
            }
        }
    });
}

From source file:TIG055st2014.mailmaster.Activities.ComposeActivity.java

/**
 * onClick for entries in the autocomplete suggestion list.
 *///w  w w  .  j a  va 2s .  co m
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
    Toast.makeText(parent.getContext(),
            getApplicationContext().getResources().getString(R.string.toast_emailsel) + " "
                    + parent.getItemAtPosition(pos).toString(),
            Toast.LENGTH_SHORT).show();
}

From source file:org.bwgz.quotation.activity.HomeActivity.java

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    Log.d(TAG, String.format("onCreateOptionsMenu - menu: %s", menu));

    getMenuInflater().inflate(R.menu.options_menu, menu);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setQueryHint(getString(R.string.search_keyword));

    final ListView drawerView = (ListView) findViewById(R.id.drawer);
    DrawerAdapter adapter = new DrawerAdapter(getResources().getStringArray(R.array.home_drawer), 0);
    drawerView.setAdapter(adapter);/*ww w.  ja  va 2  s  .c  om*/
    drawerView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Log.d(TAG, String.format("drawer - onItemClick - parent: %s  view: %s  position: %d  id: %d",
                    parent, view, position, id));

            drawerLayout.closeDrawer(drawerView);

            if (id == 1) {
                Intent intent = new Intent(parent.getContext(), QuotationsActivity.class);
                intent.putExtra(CategoryActivity.EXTRA_ITEM, QuotationsActivity.QUOTATIONS_ITEM_BOOKMARKS);
                startActivity(intent);
            }
        }
    });

    return true;
}

From source file:tinygsn.gui.android.ActivityViewData.java

public void loadVSList() {
    spinnerVS = (Spinner) findViewById(R.id.spinner_vs);
    List<String> list = new ArrayList<String>();
    for (String s : vsNameList) {
        list.add(s);/*from w ww  .  j  a  va  2s  .  c o  m*/
    }
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, R.layout.spinner_item, list);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinnerVS.setAdapter(dataAdapter);

    spinnerVS.setOnItemSelectedListener(new OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            vsName = parent.getItemAtPosition(pos).toString();
            Toast.makeText(parent.getContext(), "The virtual sensor \"" + vsName + "\" is selected.",
                    Toast.LENGTH_SHORT).show();
            controller.loadListFields(parent.getItemAtPosition(pos).toString());
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            Toast.makeText(context, "Please select a virtual sensor", Toast.LENGTH_SHORT).show();
        }
    });
}

From source file:tinygsn.gui.android.ActivityViewData.java

protected void loadFieldList() {
    spinnerField = (Spinner) findViewById(R.id.spinner_field);
    List<String> list = new ArrayList<String>();
    for (String s : fieldList) {
        list.add(s);//from   w ww. j  ava 2 s .c  om
    }
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, R.layout.spinner_item, list);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinnerField.setAdapter(dataAdapter);

    spinnerField.setOnItemSelectedListener(new OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            fieldName = parent.getItemAtPosition(pos).toString();
            Toast.makeText(parent.getContext(), "The field \"" + fieldName + "\" is selected.",
                    Toast.LENGTH_SHORT).show();
            loadData();
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            Toast.makeText(context, "Please select a field", Toast.LENGTH_SHORT).show();
        }
    });
}

From source file:top.isense.demo.testsensor.DeviceScanActivity.java

private void initial_naviview(Activity act) {
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    //setSupportActionBar(toolbar);

    mListView = (ListView) findViewById(R.id.listView);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override//from  w  ww  .j a  v  a 2  s . co m
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG).setAction("Action", null)
                    .show();
        }
    });

    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);

    if (null != mListView) {
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                //protected void onListItemClick(ListView l, View v, int position, long id) {
                final BluetoothDevice device = mLeDeviceListAdapter.getDevice(position);
                if (device == null)
                    return;
                final Intent intent = new Intent(parent.getContext(), DeviceControlActivity.class);
                intent.putExtra(DeviceControlActivity.EXTRAS_DEVICE_NAME, device.getName());
                intent.putExtra(DeviceControlActivity.EXTRAS_DEVICE_ADDRESS, device.getAddress());
                if (mScanning) {
                    mBluetoothAdapter.stopLeScan(mLeScanCallback);
                    mScanning = false;
                }
                startActivity(intent);
                //}
            }
        });
    }
}

From source file:tw.idv.palatis.danboorugallery.PostListActivity.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Object rawitem = parent.getAdapter().getItem(position);
    if (rawitem.getClass().equals(DrawerListAdapter.DrawerItem.class)) {
        DrawerListAdapter.DrawerItem item = (DrawerListAdapter.DrawerItem) rawitem;
        switch (item.id) {
        case R.id.action_new_host:
            startActivity(new Intent(parent.getContext(), NewHostActivity.class));
            break;
        }//  w w w. j  ava  2 s.  c  om
        mDrawerLayout.closeDrawer(mDrawerLeft);
    } else if (rawitem instanceof Cursor) {
        Cursor cursor = (Cursor) rawitem;
        int host_id = cursor.getInt(HostsTable.INDEX_HOST_DATABASE_ID);
        Host host = SiteSession.getHostById(host_id);
        host.enabled = !host.enabled;
        HostsTable.addOrUpdateHost(host);
    }
}

From source file:org.dharmaseed.android.NavigationActivity.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Log.d("onItemClick", "selected " + position + ", " + id);
    Context ctx = parent.getContext();

    switch (viewMode) {
    case VIEW_MODE_TALKS:
    case VIEW_MODE_TEACHER_TALKS:
    case VIEW_MODE_CENTER_TALKS:
        Intent intent = new Intent(ctx, PlayTalkActivity.class);
        intent.putExtra(TALK_DETAIL_EXTRA, id);
        ctx.startActivity(intent);/*from  ww  w. j ava2s  . c o m*/
        break;

    case VIEW_MODE_TEACHERS:
        setDetailMode(DETAIL_MODE_TEACHER, id);
        break;

    case VIEW_MODE_CENTERS:
        setDetailMode(DETAIL_MODE_CENTER, id);
        break;
    }
}

From source file:com.nbos.phonebook.sync.authenticator.AuthenticatorActivity.java

@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
    String value = parent.getItemAtPosition(pos).toString();
    String[] parts = value.split("\\+");
    String country = parts[0].substring(0, parts[0].indexOf("(")).trim();
    countryCode = parts[1].substring(0, parts[1].indexOf(")")).trim();
    Toast.makeText(parent.getContext(), "Country is " + country + ", code is: " + countryCode,
            Toast.LENGTH_LONG).show();//w  w  w  .  j av a 2  s  . c  o m
}