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.springsource.greenhouse.events.sessions.EventSessionsScheduleActivity.java

private void refreshScheduleDays() {
    if (event == null) {
        return;//w w w . j  a v  a2  s  .  co  m
    }

    conferenceDates = new ArrayList<Date>();
    List<String> conferenceDays = new ArrayList<String>();
    Date day = (Date) event.getStartTime().clone();

    while (day.before(event.getEndTime())) {
        conferenceDates.add((Date) day.clone());
        conferenceDays.add(new SimpleDateFormat("EEEE, MMM d").format(day));
        day.setDate(day.getDate() + 1);
    }

    setListAdapter(new ArrayAdapter<String>(this, R.layout.menu_list_item, conferenceDays));
}

From source file:eltharis.wsn.showAllActivity.java

/**
 * Called when the activity is first created.
 *//*from  w ww.ja v a 2  s.  c  o  m*/
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    try {
        String response = executeGET();
        showAll(response);
    } catch (Exception e) {
        Toast toast = Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG); //do debuggowania
        toast.show();
    }
    adapter = new ArrayAdapter<User>(this, android.R.layout.simple_list_item_1, users);
    setListAdapter(adapter);
    ListView lv = getListView();
    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { //nasuchiwanie, czy jaki z uytkownikw by nacinity

        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String username = ((TextView) view).getText().toString();
            Toast.makeText(getBaseContext(), username, Toast.LENGTH_SHORT).show();
            User selected = null;
            for (User u : users) {
                if (u.getUsername().equals(username)) {
                    selected = u;
                    break;
                }
            }
            if (selected != null) {
                Intent intent = new Intent(getBaseContext(), showIDActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.putExtra("id", selected.getId()); //dodajemy jako Extra do intentu. S to tak jakby parametry
                getBaseContext().startActivity(intent); //zaczynamy intent
            }
        }
    });
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_course_browser);
    ListView lv = (ListView) this.findViewById(R.id.schools);
    this.setTitle("Course Browser");

    map_items = new HashMap<String, School>();
    map = new ArrayList<String>();
    this.sp = getPreferences(MODE_WORLD_READABLE);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, map);
    this.setTitle("Course Browser");

    if (!sp.contains("firstRun")) {
        SharedPreferences.Editor e = sp.edit();
        e.putBoolean("firstRun", false);
        e.commit();//w ww.  j a v  a2 s .  co  m
        Intent intent = new Intent(SchoolActivity.this, AboutActivity.class);
        startActivity(intent);
    }

    addItem(new School("01", "Saunder's College of Business"));
    addItem(new School("03", "College of Engineering"));
    addItem(new School("05", "College of Liberal Arts"));
    addItem(new School("06", "Applied Science & Technology"));
    addItem(new School("08", "NTID"));
    addItem(new School("10", "College of Science"));
    addItem(new School("11", "Wellness"));
    addItem(new School("17", "Academic Services"));
    addItem(new School("20", "Imaging Arts and Sciences"));
    addItem(new School("30", "Interdisciplinary Studies"));
    addItem(new School("40", "GCCIS"));
    addItem(new School("50", "Institute for Sustainability"));

    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 School school = map_items.get(s);
            new AsyncTask<String, String, String>() {
                ProgressDialog p;

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

                protected String doInBackground(String... school) {
                    String params = "action=getDepartments&school=" + school[0] + "&quarter=20123";
                    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();
                        return null;
                    }
                    return back;
                }

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

                    try {
                        JSONObject jso = new JSONObject(s);
                        JSONArray jsa = new JSONArray(jso.getString("departments"));
                        ArrayList<Department> depts = new ArrayList<Department>();
                        for (int i = 0; i < jsa.length(); ++i) {
                            JSONObject obj = new JSONObject(jsa.get(i).toString());
                            depts.add(new Department(obj.getString("title"), obj.getString("id"),
                                    obj.getString("code")));
                        }

                    } catch (JSONException e) {
                        e.printStackTrace();
                        new AlertError(SchoolActivity.this, "Invalid JSON From Server").show();
                        p.dismiss();
                        return;
                    }

                    Intent intent = new Intent(SchoolActivity.this, DepartmentActivity.class);
                    intent.putExtra("from", school.deptName);
                    intent.putExtra("args", s);
                    intent.putExtra("qCode", sp.getString("quarter", "20122"));
                    startActivity(intent);
                    p.dismiss();
                }
            }.execute(school.deptNum);
        }

    });

}

From source file:com.allmycode.flags.MyActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);/*from ww  w .  jav a  2  s.c  o  m*/
    targetActivity = (AutoCompleteTextView) findViewById(R.id.editText1);
    ArrayAdapter<String> targetsAdapter = new ArrayAdapter<String>(this, R.layout.list_item, TARGETS_LIST);
    targetActivity.setAdapter(targetsAdapter);
    flags = (AutoCompleteTextView) findViewById(R.id.editText2);
    ArrayAdapter<String> flagsAdapter = new ArrayAdapter<String>(this, R.layout.list_item, FLAGS_LIST_CONCISE);
    flags.setAdapter(flagsAdapter);
    cheatSheet = (EditText) findViewById(R.id.editText3);
    for (String item : FLAGS_LIST) {
        cheatSheet.append(item);
        cheatSheet.append("\n");
    }
    Intent whoCalled = getIntent();
    helloView = ((TextView) findViewById(R.id.textView3));
    helloView.setTextColor(android.graphics.Color.WHITE);
    helloView.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
    helloView.setText("Flags: 0x" + Integer.toHexString(whoCalled.getFlags()));
    if (whoCalled.getExtras() != null) {
        boolean areErrors = whoCalled.getExtras().getBoolean("existErrors", false);
        if (areErrors) {
            helloView.append(" There were errors!");
            helloView.setTextColor(android.graphics.Color.RED);
            helloView.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
        }
    }

    ActivityManager am = (ActivityManager) getSystemService(Service.ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> processes;
    processes = am.getRunningAppProcesses();
    for (ActivityManager.RunningAppProcessInfo info : processes) {
        Log.i("Process:", info.processName);
    }
}

From source file:anomalyDetector.activities.MainFeaturesActivity.java

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

    listView = (ListView) findViewById(R.id.featuresListView);
    startServiceButton = (Button) findViewById(R.id.startServiceButton);
    stopServiceButton = (Button) findViewById(R.id.stopServiceButton);

    //Initialize Drawer Layout components
    drawerMenuEntries = getResources().getStringArray(R.array.drawer_layout_entries);
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawerList = (ListView) findViewById(R.id.left_drawer);

    //Set the adapter for the list view in the drawer
    drawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.row, drawerMenuEntries));
    //Set on item click listener to open the new activity
    //to show graphs.
    drawerItemClickListener = new DrawerItemClickListener();
    drawerList.setOnItemClickListener(drawerItemClickListener);

}

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

private void initializeExerciseSpinner() {
    // La idea de esta funcin es crear los elementos del spinner utilizando
    // los arrays definidos en los recursos

    mExercises = new ArrayList<Exercise>();
    addExerciseModule(mExercises, R.array.codes);
    addExerciseModule(mExercises, R.array.digital_systems);
    addExerciseModule(mExercises, R.array.networks);

    ArrayAdapter<Exercise> adapter = new ArrayAdapter<Exercise>(getActivity(),
            android.R.layout.simple_list_item_1, mExercises);

    mExerciseSpinner = (Spinner) mRootView.findViewById(R.id.spinner_exercise);
    mExerciseSpinner.setAdapter(adapter);

    mExerciseSpinner.setOnItemSelectedListener(this);
}

From source file:com.arantius.tivocommander.MyShows.java

public void doSort(View v) {
    ArrayAdapter<String> orderAdapter = new ArrayAdapter<String>(this, android.R.layout.select_dialog_item,
            mOrderLabels);/*from  w ww.j av a2  s.  c  o m*/
    Builder dialogBuilder = new AlertDialog.Builder(this);
    dialogBuilder.setTitle("Order?");
    dialogBuilder.setAdapter(orderAdapter, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int position) {
            mOrderBy = mOrderValues[position];
            startRequest();
        }
    });
    AlertDialog dialog = dialogBuilder.create();
    dialog.show();
}

From source file:be.geecko.openlauncher.net.SuggestionsTask.java

@Override
protected void onPostExecute(JSONArray jsonResult) {
    super.onPostExecute(jsonResult);
    if (jsonResult == null)
        return;//from w  w  w  .j a v  a 2 s  .co  m

    final int limit = jsonResult.length() > 3 ? 3 : jsonResult.length();
    final String[] results = new String[limit];
    try {
        for (int i = 0; i < limit; i++)
            results[i] = jsonResult.getString(i);
    } catch (JSONException e) {
        e.printStackTrace();
        return;
    }

    ListView resultList = (ListView) LayoutInflater.from(customContent.getContext())
            .inflate(R.layout.suggestion_listview, null);
    resultList.setAdapter(
            new ArrayAdapter<CharSequence>(customContent.getContext(), R.layout.card_list_adapter, results));
    resultList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            CustomContent.search(results[i], view.getContext());
        }
    });

    if (((EditText) customContent.findViewById(R.id.search_bar)).getText().length() > 0)
        customContent.pushCard(resultList, SuggestionsCard.class);
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_course);
    // Show the Up button in the action bar.
    this.getActionBar().setHomeButtonEnabled(false);
    map_item = new HashMap<String, Course>();
    map = new ArrayList<String>();
    Bundle args = this.getIntent().getExtras();
    this.setTitle(args.getCharSequence("title"));
    try {/*from   w w w  .j  a  v  a  2s. c  om*/
        JSONObject jso = new JSONObject(args.get("args").toString());
        JSONArray jsa = new JSONArray(jso.getString("courses"));
        ListView lv = (ListView) this.findViewById(R.id.course_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);
            Course course = new Course(obj.getString("title"), obj.getString("department"),
                    obj.getString("course"), obj.getString("description"), obj.getString("id"));
            addItem(course);
            Log.v("Added", course.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 Course course = map_item.get(s);
                new AsyncTask<String, String, String>() {
                    ProgressDialog p;

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

                    protected String doInBackground(String... dep) {
                        String params = "action=getSections&course=" + course.id;
                        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(CourseActivity.this, "IO Error!").show();
                            return;
                        }
                        try {
                            JSONObject jso = new JSONObject(s);
                            JSONArray jsa = new JSONArray(jso.getString("sections"));
                        } catch (JSONException e) {
                            e.printStackTrace();
                            new AlertError(CourseActivity.this, "Invalid JSON From Server").show();
                            p.dismiss();
                            return;
                        }
                        Intent intent = new Intent(CourseActivity.this, SectionsActivity.class);
                        intent.putExtra("title", course.title);
                        intent.putExtra("id", course.id);
                        intent.putExtra("description", course.description);
                        intent.putExtra("args", s);
                        startActivity(intent);
                        p.dismiss();
                    }
                }.execute(course.id);
            }

        });

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

}

From source file:com.clearcenter.mobile_demo.mdMainActivity.java

public void onCreate(Bundle bundle) {
    Log.i(TAG, "onCreate(" + bundle + ")");
    super.onCreate(bundle);

    setContentView(R.layout.main_activity);

    Log.i(TAG, "loading data from Intent");
    final Intent intent = getIntent();
    Log.i(TAG, "onCreate intent: " + intent);
    final Bundle extras = getIntent().getExtras();
    Log.i(TAG, "onCreate intent extras: " + extras);

    accounts_textview = (TextView) findViewById(R.id.accounts_textview);
    accounts_listview = (ListView) findViewById(R.id.accounts_listview);
    accounts_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1);
    accounts_listview.setAdapter(accounts_adapter);
    accounts_listview.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (position == 0) {
                final Intent intent = new Intent(mdMainActivity.this, mdAuthenticatorActivity.class);
                mdMainActivity.this.startActivity(intent);
                //new Intent(android.provider.Settings.ACTION_ADD_ACCOUNT), 0);
            } else {
                final Intent intent = new Intent(mdMainActivity.this, mdStatusActivity.class);
                intent.putExtra("nickname", mdMainActivity.this.accounts_adapter.getItem(position));
                mdMainActivity.this.startActivity(intent);
            }//from   www.  ja va2 s  .c o m
        }
    });

    accounts_listview.setOnItemLongClickListener(new OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            if (position == 0)
                return false;
            final String nickname = mdMainActivity.this.accounts_adapter.getItem(position);
            mdMainActivity.this.account_to_delete = nickname;
            AlertDialog alert_dialog = new AlertDialog.Builder(mdMainActivity.this).create();
            //alert_dialog.setIcon(R.drawable.ic_launcher);
            alert_dialog.setTitle("Remove System?");
            alert_dialog.setMessage("Are you sure you want to remove the " + nickname + " system account?");
            alert_dialog.setButton(DialogInterface.BUTTON_POSITIVE, "Remove system",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            mdMainActivity.this.onRemoveAccount();
                        }
                    });
            alert_dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                        }
                    });

            alert_dialog.show();
            return true;
        }
    });

    account_manager = AccountManager.get(this);
}