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:net.olejon.spotcommander.PlaylistsActivity.java

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

    // Allow landscape?
    if (!mTools.allowLandscape())
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    // Intent/*from w w w  . jav a  2  s .  com*/
    final Intent intent = getIntent();

    // Computer
    final long computerId = mTools.getSharedPreferencesLong(
            "WIDGET_" + intent.getStringExtra(WidgetLarge.WIDGET_LARGE_INTENT_EXTRA) + "_COMPUTER_ID");

    final String[] computer = mTools.getComputer(computerId);

    // Layout
    setContentView(R.layout.activity_playlists);

    // Toolbar
    final Toolbar toolbar = (Toolbar) findViewById(R.id.playlists_toolbar);
    toolbar.setNavigationIcon(R.drawable.ic_close_white_24dp);
    toolbar.setTitle(getString(R.string.playlists_title));

    setSupportActionBar(toolbar);

    // Progress bar
    mProgressBar = (ProgressBar) findViewById(R.id.playlists_progressbar);
    mProgressBar.setVisibility(View.VISIBLE);

    // Listview
    mListView = (ListView) findViewById(R.id.playlists_list);

    // Get playlists
    final Cache cache = new DiskBasedCache(getCacheDir(), 0);

    final Network network = new BasicNetwork(new HurlStack());

    final RequestQueue requestQueue = new RequestQueue(cache, network);

    requestQueue.start();

    final JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET,
            computer[0] + "/playlists.php?get_playlists_as_json", null, new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    requestQueue.stop();

                    try {
                        final ArrayList<String> playlistNames = new ArrayList<>();

                        final Iterator<?> iterator = response.keys();

                        while (iterator.hasNext()) {
                            String key = (String) iterator.next();

                            playlistNames.add(key);
                        }

                        Collections.sort(playlistNames, new Comparator<String>() {
                            @Override
                            public int compare(String string1, String string2) {
                                return string1.compareToIgnoreCase(string2);
                            }
                        });

                        for (String playlistName : playlistNames) {
                            mPlaylistUris.add(response.getString(playlistName));
                        }

                        final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(mContext,
                                R.layout.activity_playlists_list_item, playlistNames);

                        mProgressBar.setVisibility(View.GONE);

                        mListView.setAdapter(arrayAdapter);
                        mListView.setVisibility(View.VISIBLE);

                        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                            @Override
                            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                                mTools.remoteControl(computerId, "shuffle_play_uri",
                                        mPlaylistUris.get(position));

                                finish();
                            }
                        });
                    } catch (Exception e) {
                        mProgressBar.setVisibility(View.GONE);

                        final TextView textView = (TextView) findViewById(R.id.playlists_error);
                        textView.setVisibility(View.VISIBLE);
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    requestQueue.stop();

                    mProgressBar.setVisibility(View.GONE);

                    final TextView textView = (TextView) findViewById(R.id.playlists_error);
                    textView.setVisibility(View.VISIBLE);
                }
            }) {
        @Override
        public HashMap<String, String> getHeaders() {
            final HashMap<String, String> hashMap = new HashMap<>();

            if (!computer[1].equals("") && !computer[2].equals(""))
                hashMap.put("Authorization", "Basic "
                        + Base64.encodeToString((computer[1] + ":" + computer[2]).getBytes(), Base64.NO_WRAP));

            return hashMap;
        }
    };

    jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(2500, 0, 0));

    requestQueue.add(jsonObjectRequest);
}

From source file:com.NotifyMe.auth.SignInActivity.java

private Spinner initializeSpinner(int id, String[] values) {
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(SignInActivity.this,
            android.R.layout.simple_spinner_item, values);
    Spinner spinner = (Spinner) findViewById(id);
    spinner.setAdapter(adapter);// ww  w .  j  av  a  2 s  .  c  om
    return spinner;
}

From source file:or.tango.android.activity.PicActivity.java

@Override
protected void findViews() {
    setTitle("");
    setLeftVisible(true);/*from   w  ww.jav  a  2  s  .  c  o m*/
    setRightVisible(true);
    getRightBtn().setOnClickListener(this);
    picImageView = (ImageView) findViewById(R.id.pic_iv);
    progressView = (ProgressView) findViewById(R.id.progressView);
    picImageView.setImageBitmap(BitmapFactory.decodeFile(uploadFile.getAbsolutePath()));

    noMsgView = (View) findViewById(R.id.noMsgLayout);

    //handler=(ImageView)findViewById(R.id.handle);
    sd = (SlidingDrawer) findViewById(R.id.drawer);
    sd.setVisibility(View.INVISIBLE);
    resultLv = (ListView) findViewById(R.id.contentListView);

    adapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.pic_adapter_item, R.id.item_text);

    resultLv.setAdapter(adapter);

    resultLv.setOnItemClickListener(new ItemClickListener());

    Log.i(TAG, "FilePath:" + uploadFile.getAbsolutePath());

    //?ip  ?ip      
    Config.HOST = MyPreferences.getHost(getApplicationContext());

}

From source file:com.capstonecontrol.AccountsActivity.java

/**
 * Sets up the 'connect' screen content.
 *///from   w  w  w . j a v a 2 s . c om
private void setConnectScreenContent() {
    List<String> accounts = getGoogleAccounts();
    if (accounts.size() == 0) {
        // Show a dialog and invoke the "Add Account" activity if requested
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setMessage(R.string.needs_account);
        builder.setPositiveButton(R.string.add_account, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT));
            }
        });
        builder.setNegativeButton(R.string.skip, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        builder.setIcon(android.R.drawable.stat_sys_warning);
        builder.setTitle(R.string.attention);
        builder.show();
    } else {
        final ListView listView = (ListView) findViewById(R.id.select_account);
        listView.setAdapter(new ArrayAdapter<String>(mContext, R.layout.account, accounts));
        listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        listView.setItemChecked(mAccountSelectedPosition, true);

        final Button connectButton = (Button) findViewById(R.id.connect);
        connectButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                CapstoneControlActivity.userChanged = true;
                // Set "connecting" status
                SharedPreferences prefs = Util.getSharedPreferences(mContext);
                prefs.edit().putString(Util.CONNECTION_STATUS, Util.CONNECTING).commit();
                // Get account name
                mAccountSelectedPosition = listView.getCheckedItemPosition();
                TextView account = (TextView) listView.getChildAt(mAccountSelectedPosition);
                // Register
                register((String) account.getText());
                // finish();
                // clear the module list so that a new one will get found
                CapstoneControlActivity.modules.clear();
                // instead of finish() go back to the AccountsActivity for
                // new login.
                CapstoneControlActivity.googleUserName = (String) account.getText();
                Intent myIntent = new Intent(v.getContext(), SplashActivity.class);
                startActivity(myIntent);
                myIntent = new Intent(v.getContext(), CapstoneControlActivity.class);
                startActivity(myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
            }
        });
    }
}

From source file:com.masteriti.manager.AccountsActivity.java

/**
 * Sets up the 'connect' screen content.
 *///www  . j av  a  2 s. c o  m
private void setConnectScreenContent() {
    List<String> accounts = getGoogleAccounts();
    if (accounts.size() == 0) {
        // Show a dialog and invoke the "Add Account" activity if requested
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setMessage(R.string.needs_account);
        builder.setPositiveButton(R.string.add_account, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT));
            }
        });
        builder.setNegativeButton(R.string.skip, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        builder.setIcon(android.R.drawable.stat_sys_warning);
        builder.setTitle(R.string.attention);
        builder.show();
    } else {
        final ListView listView = (ListView) findViewById(R.id.select_account);
        listView.setAdapter(new ArrayAdapter<String>(mContext, R.layout.account, accounts));
        listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        listView.setItemChecked(mAccountSelectedPosition, true);

        final Button connectButton = (Button) findViewById(R.id.connect);
        connectButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // Set "connecting" status
                SharedPreferences prefs = Util.getSharedPreferences(mContext);
                prefs.edit().putString(Util.CONNECTION_STATUS, Util.CONNECTING).commit();
                // Get account name
                mAccountSelectedPosition = listView.getCheckedItemPosition();
                TextView account = (TextView) listView.getChildAt(mAccountSelectedPosition);
                // Register
                register((String) account.getText());
                finish();
            }
        });
    }
}

From source file:com.example.h156252.connected_cars.CarGrid.java

/** Called when the activity is first created. */
@Override/*from w ww.ja v a  2  s  .  c o  m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.content_car_grid);
    try {
        Window window = getWindow();

        // clear FLAG_TRANSLUCENT_STATUS flag:
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

        // add FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag to the window
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

        // finally change the color
        window.setStatusBarColor(Color.rgb(0, 0, 0));
        android.support.v7.app.ActionBar actionBar = getSupportActionBar();
        actionBar.setBackgroundDrawable(new ColorDrawable(Color.rgb(0, 0, 0)));
    } catch (Exception e) {
        // Toast.makeText(getApplicationContext(),"Exception in actionbar  "+e.getLocalizedMessage(),Toast.LENGTH_SHORT).show();
    }
    session = new SessionManagement(this);
    tts = new TextToSpeech(this, this);
    //Toast.makeText(getApplicationContext(),"Entering activity",Toast.LENGTH_SHORT).show();
    Intent intent = getIntent();
    String result = intent.getStringExtra(HomeScreen.EXTRA_MESSAGE);
    //Toast.makeText(getApplicationContext(),"obtaining result: " +result,Toast.LENGTH_SHORT).show();
    ArrayList<String> listdata = new ArrayList<String>();

    try {

        JSONArray jArray = new JSONArray(result);
        if (jArray != null) {
            for (int i = 0; i < jArray.length(); i++) {

                String jstr = jArray.get(i).toString();
                JSONObject jObj = new JSONObject(jstr);
                String id = jObj.getString("id");
                //String phone = jObj.getString("phone");
                String brand = jObj.getString("text");
                String text = jObj.getString("cartext");
                String carno = jObj.getString("carnum");
                String color = jObj.getString("color");
                //String isDone = jObj.getString("isDone");
                String result_combine = "CAR " + i + ":\nCar id : #" + id + "*\n" + "License No.   : " + carno
                        + "\n" + "Color   : " + color + "\n" + "Brand   : " + brand + "\n"
                        + "Text behind car   : " + text;
                String rr = "Success " + result_combine;
                //Toast.makeText(getApplicationContext(),rr,Toast.LENGTH_SHORT).show();
                String own_id = session.getID();
                if (!(id.equals(own_id)))
                    listdata.add(result_combine);
            }
        }
    } catch (Exception e) {
        //Toast.makeText(getApplicationContext(),e.getLocalizedMessage(),Toast.LENGTH_SHORT).show();
    }

    //Toast.makeText(getApplicationContext(),"out of json",Toast.LENGTH_SHORT).show();
    final GridView gridview = (GridView) findViewById(R.id.gridview);
    // final String[] items = new String[] { "Item1", "Item2", "Item3","Item4", "Item5", "Item6", "Item7", "Item8" };

    ArrayAdapter<String> ad = new ArrayAdapter<String>(getApplicationContext(),
            android.R.layout.simple_list_item_1, listdata);
    //Toast.makeText(getApplicationContext(),"setting array adapter",Toast.LENGTH_SHORT).show();
    //gridview.setBackgroundColor(Color.GRAY);

    gridview.setNumColumns(2);
    gridview.setGravity(Gravity.CENTER);
    gridview.setAdapter(ad);
    gridview.setBackgroundColor(Color.GRAY);
    //Toast.makeText(getApplicationContext(),"setting grid view",Toast.LENGTH_SHORT).show();
    gridview.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View v, int position, long arg3) {
            // TODO Auto-generated method stub
            // Toast.makeText(getApplicationContext(), "" + arg2,Toast.LENGTH_SHORT).show();
            //Toast.makeText(getApplicationContext(),"Prompting speech",Toast.LENGTH_SHORT).show();

            try {
                String s = ((TextView) v).getText().toString();

                int start = 0; // '(' position in string
                int end = 0; // ')' position in string
                for (int i = 0; i < s.length(); i++) {
                    if (s.charAt(i) == '#') // Looking for '(' position in string
                        start = i;
                    else if (s.charAt(i) == '*') // Looking for ')' position in  string
                        end = i;
                }
                receiver_id = s.substring(start + 1, end);

                //Toast.makeText(getApplicationContext(), "ID: " + receiver_id, Toast.LENGTH_SHORT).show();
                //promptSpeechInput();

            } catch (Exception e) {
                // Toast.makeText(getApplicationContext(), e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
            }

            //receiver_id = grid_text.substring(grid_text.indexOf("#") + 1, grid_text.indexOf("#"));
            //Toast.makeText(getApplicationContext(),receiver_id,Toast.LENGTH_SHORT).show();

            try {
                promptSpeechInput();
            } catch (Exception e) {
                //Toast.makeText(getApplicationContext(), e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
            }

            try {
                Intent intent_rate = new Intent(getApplicationContext(), RateDriving.class);
                intent_rate.putExtra(EXTRA_MESSAGE, receiver_id);
                startActivity(intent_rate);

            } catch (Exception e) {
                //Toast.makeText(getApplicationContext(), e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
            }

            //new VoiceTask().execute("http://myfirst.au-syd.mybluemix.net/api/Items");
        }
    });

}

From source file:com.ichi2.anki.ModelFieldEditor.java

private void createfieldLabels() {
    ArrayAdapter<String> mFieldLabelAdapter = new ArrayAdapter<>(this, R.layout.model_field_editor_list_item,
            mFieldLabels);/* w  w  w  . j  a  v a  2  s  .com*/
    mFieldLabelView.setAdapter(mFieldLabelAdapter);
    mFieldLabelView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mContextMenu = ModelEditorContextMenu.newInstance(mFieldLabels.get(position), mContextMenuListener);
            showDialogFragment(mContextMenu);
            mCurrentPos = position;
        }
    });
}

From source file:com.cloudtask1.AccountsActivity.java

/**
 * Sets up the 'connect' screen content.
 *///from w  w  w .  ja  v  a2s. c o  m
private void setConnectScreenContent() {
    List<String> accounts = getGoogleAccounts();
    if (accounts.size() == 0) {
        // Show a dialog and invoke the "Add Account" activity if requested
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setMessage(R.string.needs_account);
        builder.setPositiveButton(R.string.add_account, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT));
            }
        });
        builder.setNegativeButton(R.string.skip, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        builder.setIcon(android.R.drawable.stat_sys_warning);
        builder.setTitle(R.string.attention);
        builder.show();
    } else {
        final ListView listView = (ListView) findViewById(R.id.select_account);
        listView.setAdapter(new ArrayAdapter<String>(mContext, R.layout.account, accounts));
        listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        listView.setItemChecked(mAccountSelectedPosition, true);

        final Button connectButton = (Button) findViewById(R.id.connect);
        connectButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // Set "connecting" status
                SharedPreferences prefs = Util.getSharedPreferences(mContext);
                prefs.edit().putString(Util.CONNECTION_STATUS, Util.CONNECTING).commit();
                // Get account name
                mAccountSelectedPosition = listView.getCheckedItemPosition();
                TextView account = (TextView) listView.getChildAt(mAccountSelectedPosition);
                // Register
                register((String) account.getText());
                finish();
            }
        });
    }
}

From source file:nz.ac.wintec.soit.af5.AccountsActivity.java

/**
 * Sets up the 'connect' screen content.
 *//*from  w  ww  . j a va  2 s. c o m*/
private void setConnectScreenContent() {
    List<String> accounts = getGoogleAccounts();
    if (accounts.size() == 0) {
        // Show a dialog and invoke the "Add Account" activity if requested
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setMessage(R.string.needs_account);
        builder.setPositiveButton(R.string.add_account, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                //  startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT));
            }
        });
        builder.setNegativeButton(R.string.skip, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        builder.setIcon(android.R.drawable.stat_sys_warning);
        builder.setTitle(R.string.attention);
        builder.show();
    } else {
        final ListView listView = (ListView) findViewById(R.id.select_account);
        listView.setAdapter(new ArrayAdapter<String>(mContext, R.layout.account, accounts));
        listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        listView.setItemChecked(mAccountSelectedPosition, true);

        final Button connectButton = (Button) findViewById(R.id.connect);
        connectButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // Set "connecting" status
                SharedPreferences prefs = Util.getSharedPreferences(mContext);
                prefs.edit().putString(Util.CONNECTION_STATUS, Util.CONNECTING).commit();
                // Get account name
                mAccountSelectedPosition = listView.getCheckedItemPosition();
                TextView account = (TextView) listView.getChildAt(mAccountSelectedPosition);
                // Register
                register((String) account.getText());
                finish();
            }
        });
    }
}

From source file:com.adarshahd.indianrailinfo.donate.TrainEnquiry.java

private void initControls() {
    mETTrainNumber = (EditText) findViewById(R.id.id_et_trn_nm);
    mACTFrom = (AutoCompleteTextView) findViewById(R.id.id_act_from);
    mACTTo = (AutoCompleteTextView) findViewById(R.id.id_act_to);
    mAdapterStnCodes = new ArrayAdapter<String>(this, R.layout.layout_dropdown_list,
            getResources().getStringArray(R.array.stn_codes));
    mACTFrom.setAdapter(mAdapterStnCodes);
    mACTTo.setAdapter(mAdapterStnCodes);
    mCal = Calendar.getInstance();
    mBtnTrnDtls = (Button) findViewById(R.id.id_btn_details);
    mBtnDate = (Button) findViewById(R.id.id_btn_date);
    mFrameLayout = (FrameLayout) findViewById(R.id.id_fl_trn_info);
    mBtnTrnDtls.setOnClickListener(this);
    mBtnDate.setOnClickListener(this);
    mBtnDate.setText(DateFormat.format("dd MMM yyyy", mCal));
}