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, @IdRes int textViewResourceId,
        @NonNull List<T> objects) 

Source Link

Document

Constructor

Usage

From source file:android.support.test.testapp.DrawerActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.drawer_activity);

    ListAdapter listAdapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.drawer_row,
            R.id.drawer_row_name, DRAWER_CONTENTS);
    final DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    ListView drawerList = (ListView) findViewById(R.id.drawer_list);
    drawerList.setAdapter(listAdapter);/*from  w  ww . ja v  a  2s. c o  m*/

    final TextView textView = (TextView) findViewById(R.id.drawer_text_view);

    drawerList.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            textView.setText("You picked: " + DRAWER_CONTENTS[(int) id]);
            drawerLayout.closeDrawers();
        }
    });

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

    title = getTitle();

    drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer, R.string.nav_drawer_open,
            R.string.nav_drawer_close) {

        /** Called when a drawer has settled in a completely closed state. */
        public void onDrawerClosed(View view) {
            getSupportActionBar().setTitle(title);
        }

        /** Called when a drawer has settled in a completely open state. */
        public void onDrawerOpened(View drawerView) {
            getSupportActionBar().setTitle(title);
        }
    };
    drawerLayout.setDrawerListener(drawerToggle);
}

From source file:com.lingeringsocket.mobflare.Main.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);/*from   w ww .ja  v a  2 s .  c om*/
    emptyMessage = getString(R.string.empty_message);
    ListView flareListView = (ListView) findViewById(R.id.flare_list);
    flareList = new ArrayList<String>();
    arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1,
            flareList);
    flareListView.setAdapter(arrayAdapter);
    flareListView.setOnItemClickListener(new ListView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String flareName = flareList.get((int) id);
            if (flareName.equals(emptyMessage)) {
                onCreateClicked(view);
                return;
            }
            Intent i = new Intent(Main.this, WaitFlare.class);
            i.putExtra(FlareTimer.FLARE_NAME, flareName);
            startActivity(i);
        }
    });

    rpcCoordinator = new RpcCoordinator(this);
    refresh();
}

From source file:com.ibm.sample.travelbuddy.MainActivity.java

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

    searchTxt = (EditText) findViewById(R.id.searchTxt);
    searchBtn = (Button) findViewById(R.id.searchBtn);
    clearBtn = (Button) findViewById(R.id.clearBtn);
    listView = (ListView) findViewById(R.id.searchListView);
    adapter = new ArrayAdapter<String>(this, R.layout.item, R.id.item_name, itemList);
    listView.setAdapter(adapter);//w  w w. j  a va 2  s . co  m

    searchBtn.setOnClickListener(this);
    clearBtn.setOnClickListener(this);

}

From source file:com.javierc.albuquerquenow.TransitMap.java

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

    // Set up the action bar to show a dropdown list.
    actionBar = getActionBar();/*from   w ww.ja  v a2  s  .com*/
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

    final String[] dropdownValues = getResources().getStringArray(R.array.dropdown);

    // Specify a SpinnerAdapter to populate the dropdown list.
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(actionBar.getThemedContext(),
            android.R.layout.simple_spinner_item, android.R.id.text1, dropdownValues);

    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    // Set up the dropdown list navigation in the action bar.
    actionBar.setListNavigationCallbacks(adapter, this);

    googlemap.getUiSettings().setRotateGesturesEnabled(false);

}

From source file:com.hybris.mobile.activity.AccountListActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.account_list);
    setTitle(R.string.account_page_title);

    mLinks = new ArrayList<String>();
    mAdapter = new ArrayAdapter<String>(this, R.layout.row_singleline_with_icon, R.id.textViewSingleLine,
            mLinks);// w ww . ja  v  a 2 s.  com
    setListAdapter(mAdapter);

    getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> a, View v, int position, long l) {
            Intent intent = null;
            if (StringUtils.equals(mLinks.get(position), mLogin)) {
                intent = new Intent(AccountListActivity.this, LoginActivity.class);
                startActivity(intent);
            } else if (StringUtils.equals(mLinks.get(position), mLogout)) {
                logoutUser();
            } else if (StringUtils.equals(mLinks.get(position), mOrderHistory)) {
                intent = new Intent(AccountListActivity.this, OrderListActivity.class);
                startActivity(intent);
            } else if (StringUtils.equals(mLinks.get(position), mAddressBook)) {
                intent = new Intent(AccountListActivity.this, AddressListActivity.class);
                startActivity(intent);
            } else if (StringUtils.equals(mLinks.get(position), mChangePassword)) {
                intent = new Intent(AccountListActivity.this, ChangePasswordActivity.class);
                startActivity(intent);
            } else if (StringUtils.equals(mLinks.get(position), mUpdateProfile)) {
                intent = new Intent(AccountListActivity.this, ProfileDetailActivity.class);
                // TODO
                intent.putExtra("value", JsonUtils.toJson(mProfileDetail));
                startActivity(intent);
            } else if (StringUtils.equals(mLinks.get(position), mPaymentDetails)) {
                intent = new Intent(AccountListActivity.this, PaymentListActivity.class);
                startActivity(intent);
            } else {
                return;
            }
        }
    });

    LinearLayout layoutSwipe = (LinearLayout) findViewById(R.id.layoutSwipe);
    layoutSwipe.setOnTouchListener(new SwipeDetector(new SwipeDetector.OnSwipeListener() {

        @Override
        public void onTopToBottomSwipe() {
            // TODO Auto-generated method stub

        }

        @Override
        public void onRightToLeftSwipe() {
            // TODO Auto-generated method stub

        }

        @Override
        public void onLeftToRightSwipe() {
            Intent intent = new Intent(AccountListActivity.this, SettingsActivity.class);
            startActivity(intent);
        }

        @Override
        public void onBottomToTopSwipe() {
            // TODO Auto-generated method stub

        }
    }));
}

From source file:net.idlesoft.android.apps.github.activities.Branch.java

@Override
public void onCreate(final Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.branch);/*from w  ww .  j  a  va  2s.  c o m*/

    mPrefs = getSharedPreferences(Hubroid.PREFS_NAME, 0);

    mUsername = mPrefs.getString("username", "");
    mPassword = mPrefs.getString("password", "");

    mGapi.authenticate(mUsername, mPassword);

    ((ImageButton) findViewById(R.id.btn_search)).setOnClickListener(new OnClickListener() {
        public void onClick(final View v) {
            startActivity(new Intent(Branch.this, Search.class));
        }
    });

    final Bundle extras = getIntent().getExtras();
    if (extras != null) {
        mRepositoryName = extras.getString("repo_name");
        mRepositoryOwner = extras.getString("repo_owner");
        mBranchName = extras.getString("branch_name");
        mBranchSha = extras.getString("branch_sha");

        final TextView branchName = (TextView) findViewById(R.id.tv_branch_name);
        final TextView branchSha = (TextView) findViewById(R.id.tv_branch_sha);
        final ListView infoList = (ListView) findViewById(R.id.lv_branch_infoList);

        branchName.setText(mBranchName);
        branchSha.setText(mBranchSha);

        infoList.setAdapter(new ArrayAdapter<String>(Branch.this, R.layout.branch_info_item,
                R.id.tv_branchInfoItem_text1, new String[] { "Commit Log", "View Branch's Tree" }));
        infoList.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(final AdapterView<?> parent, final View v, final int position,
                    final long id) {
                if (position == 0) {
                    mIntent = new Intent(Branch.this, CommitsList.class);
                    mIntent.putExtra("repo_owner", mRepositoryOwner);
                    mIntent.putExtra("repo_name", mRepositoryName);
                    mIntent.putExtra("branch_name", mBranchName);
                    startActivity(mIntent);
                } else if (position == 1) {
                    mIntent = new Intent(Branch.this, BranchTree.class);
                    mIntent.putExtra("repo_owner", mRepositoryOwner);
                    mIntent.putExtra("repo_name", mRepositoryName);
                    mIntent.putExtra("branch_name", mBranchName);
                    mIntent.putExtra("branch_sha", mBranchSha);
                    startActivity(mIntent);
                }
            }
        });
    }
}

From source file:app.com.example.android.sunshine_tutorial.ForecastFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    List<String> weekForecast = new ArrayList<String>();

    mForecastAdapter = new ArrayAdapter<String>(getActivity(), R.layout.list_item_forecast,
            R.id.list_item_forecast_textview, weekForecast);

    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast);
    listView.setAdapter(mForecastAdapter);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override/*ww w  .  j a v a2  s . com*/
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String forecast = mForecastAdapter.getItem(position);
            Intent goToDetails = new Intent(getActivity(), DetailActivity.class);
            goToDetails.putExtra(Intent.EXTRA_TEXT, forecast);
            startActivity(goToDetails);
        }
    });

    return rootView;
}

From source file:com.pimp.companionforband.fragments.cloud.SummariesFragment.java

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    summariesLV = (ListView) view.findViewById(R.id.summaries_listview);
    statusTV = (TextView) view.findViewById(R.id.status_textview);
    stringArrayList = new ArrayList<>();
    stringArrayAdapter = new ArrayAdapter<>(getContext(), R.layout.activities_list_item,
            R.id.list_item_textView, stringArrayList);
    summariesLV.setAdapter(stringArrayAdapter);

    RequestQueue queue = Volley.newRequestQueue(getContext());

    JsonObjectRequest profileRequest = new JsonObjectRequest(Request.Method.GET,
            CloudConstants.BASE_URL + CloudConstants.Summaries_URL
                    + "Daily?startTime=2015-01-01T16%3A04%3A49.8578590-07%3A00",
            null, new Response.Listener<JSONObject>() {
                @Override/*  www  . ja va  2 s. c o  m*/
                public void onResponse(JSONObject response) {
                    statusTV.setText("CSV file can be found in CompanionForBand/Summaries\n");

                    Iterator<String> stringIterator = response.keys();
                    while (stringIterator.hasNext()) {
                        try {
                            String key = stringIterator.next();
                            JSONArray jsonArray = response.getJSONArray(key);

                            String path = Environment.getExternalStorageDirectory().getAbsolutePath()
                                    + File.separator + "CompanionForBand" + File.separator + "Summaries";
                            File file = new File(path);
                            file.mkdirs();

                            JsonFlattener parser = new JsonFlattener();
                            CSVWriter writer = new CSVWriter();
                            try {
                                List<LinkedHashMap<String, String>> flatJson = parser
                                        .parseJson(jsonArray.toString());
                                writer.writeAsCSV(flatJson, path + File.separator + key + ".csv");
                            } catch (Exception e) {
                                Log.e("SummariesParseJson", e.toString());
                            }

                            for (int i = 0; i < jsonArray.length(); i++) {
                                JSONObject activity = jsonArray.getJSONObject(i);
                                Iterator<String> iterator = activity.keys();
                                String str = "";
                                while (iterator.hasNext()) {
                                    key = iterator.next();
                                    str = str + UIUtils.splitCamelCase(key) + " : "
                                            + activity.get(key).toString() + "\n";
                                }
                                stringArrayAdapter.add(str);
                            }
                        } catch (Exception e) {
                            Log.e("Summaries", e.toString());
                        }
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Toast.makeText(getActivity(), error.toString(), Toast.LENGTH_LONG).show();
                }
            }) {
        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            HashMap<String, String> headers = new HashMap<>();
            headers.put("Authorization",
                    "Bearer " + MainActivity.sharedPreferences.getString("access_token", "hi"));

            return headers;
        }
    };

    queue.add(profileRequest);
}

From source file:com.pimp.companionforband.fragments.cloud.ActivitiesFragment.java

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    activitiesLV = (ListView) view.findViewById(R.id.activities_listview);
    statusTV = (TextView) view.findViewById(R.id.status_textview);
    stringArrayList = new ArrayList<>();
    stringArrayAdapter = new ArrayAdapter<>(getContext(), R.layout.activities_list_item,
            R.id.list_item_textView, stringArrayList);
    activitiesLV.setAdapter(stringArrayAdapter);

    RequestQueue queue = Volley.newRequestQueue(getContext());

    JsonObjectRequest activitiesRequest = new JsonObjectRequest(Request.Method.GET,
            CloudConstants.BASE_URL + CloudConstants.Activities_URL, null, new Response.Listener<JSONObject>() {
                @Override//w ww  . j  a  va  2  s .  c om
                public void onResponse(JSONObject response) {
                    statusTV.setText("CSV file can be found in CompanionForBand/Activities\n");

                    Iterator<String> stringIterator = response.keys();
                    while (stringIterator.hasNext()) {
                        try {
                            String key = stringIterator.next();
                            JSONArray jsonArray = response.getJSONArray(key);

                            String path = Environment.getExternalStorageDirectory().getAbsolutePath()
                                    + File.separator + "CompanionForBand" + File.separator + "Activities";
                            File file = new File(path);
                            file.mkdirs();

                            JsonFlattener parser = new JsonFlattener();
                            CSVWriter writer = new CSVWriter();
                            try {
                                List<LinkedHashMap<String, String>> flatJson = parser
                                        .parseJson(jsonArray.toString());
                                writer.writeAsCSV(flatJson, path + File.separator + key + ".csv");
                            } catch (Exception e) {
                                Log.e("ActivitiesParseJson", e.toString());
                            }

                            for (int i = 0; i < jsonArray.length(); i++) {
                                JSONObject activity = jsonArray.getJSONObject(i);
                                Iterator<String> iterator = activity.keys();
                                String str = "";
                                while (iterator.hasNext()) {
                                    key = iterator.next();
                                    str = str + UIUtils.splitCamelCase(key) + " : "
                                            + activity.get(key).toString() + "\n";
                                }
                                stringArrayAdapter.add(str);
                            }
                        } catch (Exception e) {
                            Log.e("Activities", e.toString());
                        }
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Toast.makeText(getActivity(), error.toString(), Toast.LENGTH_LONG).show();
                }
            }) {
        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            HashMap<String, String> headers = new HashMap<>();
            headers.put("Authorization",
                    "Bearer " + MainActivity.sharedPreferences.getString("access_token", "hi"));

            return headers;
        }
    };

    queue.add(activitiesRequest);
}

From source file:com.example.joseba.sunshine.app.ForecastFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // Now that we have some dummy forecast data, create an ArrayAdapter.
    // The ArrayAdapter will take data from a source (like our dummy forecast) and
    // use it to populate the ListView it's attached to.
    forecastAdapter = new ArrayAdapter<String>(getActivity(), // The current context (this activity)
            R.layout.list_item_forecast, // The name of the layout ID.
            R.id.list_item_forecast_textview, // The ID of the textview to populate.
            new ArrayList<String>());

    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    // Get a reference to the ListView, and attach this adapter to it.
    ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast);
    listView.setAdapter(forecastAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override//ww w  .  j a v  a  2 s  .  c o m
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String forecast = forecastAdapter.getItem(position);
            Intent intent = new Intent(getActivity(), DetailActivity.class).putExtra(Intent.EXTRA_TEXT,
                    forecast);

            startActivity(intent);

        }
    });
    return rootView;
}