Example usage for android.widget ArrayAdapter ArrayAdapter

List of usage examples for android.widget ArrayAdapter ArrayAdapter

Introduction

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

Prototype

public ArrayAdapter(@NonNull Context context, @LayoutRes int resource, @NonNull List<T> objects) 

Source Link

Document

Constructor

Usage

From source file:com.cs411.trackallthethings.MyItems.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.myitems);/*from w w w. j  a  v a2  s.  co  m*/

    // bind the ArrayList of Item Objects to the Array Adapter
    // and then bind the Array Adapter to the ListView
    ListView myItemsFeed = (ListView) findViewById(R.id.myitemsfeed);
    myItemsAdapter = new ArrayAdapter<Item>(this, R.layout.item, myItems);
    myItemsFeed.setAdapter(myItemsAdapter);

    // fire up an AsyncTask to get the user's items
    //show the loading dialog
    loading = ProgressDialog.show(MyItems.this, "", "Getting your items...", true);
    getMyItems task = new getMyItems(MyItems.this,
            "http://www.trackallthethings.com/mobile-api/display_user_inventory_items.php");
    task.execute();

    Button back = (Button) findViewById(R.id.backfrommyitems);
    back.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (myItemsAdapter != null)
                myItemsAdapter.clear();
            finish();
        }
    });
}

From source file:edu.asu.bsse.vtanders.finalproject.MainActivity.java

License:asdf

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    messageEditor = (EditText) findViewById(R.id.message_editor);
    users = new ArrayList<String>();
    //        users.add("Gabe");
    //        users.add("Alex");
    //        users.add("Hillary");
    //        users.add("Vance");
    userListAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, users);

    userList = (ListView) findViewById(R.id.user_list);
    userList.setAdapter(userListAdapter);

    ArrayList<String> channels = new ArrayList<String>();
    channels.add("Android Project");
    channels.add("Webapp Group");
    channels.add("Help");
    channels.add("Misc");
    ArrayAdapter<String> channelListAdapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, channels);

    //corresponds to the commented out stuff in the layout
    //        channelList = (ListView)findViewById(R.id.channel_list);
    //        channelList.setAdapter(channelListAdapter);

    chatHistory = (TextView) findViewById(R.id.chat_history);
    // setup up connection info

    Button sendButton = (Button) findViewById(R.id.button_send);
    sendButton.setOnClickListener(new SendListener(messageEditor));
    //        StringBuilder sb = new StringBuilder();
    //        sb.append("08:40 Gabe: Isn't this chat service really cool?\n")
    //            .append("08:41 Alex: It certainly is. Whoever developed this for us is pretty awesome.\n")
    //            .append("08:41 Hillary: I agree. It's a pretty simplistic approach and it keeps our productivity high!\n")
    //            .append("08:45 Vance: Thanks guys. I think it's pretty cool, too. Get back to work please\n")
    //            .append("08:51 Alex: @Gabe, do you wanna do this PR real quick? I need to get this issue out of code review at some point today\n")
    //            .append("08:53 Gabe: Sure, you wanna take the conversation to the webapp channel though?\n")
    //            .append("08:53 Alex: That's probably best\n")
    //            .append("09:18 Hillary: Anyone else on the cs17 server having connection issues?\n")
    //            .append("09:20 Vance: Yeah I've been using it all day and it's been performing like garbage\n")
    //            .append("11:48 SERVER: _Jeff has joined the channel.\n")
    //            .append("11:48 _Jeff: Hey guys. Lunch is here\n")
    //            .append("11:49 SERVER: _Jeff has left the channel.\n")
    //            .append("11:50 Vance: NICE");
    //        chatHistory.setText(sb.toString());
    chatHistory.setMovementMethod(new ScrollingMovementMethod());
}

From source file:dentex.youtube.downloader.docs.TranslatorsListActivity.java

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

    getWindow().requestFeature(Window.FEATURE_ACTION_BAR);

    // Theme init
    Utils.themeInit(this);

    setContentView(R.layout.activity_translators_list);

    setupActionBar();//w  w  w .j av a  2 s.co  m

    String[] languagesArray = getLanguages(false);
    String[] decodedLanguagesArray = getLanguages(true);

    for (int i = 0; i < languagesArray.length; i++) {
        String[] list = getTranslatorsNames(languagesArray[i]);
        adapter.addSection(decodedLanguagesArray[i],
                new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list));
    }

    setListAdapter(adapter);
}

From source file:com.cs411.trackallthethings.ItemsOnLoan.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.itemsonloan);

    // bind the ArrayList of Item Objects to the Array Adapter
    // and then bind the Array Adapter to the ListView
    ListView itemsOnLoanFeed = (ListView) findViewById(R.id.itemsonloanfeed);
    itemsOnLoanAdapter = new ArrayAdapter<Item>(this, R.layout.item, itemsOnLoan);
    itemsOnLoanFeed.setAdapter(itemsOnLoanAdapter);

    // fire up an AsyncTask to get the user's items
    //show the loading dialog
    loading = ProgressDialog.show(ItemsOnLoan.this, "", "Getting your items on loan...", true);
    getItemsOnLoan task = new getItemsOnLoan(ItemsOnLoan.this,
            "http://www.trackallthethings.com/mobile-api/items_on_loan.php?user_id=" + Main.user_id);
    task.execute();/*  www .  ja  va  2 s .c om*/

    Button back = (Button) findViewById(R.id.backfromloan);
    back.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (itemsOnLoanAdapter != null)
                itemsOnLoanAdapter.clear();
            finish();
        }
    });

}

From source file:net.dahanne.android.google.client.GoogleActivity.java

private void showConnectOption() {
    String[] options = { "Connect" };
    ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
            options);// w  w  w . j ava2 s. c o m
    ListView listView = (ListView) this.findViewById(R.id.google_activity_options_list);
    listView.setAdapter(arrayAdapter);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parentView, View childView, int position, long id) {
            switch (position) {
            case 0:
                displayGoogleAuthorization();
                break;
            default:
                break;
            }
        }
    });
}

From source file:info.xuluan.podcast.SearchActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.search_activity);
    setTitle(getResources().getString(R.string.title_channels));

    mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mStrings);

    setListAdapter(mAdapter);// w  ww.ja  va2  s  .  com
    getListView().setOnCreateContextMenuListener(this);
    mEditText = (EditText) findViewById(R.id.keywords);
    mEditText.addTextChangedListener(this);

    startInit();
    Button next = (Button) findViewById(R.id.ButtonNext);

    next.setEnabled(false);
    next.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            String str = "&start=" + mStart;

            String url = getUrl();
            if (url != null) {
                start_search(url + str);
            }
        }
    });

    ImageButton start = (ImageButton) findViewById(R.id.ButtonStart);
    start.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            InputMethodManager m = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            m.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS);
            m.hideSoftInputFromInputMethod(mEditText.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

            String str = "&start=" + mStart;

            String url = getUrl();
            if (url != null) {
                start_search(url + str);
            }
        }
    });

    TabsHelper.setChannelTabClickListeners(this, R.id.channel_bar_search_button);
}

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

private void showConnectOption() {
    String[] options = { "Connect" };
    ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
            options);/*  w w w.  ja va 2s .  c om*/
    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) {
            switch (position) {
            case 0:
                displayFacebookAuthorization();
                break;
            default:
                break;
            }
        }
    });
}

From source file:net.palacesoft.cngstation.client.loader.CityLoader.java

@Override
protected void onPostExecute(List<String> citiesList) {

    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(stationActivity, simple_spinner_item,
            citiesList);//from  w  ww .  ja v  a2s  .  c o  m
    dataAdapter.setDropDownViewResource(simple_spinner_dropdown_item);
    stationActivity.getCities().setAdapter(dataAdapter);
    progressDialog.dismiss();
}

From source file:ca.psiphon.tunneledwebview.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mListView = (ListView) findViewById(R.id.listView);
    mWebView = (WebView) findViewById(R.id.webView);

    mLogMessages = new ArrayAdapter<String>(this, R.layout.log_message, R.id.logMessageTextView);

    mListView.setAdapter(mLogMessages);//w  w w. j  a v  a  2  s.  c  o m

    mLocalHttpProxyPort = new AtomicInteger(0);

    mPsiphonTunnel = PsiphonTunnel.newPsiphonTunnel(this);
}

From source file:android.support.v7.app.DrawerLayoutActivity.java

@Override
protected void onContentViewSet() {
    super.onContentViewSet();

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawer = (ListView) findViewById(R.id.start_drawer);
    mContent = (TextView) findViewById(R.id.content_text);

    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    // The drawer title must be set in order to announce state changes when
    // accessibility is turned on. This is typically a simple description,
    // e.g. "Navigation".
    mDrawerLayout.setDrawerTitle(GravityCompat.START, getString(R.string.drawer_title));

    mDrawer.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, Shakespeare.TITLES));
    mDrawer.setOnItemClickListener(new DrawerItemClickListener());

    // Find the toolbar in our layout and set it as the support action bar on the activity.
    // This is required to have the drawer slide "over" the toolbar.
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    mToolbar.setTitle(R.string.drawer_title);
    setSupportActionBar(mToolbar);//from   ww w.  j ava 2 s.  c o m

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(false);

    // ActionBarDrawerToggle provides convenient helpers for tying together the
    // prescribed interactions between a top-level sliding drawer and the action bar.
    // Note that, as the Javadocs of ActionBarDrawerToggle constructors say, we are
    // *not* using a constructor that gets a Toolbar since we're setting our toolbar
    // dynamically at runtime. Furthermore, as the drawer is sliding over the toolbar,
    // we are suppressing the morphing animation from hamburger to back arrow by
    // calling super.onDrawerSlide with slideOffset=0.0f. In case your app only has
    // top-level pages and doesn't need back arrow visuals at all, you can set up
    // your activity theme to have attribute named "drawerArrowStyle" that points
    // to an extension of Widget.AppCompat.DrawerArrowToggle that has its "spinBars"
    // attribute set to false.
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open,
            R.string.drawer_close) {
        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            super.onDrawerSlide(drawerView, 0.0f);
        }

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
            super.onDrawerSlide(drawerView, 0.0f);
        }
    };

    mDrawerLayout.addDrawerListener(mDrawerToggle);

    // Configure the background color fill of the system status bar (on supported platform
    // versions) and the toolbar itself. We're using the same color, and android:statusBar
    // from the theme makes the status bar slightly darker.
    final int metalBlueColor = getResources().getColor(R.color.drawer_sample_metal_blue);
    mDrawerLayout.setStatusBarBackgroundColor(metalBlueColor);
    mToolbar.setBackgroundColor(metalBlueColor);

    // Register a pre-draw listener to get the initial width of the DrawerLayout so
    // that we can determine the width of the drawer based on the Material spec at
    // https://www.google.com/design/spec/patterns/navigation-drawer.html#navigation-drawer-specs
    mDrawerLayout.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            // What is the width of the entire DrawerLayout?
            final int drawerLayoutWidth = mDrawerLayout.getWidth();

            // What is the action bar size?
            final Resources.Theme theme = mDrawerLayout.getContext().getTheme();
            final TypedArray a = theme
                    .obtainStyledAttributes(new int[] { android.support.v7.appcompat.R.attr.actionBarSize });
            final int actionBarSize = a.getDimensionPixelSize(0, 0);
            if (a != null) {
                a.recycle();
            }

            // Compute the width of the drawer and set it on the layout params.
            final int idealDrawerWidth = 5 * actionBarSize;
            final int maxDrawerWidth = Math.max(0, drawerLayoutWidth - actionBarSize);
            final int drawerWidth = Math.min(idealDrawerWidth, maxDrawerWidth);

            final DrawerLayout.LayoutParams drawerLp = (DrawerLayout.LayoutParams) mDrawer.getLayoutParams();
            drawerLp.width = drawerWidth;
            mDrawer.setLayoutParams(drawerLp);

            // Remove ourselves as the pre-draw listener since this is a one-time
            // configuration.
            mDrawerLayout.getViewTreeObserver().removeOnPreDrawListener(this);
            return true;
        }
    });
}