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:at.tugraz.ist.akm.activities.MainActivity.java

private SimpleAdapter newItemDrawerAdapter() {
    mDrawerEntryTitles = getResources().getStringArray(R.array.drawer_string_array);
    mDrawerIcons = getResources().getStringArray(R.array.drawer_icon_array);

    List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
    for (int i = 0; i < mDrawerFragments.length; i++) {
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("icon", Integer.toString(getDrawableIdentifier(mDrawerIcons[i])));
        map.put("title", mDrawerEntryTitles[i]);
        data.add(map);/* w w  w .  ja  va  2 s  .c om*/
    }

    String[] fromMapping = { "icon", "title" };
    int[] toMapping = { R.id.drawer_item_icon, R.id.drawer_item_text };

    return new SimpleAdapter(getBaseContext(), data, R.layout.navigation_drawer_list_entry, fromMapping,
            toMapping);
}

From source file:com.tritop.androsense2.fragments.GpsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mLocationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
    mSensorManager = ((AndrosensApp) getActivity().getApplication()).getSensorManager();
    defaultAccel = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    defaultMag = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    mGpsListAdapter = new SimpleAdapter(getActivity(), itemListGps, R.layout.gpsfragment_sat_item, boundRows,
            boundViews);/*from www.j  ava2  s  . c om*/
    mGlonassListAdapter = new SimpleAdapter(getActivity(), itemListGlonass, R.layout.gpsfragment_sat_item,
            boundRows, boundViews);
    setupViewBinders(mGpsListAdapter, R.drawable.shape_satitem_background_nofix,
            R.drawable.shape_satitem_background_fix);
    setupViewBinders(mGlonassListAdapter, R.drawable.shape_satitem_background_glonass_nofix,
            R.drawable.shape_satitem_background_glonass_fix);
    display = getActivity().getWindowManager().getDefaultDisplay();
    return inflater.inflate(R.layout.gpsfragment_layout, container, false);
}

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

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

    setContentView(R.layout.activity_play);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*  w w  w.  j  a  v  a  2s  .  co m*/

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

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

    firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
    if (firebaseUser != null) {
        updateUI(true);
    }

    channelLabel = (TextView) findViewById(R.id.channelLabel);

    messages = new ArrayList<Map<String, String>>();
    messageAdapter = new SimpleAdapter(this, messages, android.R.layout.simple_list_item_2,
            new String[] { "message", "meta" }, new int[] { android.R.id.text1, android.R.id.text2 });
    messageHistory = (ListView) findViewById(R.id.messageHistory);
    messageHistory.setAdapter(messageAdapter);
    messageText = (EditText) findViewById(R.id.messageText);
    messageText.setOnKeyListener(this);
    fmt = new SimpleDateFormat("MM.dd.yy HH:mm z");

    status = (TextView) findViewById(R.id.status);

    // Switching a listener to the selected channel.
    initFirebase();
    currentChannel = getIntent().getStringExtra("key");
    String names = getIntent().getStringExtra("names");
    firebase.child(CHS + "/" + currentChannel + "/history").addChildEventListener(channelListener);

    Map<String, Object> map = new HashMap<>();
    map.put("names", names);
    firebase.child(CHS + "/" + currentChannel).updateChildren(map);

    channelLabel.setText(names);

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

From source file:org.adaway.ui.ScanAdwareListFragment.java

@Override
public void onLoadFinished(Loader<List<Map<String, String>>> loader, List<Map<String, String>> data) {
    // Set the new data in the adapter.
    // for (String item : data) {
    // mAdapter.add(item);
    // }/*from  w  ww  . j av  a  2 s  .  c o m*/
    Log.d(Constants.TAG, "data: " + data);
    // TODO: real swapping the data to the already defined adapter doesn't work
    // Workaround: recreate adapter!
    // http://stackoverflow.com/questions/2356091/android-add-function-of-arrayadapter-not-working
    // mAdapter = new ArrayAdapter<String>(mActivity, android.R.layout.two_line_list_item,
    // data);

    String[] from = new String[] { "app_name", "package_name" };
    int[] to = new int[] { android.R.id.text1, android.R.id.text2 };
    mAdapter = new SimpleAdapter(getActivity(), data, android.R.layout.two_line_list_item, from, to);

    mAdapter.notifyDataSetChanged();
    setListAdapter(mAdapter);

    // The list should now be shown.
    if (isResumed()) {
        setListShown(true);
    } else {
        setListShownNoAnimation(true);
    }

    // enable Start scanning button
    mStartButton.setEnabled(true);
}

From source file:foundme.uniroma2.it.professore.ReadMessageActivity.java

public static void populateView(String[] result) {
    messageIds = new String[result.length];
    List<Map<String, String>> data = new ArrayList<Map<String, String>>();

    for (int i = 0; i < result.length; i++) {
        Map<String, String> datum = new HashMap<String, String>(2);
        if (i == 0 && result[0].equalsIgnoreCase(Variables_it.NO_MSG)) {
            datum.put("Msg", result[0]);
            datum.put("Num", "");
            data.add(datum);/*from ww  w .  j  a v  a  2  s  . c o  m*/
            messageIds[0] = result[0];
            break;
        } else {
            String[] items = result[i].split(",");
            String ap = "[" + items[0] + "] " + items[1];
            datum.put("Msg", ap);
            datum.put("Num", "Messaggio Visualizzato: " + items[2] + " volte");
            data.add(datum);
            messageIds[i] = items[3];
        }
    }
    //creo l'adapter
    SimpleAdapter adapter = new SimpleAdapter(context, data, android.R.layout.simple_list_item_2,
            new String[] { "Msg", "Num" }, new int[] { android.R.id.text1, android.R.id.text2 });
    //inserisco i dati
    lvMessaggi.setAdapter(adapter);

    swipeMsg.setColorSchemeColors(0xff429874, 0xffffffff, 0xff429874, 0xffffffff);
    swipeMsg.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            swipeMsg.setRefreshing(true);
            (new Handler()).postDelayed(new Runnable() {
                @Override
                public void run() {
                    swipeMsg.setRefreshing(false);
                    try {
                        getMsg(Title, false);
                    } catch (ExecutionException e) {
                        e.printStackTrace();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }, 3000);
        }
    });

    lvMessaggi.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView parent, View view, int position, long id) {
            toEdit = messageIds[position];
            for (int j = 0; j < parent.getChildCount(); j++)
                parent.getChildAt(j).setBackgroundColor(Color.TRANSPARENT);

            view.setBackgroundColor(0xff429874);
            ((Activity) context).startActionMode(modeCallBack);
            viewList = view;
            return true;
        }
    });

    lvMessaggi.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView absListView, int i) {

        }

        @Override
        public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount,
                int totalItemCount) {
            if (firstVisibleItem == 0)
                swipeMsg.setEnabled(true);
            else
                swipeMsg.setEnabled(false);
        }
    });
}

From source file:org.sufficientlysecure.keychain.ui.ImportKeysListFragment.java

@Override
public void onLoadFinished(Loader<List<Map<String, String>>> loader, List<Map<String, String>> data) {
    // Set the new data in the adapter.
    // for (String item : data) {
    // mAdapter.add(item);
    // }// w w  w  .  j a va  2  s  .  c  o  m
    Log.d(Constants.TAG, "data: " + data);
    // TODO: real swapping the data to the already defined adapter doesn't work
    // Workaround: recreate adapter!
    // http://stackoverflow.com/questions/2356091/android-add-function-of-arrayadapter-not-working
    // mAdapter = new ArrayAdapter<String>(mActivity, android.R.layout.two_line_list_item,
    // data);

    String[] from = new String[] { ImportKeysListLoader.MAP_ATTR_USER_ID,
            ImportKeysListLoader.MAP_ATTR_FINGERPINT };
    int[] to = new int[] { android.R.id.text1, android.R.id.text2 };
    mAdapter = new SimpleAdapter(getActivity(), data, android.R.layout.two_line_list_item, from, to);

    mAdapter.notifyDataSetChanged();
    setListAdapter(mAdapter);

    // The list should now be shown.
    if (isResumed()) {
        setListShown(true);
    } else {
        setListShownNoAnimation(true);
    }
}

From source file:de.nico.asura.Main.java

private void setList() {
    ListView list = (ListView) findViewById(R.id.listView_main);
    ListAdapter adapter = new SimpleAdapter(this, downloadList, android.R.layout.simple_list_item_1,
            new String[] { TAG_NAME }, new int[] { android.R.id.text1 });
    list.setAdapter(adapter);/*  w ww  . j  av a 2 s  . c  o m*/

    // Do nothing when there is no Internet
    if (!(Utils.isNetworkAvailable(this))) {
        return;
    }
    // React when user click on item in the list
    list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View v, int pos, long id) {

            Uri downloadUri = Uri.parse(downloadList.get(pos).get(TAG_URL));
            String title = downloadList.get(pos).get(TAG_NAME);
            file = new File(Environment.getExternalStorageDirectory() + "/" + localLoc + "/"
                    + downloadList.get(pos).get(TAG_FILENAME) + ".pdf");
            Uri dest = Uri.fromFile(file);

            if (file.exists()) {
                Intent pdfIntent = new Intent(Intent.ACTION_VIEW);
                pdfIntent.setDataAndType(dest, "application/pdf");
                pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

                try {
                    startActivity(pdfIntent);
                } catch (ActivityNotFoundException e) {
                    Utils.makeLongToast(Main.this, noPDF);
                    Log.e("ActivityNotFoundException", e.toString());
                }
                return;
            }

            // Download PDF
            Request request = new Request(downloadUri);
            request.setTitle(title).setDestinationUri(dest);
            downloadID = downloadManager.enqueue(request);
        }

    });

}

From source file:it.geosolutions.android.map.fragment.GetFeatureInfoFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onViewCreated(view, savedInstanceState);

    ListView list = (ListView) getActivity().findViewById(android.R.id.list);
    Bundle b = getArguments().getBundle("data");
    if (b == null) {
        return;//TODO notify problem
    }//from  w w  w  .  j  av a  2 s  . c  o  m
    String[] from = { "name", "value" };
    int[] to = { R.id.attribute_name, R.id.attribute_value };
    Set<String> layerNameSet = b.keySet();
    for (String layerName : layerNameSet) {

        // Bundle layerBundle = b.getBundle(layerName);
        ArrayList<Bundle> layerBundleList = b.getParcelableArrayList(layerName);
        if (layerBundleList != null) {
            //if some data from the current section
            int featureListSize = layerBundleList.size();
            if (featureListSize != 0) {

                FeatureSectionAdapter fsa = new FeatureSectionAdapter();

                //create a section for every feature
                for (Bundle feature : layerBundleList) {

                    //Crete an array do display a list of strings...
                    //TODO improve this with a table

                    ArrayList<Map<String, String>> attributeList = new ArrayList<Map<String, String>>();
                    for (String attributeName : feature.keySet()) {
                        HashMap<String, String> attribute = new HashMap<String, String>();
                        attribute.put("name", attributeName);
                        attribute.put("value", feature.getString(attributeName));
                        attributeList.add(attribute);
                    }

                    //tableLayout.addView(adapter.getView(i, null, tableLayout))
                    Adapter adapter = new SimpleAdapter(view.getContext(), attributeList,
                            R.layout.feature_info_attribute_row, from, to);
                    //new ArrayAdapter<String>(view.getContext(), R.layout.feature_info_header,attributes)
                    fsa.addSection("", adapter);

                }
                ;

                layerSection.addSection(layerName, fsa);

            }
        }
    }
    // TODO init adapter with headers and data
    // 
    list.setAdapter(layerSection);

}

From source file:fr.eoit.activity.fragment.blueprint.RequiredSkillInventionFragment.java

@Override
public void onLoadFinished(Cursor cursor) {
    if (DbUtil.hasAtLeastOneRow(cursor)) {
        short encryptionSkillLevel = -1;
        int encryptionSkillId = -1;
        short datacore1SkillLevel = -1;
        short datacore2SkillLevel = -1;

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

        boolean datacore1SkillSet = false;

        while (!cursor.isAfterLast()) {
            Map<String, Object> dataLine = new HashMap<String, Object>();

            int skillId = cursor.getInt(cursor.getColumnIndexOrThrow(InventionMapping.COLUMN_NAME_SKILL_ID));
            String skillName = cursor.getString(cursor.getColumnIndexOrThrow(Item.COLUMN_NAME_NAME));
            int skillLevel = 1;

            short userSkillLevel = Skills.getSkill(skillId);
            if (Skills.isEncryptionSkill(skillId)) {
                encryptionSkillLevel = userSkillLevel;
                encryptionSkillId = skillId;
            } else {
                if (datacore1SkillSet) {
                    datacore2SkillLevel = userSkillLevel;
                } else {
                    datacore1SkillLevel = userSkillLevel;
                    datacore1SkillSet = true;
                }//from   www  .  j  av  a 2 s.  c  o  m
            }

            boolean learnt = userSkillLevel >= skillLevel;

            dataLine.put(InventionMapping.COLUMN_NAME_LEARNT, learnt);
            dataLine.put(Item.COLUMN_NAME_NAME, skillName);
            dataLine.put(InventionMapping.COLUMN_NAME_SKILL_LEVEL, userSkillLevel);
            data.add(dataLine);

            cursor.moveToNext();
        }

        SimpleAdapter adapter = new SimpleAdapter(getActivity(), data, R.layout.required_skills_row, FROM, TO);

        adapter.setViewBinder(new RequiredSkillsViewBinder());
        ListView listView = (ListView) getView().findViewById(R.id.REQUIRED_SKILLS_LIST);
        listView.setAdapter(adapter);
        int count = cursor.getCount();
        int width = count * ((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 26,
                getResources().getDisplayMetrics()));
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                width);
        listView.setLayoutParams(lp);

        if (fragmentReference != null && fragmentReference.get() != null) {
            fragmentReference.get().updateInventionChances(encryptionSkillLevel, datacore1SkillLevel,
                    datacore2SkillLevel);
            fragmentReference.get().setEncryptionSkillId(encryptionSkillId);
        }
    }
}