Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package dindonquifetmeuh.evasion_game.net.dindonquifetmeuh;
- import android.os.Bundle;
- import android.support.annotation.Nullable;
- import android.support.v4.app.Fragment;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.AdapterView;
- import android.widget.ArrayAdapter;
- import android.widget.BaseAdapter;
- import android.widget.ImageView;
- import android.widget.Spinner;
- import android.widget.TextView;
- import java.util.ArrayList;
- /**
- * A simple {@link Fragment} subclass.
- */
- public class Fragment_center extends Fragment implements AdapterView.OnItemSelectedListener {
- public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
- }
- public void onNothingSelected(AdapterView<?> parent) {
- }
- Spinner categorySpinner;
- ArrayList categoryList;
- LayoutInflater inflater;
- public Fragment_center() {
- }
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- View view = inflater.inflate(R.layout.fragment_fragment_center, container, false);
- categoryList = new ArrayList<>();
- categoryList.add(new categoryInfo("Categories", R.drawable.dindon));
- categoryList.add(new categoryInfo("Ressource", R.drawable.dindon));
- categoryList.add(new categoryInfo("Monnais", R.drawable.dindon));
- categoryList.add(new categoryInfo("Crypto Monnais", R.drawable.dindon));
- categoryList.add(new categoryInfo("Destok", R.drawable.dindon));
- categorySpinner = (Spinner) view.findViewById(R.id.category_spinner);
- CustomAdapter adapter = new CustomAdapter(categoryList);
- categorySpinner.setAdapter(adapter);
- return view;
- }
- public class CustomAdapter extends BaseAdapter {
- ArrayList categoryList;
- public CustomAdapter(ArrayList categoryList) {
- this.categoryList = categoryList;
- inflater = getActivity().getLayoutInflater();
- }
- @Override
- public int getCount() {
- return categoryList.size();
- }
- @Override
- public Object getItem(int position) {
- return null;
- }
- @Override
- public long getItemId(int position) {
- return 0;
- }
- @Override
- public View getView(int position, View view, ViewGroup parent) {
- view = inflater.inflate(R.layout.category_info, parent, false);
- TextView categoryName = (TextView) view.findViewById(R.id.categoryName);
- ImageView categoryImage = (ImageView) view.findViewById(R.id.categoryImage);
- categoryName.setText(categoryList.get(position).getName().toString());
- categoryImage.setImageResource(categoryList.get(position).getImage());
- return view;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement