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.alladin.rmbt.android.views.ResultQoSDetailView.java

@SuppressWarnings("unchecked")
@Override//from w ww  . j av  a  2s .  com
public void taskEnded(JSONArray result) {
    System.out.println("ResultQoSDetail taskEnded");
    this.testResult = result;

    if (resultFetchEndTaskListener != null) {
        resultFetchEndTaskListener.taskEnded(result);
    }

    ProgressBar resultProgressBar = (ProgressBar) view.findViewById(R.id.progress_bar);
    TextView resultTextView = (TextView) view.findViewById(R.id.info_text);

    try {
        results = new QoSServerResultCollection(result);

        View successList = view.findViewById(R.id.qos_success_list);

        List<HashMap<String, String>> itemList = new ArrayList<HashMap<String, String>>();
        int index = 0;
        for (QoSTestResultEnum type : QoSTestResultEnum.values()) {
            if (results.getQoSStatistics().getTestCounter(type) > 0) {
                HashMap<String, String> listItem = new HashMap<String, String>();
                listItem.put("name", ConfigHelper.getCachedQoSNameByTestType(type, activity));
                listItem.put("type_name", type.toString());
                listItem.put("index", String.valueOf(index++));
                itemList.add(listItem);
            }
        }

        ListAdapter valueList = new SimpleAdapter(activity, itemList, R.layout.qos_category_list_item,
                new String[] { "name" }, new int[] { R.id.name });

        resultProgressBar.setVisibility(View.GONE);

        if (valueList.getCount() > 0) {

            //in case the view will change again:
            if (ListView.class.isAssignableFrom(successList.getClass())) {
                ((ListView) successList).setAdapter(valueList);
                ((ListView) successList).setOnItemClickListener(this);
            } else {
                ViewGroup vgList = (ViewGroup) successList;
                for (int i = 0; i < valueList.getCount(); i++) {
                    View v = valueList.getView(i, null, null);

                    QoSTestResultEnum key = QoSTestResultEnum
                            .valueOf(((HashMap<String, String>) valueList.getItem(i)).get("type_name"));
                    if (results.getQoSStatistics().getFailureCounter(key) > 0) {
                        ImageView img = (ImageView) v.findViewById(R.id.status);
                        img.setImageResource(R.drawable.traffic_lights_red);
                    }

                    TextView status = (TextView) v.findViewById(R.id.qos_type_status);
                    status.setText((results.getQoSStatistics().getTestCounter(key)
                            - results.getQoSStatistics().getFailedTestsCounter(key)) + "/"
                            + results.getQoSStatistics().getTestCounter(key));

                    v.setOnClickListener(this);
                    v.setTag(valueList.getItem(i));
                    vgList.addView(v);
                }
            }

            successList.invalidate();

            resultTextView.setVisibility(View.GONE);
            successList.setVisibility(View.VISIBLE);
        } else {
            resultTextView.setText(R.string.result_qos_error_no_data_available);
        }

    } catch (Throwable t) {
        resultTextView.setText(R.string.result_qos_error_no_data_available);
        resultProgressBar.setVisibility(View.GONE);
        t.printStackTrace();
    }
}

From source file:org.sigimera.app.android.CrisesListFragment.java

private void showCrises() {
    if (getActivity() != null) {
        ArrayList<HashMap<String, String>> crisesList = new ArrayList<HashMap<String, String>>();

        HashMap<String, String> listEntry;

        Iterator<Crisis> iter = this.crises.iterator();
        while (iter.hasNext()) {
            Crisis entry = iter.next();//from  w  w w  . ja v  a 2s.co m

            listEntry = new HashMap<String, String>();
            listEntry.put("type_icon", entry.getTypeIcon());
            listEntry.put("short_title", entry.getShortTitle());
            listEntry.put("dc_date", Common.getTimeAgoInWords(Common.getMiliseconds(entry.getDate())));

            crisesList.add(listEntry);
        }
        this.adapterMainList = new SimpleAdapter(getActivity(), crisesList, R.layout.list_entry,
                new String[] { "type_icon", "short_title", "dc_date" },
                new int[] { R.id.icon, R.id.topText, R.id.bottomText });

        this.list.setAdapter(adapterMainList);

        this.progessDialog.dismiss();
    }
}

From source file:net.reichholf.dreamdroid.activities.DreamDroidShareActivity.java

public void load() {
    DatabaseHelper dbh = DatabaseHelper.getInstance(this);
    mProfileMapList = new ArrayList<ExtendedHashMap>();
    mProfileMapList.clear();/* w  ww .  j  a  v  a 2  s.c o  m*/
    mProfiles = dbh.getProfiles();
    if (mProfiles.size() > 1) {
        for (Profile m : mProfiles) {
            ExtendedHashMap map = new ExtendedHashMap();
            map.put(DatabaseHelper.KEY_PROFILE, m.getName());
            map.put(DatabaseHelper.KEY_HOST, m.getHost());
            mProfileMapList.add(map);
        }

        mAdapter = new SimpleAdapter(this, mProfileMapList, android.R.layout.two_line_list_item,
                new String[] { DatabaseHelper.KEY_PROFILE, DatabaseHelper.KEY_HOST },
                new int[] { android.R.id.text1, android.R.id.text2 });
        setListAdapter(mAdapter);
        mAdapter.notifyDataSetChanged();
    } else {
        if (mProfiles.size() == 1) {
            playOnDream(mProfiles.get(0));
        } else {
            showToast(getString(R.string.no_profile_available));
        }
    }
}

From source file:at.alladin.rmbt.android.views.ResultDetailsView.java

@Override
public void taskEnded(final JSONArray testResultDetail) {
    //if (getVisibility()!=View.VISIBLE)
    //    return;

    if (this.resultFetchEndTaskListener != null) {
        this.resultFetchEndTaskListener.taskEnded(testResultDetail);
    }//from   w  ww .  j  a  v a 2s . c om

    if (testResultDetail != null && testResultDetail.length() > 0
            && (testResultDetailTask == null || !testResultDetailTask.hasError())) {
        this.testResult = testResultDetail;

        System.out.println("testResultDetail: " + testResultDetail);

        try {

            HashMap<String, String> viewItem;

            for (int i = 0; i < testResultDetail.length(); i++) {

                final JSONObject singleItem = testResultDetail.getJSONObject(i);

                viewItem = new HashMap<String, String>();
                viewItem.put("name", singleItem.optString("title", ""));

                if (singleItem.has("time")) {
                    final String timeString = Helperfunctions.formatTimestampWithTimezone(
                            singleItem.optLong("time", 0), singleItem.optString("timezone", null),
                            true /* seconds */);
                    viewItem.put("value", timeString == null ? "-" : timeString);
                } else
                    viewItem.put("value", singleItem.optString("value", ""));
                itemList.add(viewItem);
            }
        } catch (final JSONException e) {
            e.printStackTrace();
        }

        valueList = new SimpleAdapter(activity, itemList, R.layout.test_result_detail_item,
                new String[] { "name", "value" }, new int[] { R.id.name, R.id.value });

        listView.setAdapter(valueList);

        listView.invalidate();

        progessBar.setVisibility(View.GONE);
        emptyView.setVisibility(View.GONE);
        listView.setVisibility(View.VISIBLE);

    } else {
        Log.i(DEBUG_TAG, "LEERE LISTE");
        progessBar.setVisibility(View.GONE);
        emptyView.setVisibility(View.VISIBLE);
        emptyView.setText(activity.getString(R.string.error_no_data));
        emptyView.invalidate();
    }

}

From source file:net.reichholf.dreamdroid.activities.ShareActivity.java

public void load() {
    DatabaseHelper dbh = DatabaseHelper.getInstance(this);
    mProfileMapList = new ArrayList<>();
    mProfileMapList.clear();// w  ww.ja  v  a  2s  . c  om
    mProfiles = dbh.getProfiles();
    if (mProfiles.size() > 1) {
        for (Profile m : mProfiles) {
            ExtendedHashMap map = new ExtendedHashMap();
            map.put(DatabaseHelper.KEY_PROFILE_PROFILE, m.getName());
            map.put(DatabaseHelper.KEY_PROFILE_HOST, m.getHost());
            mProfileMapList.add(map);
        }

        mAdapter = new SimpleAdapter(this, mProfileMapList, android.R.layout.two_line_list_item,
                new String[] { DatabaseHelper.KEY_PROFILE_PROFILE, DatabaseHelper.KEY_PROFILE_HOST },
                new int[] { android.R.id.text1, android.R.id.text2 });
        setListAdapter(mAdapter);
        mAdapter.notifyDataSetChanged();
    } else {
        if (mProfiles.size() == 1) {
            playOnDream(mProfiles.get(0));
        } else {
            showToast(getString(R.string.no_profile_available));
        }
    }
}

From source file:com.melchor629.musicote.MainActivity.java

private void sis() {
    if (songList == null) {
        Log.e("MainActivity", "songList viene vaco...");
        return;/*ww w .ja  v a2s .c  o  m*/
    }
    /**
     * Updating parsed JSON data into ListView
     * */
    ListAdapter adapter = new SimpleAdapter(this, songList, R.layout.list_item,
            new String[] { "titulo", "artista", "album", "downloaded" },
            new int[] { R.id.name, R.id.email, R.id.mobile, R.id.mainStatusSong });

    setListAdapter(adapter);

    // selecting single ListView item
    ListView lv = getListView();
    lv.setFastScrollEnabled(true);

    // Launching new screen on Selecting Single ListItem
    lv.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // getting values from selected ListItem
            LinkedTreeMap<String, String> datos = songList.get(position);

            // Starting new intent
            Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);
            in.putExtra("obj", datos);

            startActivity(in);
        }
    });

    lv.setLongClickable(true);
    lv.setOnItemLongClickListener(new OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, final View v, final int which, long id) {
            final boolean isDownloaded = Utils.isDownloaded(songList.get(which).get("archivo"));
            AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
            builder.setTitle(((TextView) v.findViewById(R.id.name)).getText().toString())
                    .setItems(isDownloaded ? R.array.song_options_array2 : R.array.song_options_array,
                            new OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which2) {
                                    LinkedTreeMap<String, String> obj = songList.get(which);
                                    String url = obj.get("archivo");
                                    if (which2 == 0) {
                                        if (Reproductor.a == -1) {
                                            PlaylistManager.self.startPlaying(obj.get("titulo"),
                                                    obj.get("artista"), obj.get("album"), url);
                                        } else {
                                            PlaylistManager.self.stopPlaying();
                                            PlaylistManager.self.addSong(obj.get("titulo"), obj.get("artista"),
                                                    obj.get("album"), url);
                                        }
                                    } else if (which2 == 1) {
                                        if (!isDownloaded) {
                                            Intent inte = new Intent(getApplicationContext(),
                                                    DownloadManager.class);
                                            inte.putExtra("file", url);
                                            inte.putExtra("id", which);
                                            startService(inte);
                                        } else {
                                            if (new File(Utils.getUrl(url)).delete()) {
                                                Utils.setFileAsDownloaded(which, false);
                                                Toast.makeText(MainActivity.this,
                                                        getString(R.string.done_delete), Toast.LENGTH_LONG)
                                                        .show();
                                            } else
                                                Toast.makeText(MainActivity.this,
                                                        getString(R.string.err_delete), Toast.LENGTH_LONG)
                                                        .show();
                                        }
                                    } else if (which2 == 2) {
                                        PlaylistManager.self.addSong(obj.get("titulo"), obj.get("artista"),
                                                obj.get("album"), url);
                                    }
                                }
                            })
                    .create().show();
            return true;
        }
    });

}

From source file:net.reichholf.dreamdroid.activities.ServiceListActivity.java

/**
 * //from   w  w  w.j av a2  s. c o  m
 */
private void setAdapter() {
    mAdapter = new SimpleAdapter(this, mMapList, R.layout.service_list_item,
            new String[] { Event.SERVICE_NAME, Event.EVENT_TITLE, Event.EVENT_START_TIME_READABLE,
                    Event.EVENT_DURATION_READABLE },
            new int[] { R.id.service_name, R.id.event_title, R.id.event_start, R.id.event_duration });

    setListAdapter(mAdapter);
}

From source file:markson.visuals.sitapp.CCActivity.java

public void json() {

    ListAdapter adapter = new SimpleAdapter(this, mylist, R.layout.jsontest, new String[] { "cclass", "fdate" },
            new int[] { R.id.item_title, R.id.item_subtitle });

    setListAdapter(adapter);//from w  ww. j  ava 2s. co m

    final ListView lv = getListView();
    lv.setTextFilterEnabled(true);
    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            @SuppressWarnings("unchecked")
            HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);
            // Toast.makeText(eventActivity.this,"ID '" + o.get("link") +
            // "' was clicked.",Toast.LENGTH_SHORT).show();

            TextView title = (TextView) findViewById(R.id.item_title);
            Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/roboto/Roboto-Regular.ttf");
            title.setTypeface(tf);

            TextView subtitle = (TextView) findViewById(R.id.item_subtitle);
            subtitle.setTypeface(tf);

            date = o.get("date");
            cclass = o.get("cclass");
            num = o.get("num");
            instructor = o.get("instructor");
            crn = o.get("crn");
            fdate = o.get("date");
            time = o.get("time");
            download();
        }
    });
}

From source file:com.personal.coine.scorpion.jxnuhelper.view.fragment.ChargeOthersCardFragment.java

private void initViews(View view) {

    final TextView userName = (TextView) view.findViewById(R.id.others_name);
    othersBalance = (TextView) view.findViewById(R.id.others_balance);
    final AppCompatEditText userInputCardNumber = (AppCompatEditText) view
            .findViewById(R.id.et_user_card_number);
    userInputCardNumber.addTextChangedListener(new TextWatcher() {
        @Override/*from ww w . j  a va 2s  .  c  om*/
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (s.length() == 10) {
                queryProgress = KProgressHUD.create(getContext())
                        .setStyle(KProgressHUD.Style.SPIN_INDETERMINATE).setLabel("...")
                        .setCancellable(false).setAnimationSpeed(2).setDimAmount(0.5f);
                BmobQuery<CampusCard> query = new BmobQuery<CampusCard>();
                query.addWhereEqualTo("cardNumber", s.toString());
                query.findObjects(getContext(), new FindListener<CampusCard>() {
                    @Override
                    public void onSuccess(List<CampusCard> list) {

                        chargeUser = list.get(0).getOwner();
                        BmobQuery<MyUser> userQuery = new BmobQuery<MyUser>();
                        userQuery.addWhereEqualTo("objectId", chargeUser.getObjectId());
                        userQuery.findObjects(getContext(), new FindListener<MyUser>() {
                            @Override
                            public void onSuccess(List<MyUser> list) {
                                queryProgress.dismiss();
                                chargeUser = list.get(0);
                                userName.setText(chargeUser.getUsername());
                                chargePresenter.loadCardInfo();
                            }

                            @Override
                            public void onError(int i, String s) {
                                queryProgress.dismiss();
                                Log.e(TAG, "??" + s);
                                Toast.makeText(getContext(), "?",
                                        Toast.LENGTH_SHORT).show();
                            }
                        });
                    }

                    @Override
                    public void onError(int i, String s) {
                        queryProgress.dismiss();
                        Toast.makeText(getContext(), "?,", Toast.LENGTH_SHORT).show();
                        Log.e(TAG, "" + s);
                    }
                });
            }
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });
    GridView chargeAmount = (GridView) view.findViewById(R.id.others_charge_amount);
    List<Map<String, Object>> dataList = new ArrayList<>();
    final String[] titleArray = new String[] { "10", "20", "30", "50", "100", "200", "300",
            "500" };
    String[] contentArray = new String[] { ":10.00", ":20.00", ":29.94",
            ":49.85", ":99.75", ":199.60", ":299.00", ":498.00" };
    for (int i = 0; i < titleArray.length; i++) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("title", titleArray[i]);
        map.put("content", contentArray[i]);
        dataList.add(map);
    }
    SimpleAdapter adapter = new SimpleAdapter(getContext(), dataList, R.layout.grid_item,
            new String[] { "title", "content" }, new int[] { R.id.charge_title, R.id.charge_content });
    chargeAmount.setAdapter(adapter);
    chargeAmount.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
            AlertDialog alertDialog = new AlertDialog.Builder(getContext()).setTitle("")
                    .setMessage("" + titleArray[position] + "?")
                    .setPositiveButton("", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            chargeSum = Integer.valueOf(
                                    titleArray[position].substring(0, (titleArray[position].length() - 1)));
                            chargePresenter.doCharge();
                        }
                    }).setNegativeButton("?", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {

                        }
                    }).show();
        }
    });
}

From source file:com.example.ajoy3.steganography.BluetoothChatFragment.java

/**
 * Set up the UI and background operations for chat.
 *//*from   w ww  .j a va2  s  .  c om*/
private void setupChat() {
    Log.d(TAG, "setupChat()");

    // Initalize the key list
    final SimpleAdapter adapter = new SimpleAdapter(BluetoothChatFragment.this.getActivity(), getMapData(list),
            R.layout.keyitem, new String[] { "itemfileName" }, new int[] { R.id.fileName });
    //        mKeyListView.setAdapter(adapter);
    //        Log.d(TAG, "show the list");
    //
    //        mKeyListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    //            @Override
    //            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
    //                Toast.makeText(BluetoothChatFragment.this.getActivity(), "You select the key: " + list.get(arg2).getName(), Toast.LENGTH_LONG).show();
    //                // Get the select key name
    //                mKey = list.get(arg2).getName();
    //                View view = getView();
    //                if(null!=view){
    //                    TextView textView = (TextView) view.findViewById(R.id.edit_text_out);
    //                    textView.setText(mKey);
    //                }
    //            }
    //        });

    // Initialize the array adapter for the conversation thread
    //        mConversationArrayAdapter = new ArrayAdapter<String>(getActivity(), R.layout.message);

    //        mConversationView.setAdapter(mConversationArrayAdapter);

    // Initialize the compose field with a listener for the return key
    mOutEditText.setOnEditorActionListener(mWriteListener);

    BtnSecureScan.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Launch the DeviceListActivity to see devices and do scan
            Intent serverIntent = new Intent(getActivity(), DeviceListActivity.class);
            startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE_SECURE);
        }
    });

    // Initialize the send button with a listener that for click events
    mSendButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Send a message using content of the edit text widget
            View view = getView();
            if (null != view) {
                TextView textView = (TextView) view.findViewById(R.id.edit_text_out);
                //create AES key
                try {
                    mKey = mAES.randomkey();
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                if (null != mKey) {
                    textView.setText("Your key is Ready & Sent!");
                    Toast.makeText(getActivity(), "key: " + mKey + "Device Name: " + mConnectedDeviceName,
                            Toast.LENGTH_SHORT).show();
                    dbHandler.createPairInfoEntry(new PairInformation(dbHandler.getPairedDeviceCount(),
                            mConnectedDeviceName, "", mKey));
                    //                        for(int index =0; index<dbHandler.getPairedDeviceCount(); index++)
                    //                        {
                    //                            if(dbHandler.getAllMyPairedDeviceInfo().get(index).get_nameofpairer().equals(mConnectedDeviceName)){
                    //                                dbHandler.getAllMyPairedDeviceInfo().get(index).set_sharedkey(mKey);
                    //                            }
                    //                        }
                    sendMessage(mKey);
                    mKey = null;
                }
            }
        }
    });

    // Initialize the store button in invisible state
    mStoreButton.setVisibility(View.INVISIBLE);

    // Initialize the BluetoothChatService to perform bluetooth connections
    mChatService = new BluetoothChatService(getActivity(), mHandler);

    // Initialize the buffer for outgoing messages
    mOutStringBuffer = new StringBuffer("");
}