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.synchophy.ui.CoverFlowActivity.java

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

    setContentView(R.layout.coverflow);//from  www  .  jav  a  2 s  . co  m

    Spinner browseSpinner = (Spinner) this.findViewById(R.id.browseSpinner);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
            new String[] { "Covers", "Albums", "Artists" });
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    browseSpinner.setAdapter(adapter);

    ActivitySwipeDetector activitySwipeDetector = new ActivitySwipeDetector(this) {
        @Override
        public void onLeftToRightSwipe() {
            CoverFlowActivity.this.finish();
            overridePendingTransition(R.anim.hold, R.anim.push_out_to_right);
        }

        @Override
        public void onBottomToTopSwipe() {
            showPlaylist();
        }

    };

    LinearLayout lowestLayout = (LinearLayout) this.findViewById(R.id.coverflowBack);
    lowestLayout.setOnTouchListener(activitySwipeDetector);

    coverFlow = (CoverFlow) findViewById(R.id.coverflow);
    coverFlow.setSpacing(-25);
    coverFlow.setSelection(4, true);
    coverFlow.setAnimationDuration(1000);
    registerForContextMenu(coverFlow);

    ImageAdapter coverImageAdapter = new ImageAdapter(CoverFlowActivity.this);
    coverFlow.setAdapter(coverImageAdapter);

    refresh();
}

From source file:cc.softwarefactory.lokki.android.fragments.AddContactsFragment.java

private void loadContacts() {
    String[] loadingList = { getResources().getString(R.string.loading) };
    aq.id(R.id.add_contacts_list_view)/* w w  w .j  a  va  2s .  c  o m*/
            .adapter(new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, loadingList));
    new getAllEmailAddressesAsync().execute();
}

From source file:com.axinom.drm.quickstart.activity.SampleChooserActivity.java

private void makeMoviesRequest() {
    JsonArrayRequest request = new JsonArrayRequest(Request.Method.GET, API_CATALOG, null,
            new Response.Listener<JSONArray>() {
                @Override/*from w w  w .jav a 2  s. co m*/
                public void onResponse(JSONArray response) {
                    // Adding video URLs and names to lists from json array response.
                    for (int i = 0; i < response.length(); i++) {
                        try {
                            JSONObject jsonObject = response.getJSONObject(i);
                            mVideoUrls.add(jsonObject.getString("url"));
                            mVideoNames.add(jsonObject.getString("name"));
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                    ArrayAdapter adapter = new ArrayAdapter<String>(getApplicationContext(),
                            android.R.layout.simple_list_item_1, mVideoNames) {
                        @Override
                        public View getView(int position, View convertView, ViewGroup parent) {
                            View view = super.getView(position, convertView, parent);
                            TextView textView = (TextView) view.findViewById(android.R.id.text1);
                            textView.setTextColor(Color.BLACK);
                            return view;
                        }
                    };
                    mListView.setAdapter(adapter);
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.d(TAG, "Movies json was not loaded with error: " + error.getMessage());
                }
            });
    BaseApp.requestQueue.add(request);
}

From source file:edu.csh.coursebrowser.DepartmentActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_departments);
    // Show the Up button in the action bar.
    // getActionBar().setDisplayHomeAsUpEnabled(false);
    this.getActionBar().setHomeButtonEnabled(true);
    final Bundle b = this.getIntent().getExtras();
    map_item = new HashMap<String, Department>();
    map = new ArrayList<String>();
    Bundle args = this.getIntent().getExtras();
    this.setTitle(args.getCharSequence("from"));
    try {/*from  w  ww  .  ja  v a2s .  c o  m*/
        JSONObject jso = new JSONObject(args.get("args").toString());
        JSONArray jsa = new JSONArray(jso.getString("departments"));
        ListView lv = (ListView) this.findViewById(R.id.department_list);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, map);
        for (int i = 0; i < jsa.length(); ++i) {
            String s = jsa.getString(i);
            JSONObject obj = new JSONObject(s);
            Department dept = new Department(obj.getString("title"), obj.getString("id"),
                    obj.getString("code"));
            addItem(dept);
            Log.v("Added", dept.toString());
        }
        lv.setAdapter(adapter);
        lv.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                String s = ((TextView) arg1).getText().toString();
                final Department department = map_item.get(s);
                new AsyncTask<String, String, String>() {
                    ProgressDialog p;

                    protected void onPreExecute() {
                        p = new ProgressDialog(DepartmentActivity.this);
                        p.setTitle("Fetching Info");
                        p.setMessage("Contacting Server...");
                        p.setCancelable(false);
                        p.show();
                    }

                    protected String doInBackground(String... dep) {
                        String params = "action=getCourses&department=" + dep[0] + "&quarter="
                                + b.getString("qCode");
                        Log.v("Params", params);
                        URL url;
                        String back = "";
                        try {
                            url = new URL("http://iota.csh.rit" + ".edu/schedule/js/browseAjax" + ".php");

                            URLConnection conn = url.openConnection();
                            conn.setDoOutput(true);
                            OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());
                            writer.write(params);
                            writer.flush();
                            String line;
                            BufferedReader reader = new BufferedReader(
                                    new InputStreamReader(conn.getInputStream()));

                            while ((line = reader.readLine()) != null) {
                                Log.v("Back:", line);
                                back += line;
                            }
                            writer.close();
                            reader.close();
                        } catch (MalformedURLException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                            return null;
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                            p.dismiss();
                            return null;
                        }
                        return back;
                    }

                    protected void onPostExecute(String s) {
                        if (s == null || s == "") {
                            new AlertError(DepartmentActivity.this, "IO Error!").show();
                            return;
                        }

                        try {
                            JSONObject jso = new JSONObject(s);
                            JSONArray jsa = new JSONArray(jso.getString("courses"));
                        } catch (JSONException e) {
                            e.printStackTrace();
                            new AlertError(DepartmentActivity.this, "Invalid JSON From Server").show();
                            p.dismiss();
                            return;
                        }
                        Intent intent = new Intent(DepartmentActivity.this, CourseActivity.class);
                        intent.putExtra("title", department.title);
                        intent.putExtra("id", department.id);
                        intent.putExtra("code", department.code);
                        intent.putExtra("args", s);
                        startActivity(intent);
                        p.dismiss();
                    }
                }.execute(department.id);
            }

        });

    } catch (JSONException e) {
        // TODO Auto-generated catch block
        new AlertError(this, "Invalid JSON");
        e.printStackTrace();
    }

}

From source file:es.uniovi.imovil.fcrtrainer.highscores.HighscoresFragment.java

private void initializeLevelSpinner() {
    ArrayList<String> levelNames = new ArrayList<String>();

    TypedArray array = getResources().obtainTypedArray(R.array.pref_level_values);

    for (int i = 0; i < array.length(); i++) {
        int defaultId = 0;
        int resourceId = array.getResourceId(i, defaultId);

        String name = getResources().getString(resourceId);
        levelNames.add(name);/*from   w w w.ja v a  2s .  c  o  m*/
    }

    array.recycle();

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item,
            levelNames);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    mLevelSpinner = (Spinner) mRootView.findViewById(R.id.spinner_level);
    mLevelSpinner.setAdapter(adapter);

    mLevelSpinner.setOnItemSelectedListener(this);
}

From source file:nmtysh.android.test.speedtest.SpeedTestActivity.java

/** Called when the activity is first created. */
@Override/*from  w w  w .  j  a  v  a2  s.com*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

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

    urlEdit = (EditText) findViewById(R.id.url_address);
    Button button = (Button) findViewById(R.id.use_http_client);
    button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            runHttpClient();
        }
    });
    button = (Button) findViewById(R.id.use_http_url_connection);
    button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            runHttpURLConnection();
        }
    });

    list = new LinkedList<String>();
    adapter = new ArrayAdapter<String>(this, R.layout.list, list);
    listView.setAdapter(adapter);
}

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  .  j ava 2s  . c o 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:com.jonbanjo.cupsprint.CertificateActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_certificate);
    host = (EditText) findViewById(R.id.cert_host_edit);
    port = (EditText) findViewById(R.id.cert_port_edit);
    certList = (ListView) findViewById(R.id.cert_list);
    importButton = (Button) findViewById(R.id.cert_import);

    Intent intent = getIntent();/* w  ww . ja v  a2 s .  co  m*/
    String ip = intent.getStringExtra("host");
    if (ip != null) {
        host.setText(ip);
    }
    String pt = intent.getStringExtra("port");
    if (pt != null) {
        port.setText(pt);
    }

    trustStore = loadTrustStore();
    if (trustStore == null) {
        return;
    }

    ArrayList<String> certArray;
    try {
        certArray = Collections.list(trustStore.aliases());
    } catch (Exception e) {
        return;
    }

    certListAdaptor = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, certArray);
    certList.setAdapter(certListAdaptor);
    certList.setClickable(true);
    certList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
            displayCert(certListAdaptor.getItem(position));

        }
    });

}

From source file:edu.asu.msse.sgowdru.moviesqldb.SearchMovie.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.search_movie);
    info = new TextView[5];
    //In the info array of TextView type store id of each field
    info[0] = (TextView) findViewById(R.id.autoCompleteTextView);
    info[1] = (TextView) findViewById(R.id.editTitleSearch);
    info[2] = (TextView) findViewById(R.id.editGenreSearch);
    info[3] = (TextView) findViewById(R.id.editYearSearch);
    info[4] = (TextView) findViewById(R.id.editActorsSearch);

    //Ratings field is of type Spinner class with field values (PG, PG-13, R rated)
    dropdown = (Spinner) findViewById(R.id.spinnerSearch);
    adapter = ArrayAdapter.createFromResource(this, R.array.Ratings, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    dropdown.setAdapter(adapter);/*  w  w w.j  a  v a2  s  . co m*/

    btn = (Button) findViewById(R.id.addSearch);

    context = getApplicationContext();
    duration = Toast.LENGTH_LONG;

    db = new MoviesDB(this);
    try {
        crsDB = db.openDB();
    } catch (SQLException e) {
        e.printStackTrace();
    }

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line,
            gen);
    AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.editGenreSearch);
    textView.setAdapter(adapter);
}

From source file:com.example.office365sample.MainActivity.java

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

    // inflate views and set initial state
    btnSendMessage = (Button) findViewById(R.id.button_sendSelectedMessage);
    btnSendMessage.setEnabled(false);// ww w .j a  va2 s  .  com
    listViewMessages = (ListView) findViewById(R.id.listview_Messages);
    listViewMessages.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

    Configuration.setServerBaseUrl(Constants.RESOURCE_ID + Constants.ODATA_ENDPOINT);
    AuthenticationSettings.INSTANCE.setSecretKey(Constants.STORAGE_KEY);

    listViewMessages.setAdapter(
            new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, new String[] { "Loading..." }));

    btnSendMessage.setOnClickListener(new View.OnClickListener() {

        @SuppressWarnings("unchecked")
        @Override
        public void onClick(View v) {
            IMessage selectedMessage;
            int position = listViewMessages.getCheckedItemPosition();
            Log.i(TAG, "Selected Item: " + position);
            try {
                selectedMessage = ((ArrayAdapter<IMessage>) listViewMessages.getAdapter()).getItem(position);
            } catch (ClassCastException e) {
                Log.i(TAG, "Adapter not set properly");
                throw e;
            }

            Log.i(TAG, "Sending message: " + selectedMessage.getSubject() + "\nto: "
                    + selectedMessage.getToRecipients());
            Futures.addCallback(selectedMessage.sendAsync(), new FutureCallback<Void>() {
                @Override
                public void onFailure(Throwable t) {
                    t.printStackTrace();
                }

                @Override
                public void onSuccess(Void result) {
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    readMessages();
                }
            });

        }
    });

    doLogin();
}