Example usage for android.widget SimpleAdapter SimpleAdapter

List of usage examples for android.widget SimpleAdapter SimpleAdapter

Introduction

In this page you can find the example usage for android.widget SimpleAdapter SimpleAdapter.

Prototype

public SimpleAdapter(Context context, List<? extends Map<String, ?>> data, @LayoutRes int resource,
        String[] from, @IdRes int[] to) 

Source Link

Document

Constructor

Usage

From source file:com.example.moneymeterexample.ViewExpenseActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_view_expense);
    format = new DecimalFormat();
    format.setMaximumFractionDigits(2);// ww w. j  av  a 2s.  c  om
    format.setMinimumFractionDigits(2);
    view_by = getIntent().getIntExtra("view_by", 0);

    SimpleAdapter sd = new SimpleAdapter(this, list, R.layout.table_row,
            new String[] { "date", "category", "amount", "select" },
            new int[] { R.id.DATE_CELL, R.id.CATEGORY_CELL, R.id.AMOUNT_CELL, R.id.SELECT_ICON });
    total = (TextView) findViewById(R.id.tvValue);

    switch (view_by) {
    case ViewByDateActivity.VIEW_BY_DATE_ID:
        fillListViewByDate();
        break;
    case ViewByCategoryActivity.VIEW_BY_CAT_ID:
        fillListViewByCat();
        break;
    case CustomViewActivity.VIEW_CUSTOM_ID:
        fillListViewCustom();
        break;
    default:
        fillListView();
        break;
    }

    setListAdapter(sd);
}

From source file:com.example.demo_highlights.slidingmenu.fragment.LeftFragment.java

private void initListView() {
    lvAdapter = new SimpleAdapter(getActivity(), getData(), R.layout.behind_list_show,
            new String[] { LIST_TEXT, LIST_IMAGEVIEW },
            new int[] { R.id.textview_behind_title, R.id.imageview_behind_icon }) {
        @Override//from   w w  w  .  ja  v  a  2 s.  co m
        public View getView(int position, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub.
            View view = super.getView(position, convertView, parent);
            if (position == mTag) {
                view.setBackgroundResource(R.drawable.back_behind_list);
                lvTitle.setTag(/*view*/String.valueOf(position));
            } else {
                view.setBackgroundColor(Color.TRANSPARENT);
            }
            return view;
        }
    };
    lvTitle.setAdapter(lvAdapter);
    lvTitle.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            //            NavigationModel navModel = navs.get(position);
            //            mAboveTitle.setText(navModel.getName());
            //            current_page = navModel.getTags();
            if (mTag != position) {
                switch (position) {
                case 0:
                    //               imgQuery.setVisibility(View.GONE);
                    new MyTask().execute(new BaseDao());
                    break;
                case 1:
                    new MyTask().execute(new BaseDao(getActivity(), 1));
                    break;
                case 2:
                    new MyTask().execute(new BaseDao(getActivity(), 2));
                    break;
                case 3:
                    new MyTask().execute(new BaseDao(getActivity(), 3));
                    break;
                }
            }

            if (lvTitle.getTag() != null) {
                if (lvTitle.getTag().equals(String.valueOf(position))) {
                    //                  MainActivity.this.showContent();
                    view.setBackgroundResource(R.drawable.back_behind_list);
                    mTag = position;
                    return;
                } else {
                    /*               ((View) lvTitle.getTag())
                                         .setBackgroundColor(Color.TRANSPARENT);*/
                    mTag = position;
                    lvTitle.setTag(/*view*/String.valueOf(position));
                    view.setBackgroundResource(R.drawable.back_behind_list);
                }
            } else {
                mTag = position;
                lvTitle.setTag(view);
                view.setBackgroundResource(R.drawable.back_behind_list);
            }
            //            imgQuery.setVisibility(View.VISIBLE);

            lvAdapter.notifyDataSetChanged();
        }
    });

}

From source file:org.videolan.vlc.gui.dialogs.SelectChapterDialog.java

private void initChapterList() {
    final MediaPlayer.Chapter[] chapters = mService.getChapters(-1);
    int chaptersCount = chapters != null ? chapters.length : 0;
    if (chaptersCount <= 1) {
        return;//  ww w . j  a  v  a 2s.  c  o m
    }

    ArrayList<Map<String, String>> chapterList = new ArrayList<Map<String, String>>();

    for (int i = 0; i < chaptersCount; i++) {
        String name;
        if (chapters[i].name == null || chapters[i].name.equals(""))
            name = getResources().getString(R.string.chapter) + " " + i;
        else
            name = chapters[i].name;
        chapterList.add(putData(name, Strings.millisToString(chapters[i].timeOffset)));
    }

    String[] from = { "name", "time" };
    int[] to = { R.id.chapter_name, R.id.chapter_time };
    SimpleAdapter adapter = new SimpleAdapter(getActivity(), chapterList, R.layout.dialog_select_chapter_item,
            from, to);

    mChapterList.setAdapter(adapter);
    mChapterList.setSelection(mService.getChapterIdx());
    mChapterList.setItemChecked(mService.getChapterIdx(), true);
    mChapterList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mService.setChapterIdx(position);
            dismiss();
        }
    });
}

From source file:com.acrylicgoat.scrumnotes.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().requestFeature(Window.FEATURE_ACTION_BAR);

    setContentView(R.layout.activity_main);
    sharedPref = getSharedPreferences("com.acrylicgoat.scrumnotes", MODE_PRIVATE);
    if (savedInstanceState != null) {
        currentOwner = savedInstanceState.getString("currentOwner");
    }/*from  w w w .ja  v a 2  s.  co m*/
    if (currentOwner == null || currentOwner.equals("")) {
        currentOwner = sharedPref.getString("currentOwner", "");
    }
    aBar = this.getActionBar();

    today = (EditText) findViewById(R.id.editToday);
    today.setAutoLinkMask(Linkify.ALL);
    today.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            Linkify.addLinks(today, Linkify.ALL);

        }
    });
    devName = (TextView) findViewById(R.id.devName);
    yesterday = (ImageButton) findViewById(R.id.calendarButton);
    yesterday.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

            displayPopup();

        }
    });

    String[] items = getResources().getStringArray(R.array.nav_list);
    setDrawer(items);
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawerList = (ListView) findViewById(R.id.left_drawer);
    SimpleAdapter sAdapter = new SimpleAdapter(this, navTitles, R.layout.nav_drawer, from, to);

    // Set the adapter for the list view
    //drawerList.setAdapter(new ArrayAdapter<String>(this,R.layout.drawer_list_item, navTitles));
    // Set the list's click listener
    drawerList.setOnItemClickListener(new DrawerItemClickListener());

    drawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            drawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
        public void onDrawerClosed(View view) {
            getActionBar().setTitle(getString(R.string.app_name));
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(getString(R.string.app_name));
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };
    drawerToggle.setDrawerIndicatorEnabled(true);
    drawerToggle.syncState();
    drawerLayout.setDrawerListener(drawerToggle);
    aBar.setTitle(getString(R.string.app_name));
    //aBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    aBar.setDisplayHomeAsUpEnabled(true);
    aBar.setHomeButtonEnabled(true);
    drawerList.setAdapter(sAdapter);

}

From source file:com.acrylicgoat.devchat.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().requestFeature(Window.FEATURE_ACTION_BAR);

    setContentView(R.layout.activity_main);

    sharedPref = getSharedPreferences("com.acrylicgoat.devchat", MODE_PRIVATE);
    if (savedInstanceState != null) {
        currentOwner = savedInstanceState.getString("currentOwner");
    }// ww  w .jav a  2 s .c o  m
    if (currentOwner == null || currentOwner.equals("")) {
        currentOwner = sharedPref.getString("currentOwner", "");
    }
    aBar = this.getActionBar();

    today = (EditText) findViewById(R.id.editToday);
    today.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            Linkify.addLinks(today, Linkify.ALL);

        }
    });
    devName = (TextView) findViewById(R.id.devName);
    yesterday = (ImageButton) findViewById(R.id.calendarButton);
    yesterday.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

            displayPopup();

        }
    });

    String[] items = getResources().getStringArray(R.array.nav_list);
    setDrawer(items);
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawerList = (ListView) findViewById(R.id.left_drawer);
    SimpleAdapter sAdapter = new SimpleAdapter(this, navTitles, R.layout.nav_drawer, from, to);

    // Set the adapter for the list view
    //drawerList.setAdapter(new ArrayAdapter<String>(this,R.layout.drawer_list_item, navTitles));
    // Set the list's click listener
    drawerList.setOnItemClickListener(new DrawerItemClickListener());

    drawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            drawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
        public void onDrawerClosed(View view) {
            getActionBar().setTitle(getString(R.string.app_name));
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(getString(R.string.app_name));
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };
    drawerToggle.setDrawerIndicatorEnabled(true);
    drawerToggle.syncState();
    drawerLayout.setDrawerListener(drawerToggle);
    aBar.setTitle(getString(R.string.app_name));
    //aBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    aBar.setDisplayHomeAsUpEnabled(true);
    aBar.setHomeButtonEnabled(true);
    drawerList.setAdapter(sAdapter);

}

From source file:com.example.messaging.GroupTextActivity.java

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

    setContentView(R.layout.activity_gm);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//w  ww . j a v a 2 s.  c o m

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.gm_drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    initUI(getResources().getString(R.string.channels));

    firebaseUser = FacebookLoginActivity.getmAuth().getCurrentUser();

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.gm_fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(view.getContext(), SelectGM_Activity.class);
            startActivity(intent);
        }
    });

    groupMessages = new ArrayList<>();
    gmAdapter = new SimpleAdapter(this, groupMessages, R.layout.grouptext_item,
            new String[] { "names", "message", "key" }, new int[] { R.id.members, R.id.message, R.id.key });
    gm_list = (ListView) findViewById(R.id.all_gms);
    gm_list.setAdapter(gmAdapter);
    gm_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Context context = view.getContext();

            String memberNames = ((TextView) view.findViewById(R.id.members)).getText().toString();
            String lastMessage = ((TextView) view.findViewById(R.id.message)).getText().toString();
            String key = ((TextView) view.findViewById(R.id.key)).getText().toString();

            Intent intent = new Intent(context, MessageActivity.class);
            intent.putExtra("key", key);
            intent.putExtra("names", memberNames);
            context.startActivity(intent);
        }
    });

    fmt = new SimpleDateFormat("MM.dd.yy HH:mm z");

    // Switching a listener to the selected channel.
    initFirebase();
    firebase.child("channels").addChildEventListener(channelListener);

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_gm_view);
    navigationView.setNavigationItemSelectedListener(this);
}

From source file:com.nachtimwald.android.serviceexplorer.ServiceListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_servicelist, container, false);
    ListView lv = (ListView) view.findViewById(R.id.serviceList);

    List<Map<String, String>> serviceData = new ArrayList<>();

    if (getArguments().getBoolean("allServices")) {
        for (PackageInfo packageInfo : getActivity().getPackageManager()
                .getInstalledPackages(PackageManager.GET_SERVICES)) {
            if (packageInfo.services == null) {
                continue;
            }//from   w  ww.  j  av a 2 s. c om
            for (ServiceInfo serviceInfo : packageInfo.services) {
                Map<String, String> datum = new HashMap<>();
                datum.put("name", serviceInfo.name);
                datum.put("package", serviceInfo.packageName);
                datum.put("search", serviceInfo.name.replace(".", " ").replace("$", " "));
                serviceData.add(datum);
            }
        }
    } else {
        ActivityManager activityManager = (ActivityManager) getActivity()
                .getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningServiceInfo> runningServiceInfos = activityManager
                .getRunningServices(Integer.MAX_VALUE);
        for (ActivityManager.RunningServiceInfo info : runningServiceInfos) {
            Map<String, String> datum = new HashMap<>();
            datum.put("name", info.service.getClassName());
            datum.put("package", info.service.getPackageName());
            datum.put("search", info.service.getClassName().replace(".", " ").replace("$", " "));
            serviceData.add(datum);
        }
    }

    mServicesAdapter = new SimpleAdapter(getActivity(), serviceData, android.R.layout.simple_list_item_2,
            new String[] { "name", "package", "search" },
            new int[] { android.R.id.text1, android.R.id.text2, 0 });
    lv.setAdapter(mServicesAdapter);

    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent i = new Intent(getActivity(), DetailActivity.class);
            i.putExtra("name", ((HashMap<String, String>) parent.getItemAtPosition(position)).get("name"));
            i.putExtra("package",
                    ((HashMap<String, String>) parent.getItemAtPosition(position)).get("package"));
            startActivity(i);
        }
    });

    if (savedInstanceState != null) {
        lv.onRestoreInstanceState(savedInstanceState.getParcelable(STATE_LISTPOS));
    }

    return view;
}

From source file:com.nestapi.codelab.demo.MainActivity.java

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

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    mCameras = new ArrayList<Camera>();
    mSmokeCOAlarms = new ArrayList<SmokeCOAlarm>();
    mThermostats = new ArrayList<Thermostat>();

    mThermostatFragment = new ThermostatFragment();
    fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction().add(R.id.container, mThermostatFragment, THERMOSTAT_FRAGMENT_TAG)
            .commit();//from  ww w.  j a v a2 s . c  o  m

    mNestApi = NestAPI.getInstance();
    mToken = Settings.loadAuthToken(this);
    if (mToken != null) {
        authenticate(mToken);
    } else {
        obtainAccessToken();
    }

    mDrawerList = (ListView) findViewById(R.id.left_drawer);

    devicesList = new ArrayList<HashMap<String, String>>();
    adapter = new SimpleAdapter(this, devicesList, android.R.layout.simple_list_item_2,
            new String[] { DEVICE_TEMPLATE, STRUCTURE_TEMPLATE },
            new int[] { android.R.id.text1, android.R.id.text2 });
    mDrawerList.setAdapter(adapter);
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    if (savedInstanceState != null) {
        mThermostat = savedInstanceState.getParcelable(THERMOSTAT_KEY);
        mCamera = savedInstanceState.getParcelable(CAMERA_KEY);
        mSmokeCOAlarm = savedInstanceState.getParcelable(SMOKE_CO_ALARM_KEY);
        mStructure = savedInstanceState.getParcelable(STRUCTURE_KEY);
    }
}

From source file:com.example.android.network.sync.basicsyncadapter.ModelSelectionFragment.java

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

    ArrayList<Map<String, String>> list = buildData();
    String[] from = { "modelName" };
    int[] to = { android.R.id.text1 };

    mAdapter = new SimpleAdapter(getActivity(), list, android.R.layout.simple_expandable_list_item_1, from, to);
    setListAdapter(mAdapter);//from  ww w  . j  a v  a 2 s  .c om

    setListAdapter(mAdapter);
    //setEmptyText(getText(R.string.loading));
    getLoaderManager().initLoader(0, null, this);

}

From source file:net.reichholf.dreamdroid.fragment.MovieListFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    mAdapter = new SimpleAdapter(getActionBarActivity(), mMapList, R.layout.movie_list_item,
            new String[] { Movie.KEY_TITLE, Movie.KEY_SERVICE_NAME, Movie.KEY_FILE_SIZE_READABLE,
                    Movie.KEY_TIME_READABLE, Movie.KEY_LENGTH },
            new int[] { R.id.movie_title, R.id.service_name, R.id.file_size, R.id.event_start,
                    R.id.event_duration });

    setListAdapter(mAdapter);/*w w  w . j  av  a2 s. c  om*/
    getListView().setOnItemLongClickListener(new OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> a, View v, int position, long id) {
            return onListItemLongClick(a, v, position, id);
        }
    });
}