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.QuarkLabs.BTCeClient.fragments.OrdersBookFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mPairsSpinner = (Spinner) LayoutInflater.from(getActivity()).inflate(R.layout.spinner, null);
    mPairsSpinner.setAdapter(new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1,
            getResources().getStringArray(R.array.ExchangePairs)));
    //restoring spinner position
    if (savedInstanceState != null) {
        mPairsSpinner.setSelection(savedInstanceState.getInt("position"));
    }/*w  ww.ja  v  a  2  s . c o m*/
    mPairsSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            String selected = parent.getSelectedItem().toString();
            Bundle bundle = new Bundle();
            bundle.putString("pair", selected);
            if (mFragmentOpenedFirstTime) {
                getLoaderManager().initLoader(LOADER_ID, bundle, OrdersBookFragment.this);
                mFragmentOpenedFirstTime = false;
            } else {
                getLoaderManager().restartLoader(LOADER_ID, bundle, OrdersBookFragment.this);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    mAsksAdapter = new OrdersBookAdapter(getActivity());
    mBidsAdapter = new OrdersBookAdapter(getActivity());
}

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

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

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mStartDrawer = (ListView) findViewById(R.id.start_drawer);
    mEndDrawer = findViewById(R.id.end_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));

    mStartDrawer.setAdapter(//  w  w w  . j a v a  2  s  .co m
            new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, Shakespeare.TITLES));
    mStartDrawer.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);

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

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

From source file:github.nisrulz.sampleoptimushttp.MainActivity.java

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

    //Setup Data//  w  w w  .  ja  v  a 2 s  . c  om
    data = new ArrayList<>();
    data.add("POST Request");
    data.add("GET Request");
    data.add("PUT Request");
    data.add("DELETE Request");
    data.add("Cancel All Request");

    progressDialog = new ProgressDialog(this);
    progressDialog.setMessage("Connecting");

    textView_res = (TextView) findViewById(R.id.txt_res);

    //ListView
    lv = (ListView) findViewById(R.id.listView);
    adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, data);
    lv.setAdapter(adapter);

    // Initialize the OptimusHTTP Client
    client = new OptimusHTTP(this);

    // Enable Logs
    client.enableDebugging();

    // Store the references of all the requests made in an arraylist for the purpose of cancelling them later on
    refHttpReqList = new ArrayList<>();

    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            switch (position) {
            case 0: {
                // POST
                // Create a param key value map to post in body of req
                ArrayMap<String, String> params = new ArrayMap<>();
                params.put("email", "abc@abc.com");
                params.put("mobileno", "000000000");
                params.put("Key1", "value1");
                params.put("key2", "value2");

                // Set method
                client.setMethod(OptimusHTTP.METHOD_POST);
                // Set Mode
                client.setMode(OptimusHTTP.MODE_PARALLEL);
                // Set Connect Timeout
                client.setConnectTimeout(10 * 1000); //ms
                // Set Read Timeout
                client.setReadTimeout(10 * 1000); //ms
                // Set Content Type
                client.setContentType(OptimusHTTP.CONTENT_TYPE_JSON);
                // Create a map of header key value pair and set headers to the client
                ArrayMap<String, String> headerMap = new ArrayMap<>();
                headerMap.put("Accept-Encoding", "gzip, deflate");
                headerMap.put("Accept-Language", "en-US");
                headerMap.put("Content-Language", "en-US");
                client.setHeaderMap(headerMap);
                try {
                    // makeRequest() returns the reference of the request made
                    // which can be used later to call the cancelReq() if required
                    // if no request is made the makeRequest() returns null

                    progressDialog.show();
                    req = client.makeRequest(SERVER, params, new OptimusHTTP.ResponseListener() {
                        @Override
                        public void onSuccess(String msg) {
                            progressDialog.dismiss();
                            getInfoFromJson(msg);
                        }

                        @Override
                        public void onFailure(String msg) {
                            progressDialog.dismiss();
                            loadInfo(msg);
                        }
                    });
                    if (req != null) {
                        refHttpReqList.add(req);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
                break;
            case 1: {
                // GET
                ArrayMap<String, String> params = new ArrayMap<>();
                params.put("email", "abc@abc.com");
                params.put("mobileno", "000000000");
                client.setMethod(OptimusHTTP.METHOD_GET);
                client.setMode(OptimusHTTP.MODE_SEQ);

                try {
                    progressDialog.show();
                    req = client.makeRequest(SERVER, params, responseListener);
                    if (req != null) {
                        refHttpReqList.add(req);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
                break;
            case 2: {
                //PUT
                ArrayMap<String, String> params = new ArrayMap<>();
                params.put("email", "abc@abc.com");
                params.put("mobileno", "000000000");
                params.put("Key1", "value3");
                params.put("key2", "value2");
                client.setMethod(OptimusHTTP.METHOD_PUT);
                client.setMode(OptimusHTTP.MODE_SEQ);
                try {
                    progressDialog.show();
                    req = client.makeRequest(SERVER, params, responseListener);
                    if (req != null) {
                        refHttpReqList.add(req);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
                break;
            case 3: {
                // DELETE
                ArrayMap<String, String> params = new ArrayMap<>();
                client.setMethod(OptimusHTTP.METHOD_DELETE);
                client.setMode(OptimusHTTP.MODE_SEQ);
                try {
                    progressDialog.show();
                    req = client.makeRequest(SERVER, params, responseListener);
                    if (req != null) {
                        refHttpReqList.add(req);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
                break;
            case 4: {
                // Cancel All

                if (refHttpReqList.size() > 0) {
                    view.setEnabled(false);
                    for (int i = 0; i < refHttpReqList.size(); i++)
                        client.cancelReq(refHttpReqList.get(i));
                    refHttpReqList.clear();
                    view.setEnabled(true);
                }
            }
                break;
            }
        }
    });
}

From source file:com.moods_final.moods.entertainment.YouTubeAPIDemoActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.topics);/*from  w  w  w  .j  a  va  2s .c o m*/
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

    StrictMode.setThreadPolicy(policy);

    lvTopics = (ListView) findViewById(R.id.topics);

    //AsyncTaskRunner runner = new AsyncTaskRunner();

    //runner.execute();
    try {
        lvTopics.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, this.getTopics()));
    } catch (IOException e) {
        e.printStackTrace();
    }

    lvTopics.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View view, int position, long id) {

            //Take action here.
            Log.e("pressed", ":" + topics.get(position).toString());

            Intent intent = new Intent().putExtra("chId", topid.get(position).toString());
            ;
            intent.setComponent(new ComponentName(getPackageName(),
                    "com.moods_final.moods.entertainment.ChannelListActivity"));
            startActivity(intent);

        }

    });

}

From source file:com.group7.dragonwars.MapSelectActivity.java

@Override
protected final void onStart() {
    super.onStart();

    if (mapInfo.size() == 0) {
        AssetManager assman = getAssets();
        ListView mapList = (ListView) this.findViewById(R.id.mapList);

        try {//from  ww  w  . j av a2s.  c om
            String[] files = assman.list("maps");

            for (int i = 0; i < files.length; ++i) {
                String path = "maps/" + files[i];
                BasicMapInfo info = MapReader.getBasicMapInformation(path, this);
                mapInfo.add(info);
            }

            String[] displayInfo = new String[mapInfo.size()];

            for (Integer i = 0; i < mapInfo.size(); i++) {
                displayInfo[i] = mapInfo.get(i).getDesc();
            }

            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
                    displayInfo);
            mapList.setAdapter(adapter);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.free.underground.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Log.i("mycode", "MainActivity onCreate");
    //loadCategories();

    mTitle = mDrawerTitle = getTitle();/*  w  w w . jav a  2s. c om*/
    mMenuTitles = getResources().getStringArray(R.array.menu_array);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);

    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mMenuTitles));
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
        public void onDrawerClosed(View view) {
            getActionBar().setTitle(mTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (savedInstanceState == null) {
        Log.i("mycode", "MainActivity selectItem");
        selectItem(0);
    }

    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);

    int width = metrics.widthPixels;
    Log.i("mycode", "width " + width);
}

From source file:com.manning.androidhacks.hack028.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);/*from   w  w  w  .  ja v a  2  s  .  co  m*/

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

    LayoutInflater inflator = LayoutInflater.from(this);
    mHeader = inflator.inflate(R.layout.header, mListView, false);
    mGallery = (Gallery) mHeader.findViewById(R.id.listview_header_gallery);
    mGallery.setAdapter(new ImageAdapter(this));

    ListView.LayoutParams params = new ListView.LayoutParams(ListView.LayoutParams.FILL_PARENT,
            ListView.LayoutParams.WRAP_CONTENT);
    mHeader.setLayoutParams(params);
    mListView.addHeaderView(mHeader, null, false);

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item, NUMBERS);
    mListView.setAdapter(adapter);

    mListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mGallery.setSelection(position - 1, true);
        }
    });
}

From source file:com.appunite.socket.Main.java

/** Called when the activity is first created. */
@Override/*from   w ww .  jav a2s .c o m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mConnectButton = findViewById(R.id.connect_button);
    mDisconnectButton = findViewById(R.id.disconnect_button);
    mSendButton = findViewById(R.id.send_button);
    mListView = (ListView) findViewById(android.R.id.list);

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

    mListView.setAdapter(mAdapter);

    mConnectButton.setOnClickListener(this);
    mDisconnectButton.setOnClickListener(this);
    mSendButton.setOnClickListener(this);

    String url = new GetBuilder("http://your_server:1000/socket.io/1/").addParam("campaign", "test")
            .addParam("player", "test").build();
    mSocketIO = new SocketIO(url, this);
}

From source file:com.ProfessorPopTart.alternateouyastore.MainActivity.java

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

    GameList = new ArrayList<String>();
    GameListAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, GameList);
    final ListView myListView = (ListView) findViewById(R.id.appsLBX);
    final TextView myGameName = (TextView) findViewById(R.id.gameName);
    myListView.setAdapter(GameListAdapter);
    myListView.setTextFilterEnabled(true);

    //assign onclick event to getListBTN
    Button myGetListBTN = (Button) findViewById(R.id.getListBTN);
    myGetListBTN.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            populateList();//from   ww  w  .  j  a v a2 s  . co m
        }
    });

    //assign onclick event to downloadGameBTN
    Button myDownloadBTN = (Button) findViewById(R.id.donwloadBTN);
    myDownloadBTN.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            buildDownloadRequest(myGameName.getText().toString());
        }
    });

    //assign onSelected event to appsLBX
    myListView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            String selectedFromList = (myListView.getItemAtPosition(i).toString());
            displayImage(getImgUrl(selectedFromList));
            myGameName.setText(selectedFromList);
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    });
}

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

private void showConnectOption() {
    String[] options = { "Connect" };
    ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
            options);//  w ww. j  a va2  s .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) {
            switch (position) {
            case 0:
                displayTwitterAuthorization();
                break;
            default:
                break;
            }
        }
    });
}