Created
March 24, 2015 15:49
-
-
Save chrisyeung1121/64cfce11b4af8a1ef3c2 to your computer and use it in GitHub Desktop.
Android: Add String Array to ArrayAdapter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Created in CarsFragment.java | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
Bundle savedInstanceState) { | |
// Inflate the layout for this fragment | |
View rootView = inflater.inflate(R.layout.fragment_cars, container, false); | |
String[] dummyCarData = { | |
"BMW 1", | |
"BMW 2", | |
"BMW 3", | |
"BMW 4", | |
"BMW 5" | |
}; | |
List<String> carArray = Arrays.asList(dummyCarData); | |
ArrayAdapter<String> carListAdapter = new ArrayAdapter<String>( | |
getActivity(), | |
R.layout.list_item_car, | |
R.id.list_item_car_textView, | |
carArray); | |
ListView listView = (ListView) rootView.findViewById(R.id.listView_cars); | |
listView.setAdapter(carListAdapter); | |
return rootView; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment