0

I want to list the most recently messaged contacts in a navigation drawer from most recent at the top, however mDrawerListView (where navigation drawer's string are created) is in NavigationDrawerFragment.java and the function to list names can't be used since getContentResolver() and getApplicationContext() are undefined. I am also unsure how I would put the items in the names list as mDrawerListView's strings.

    @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    mDrawerListView = (ListView) inflater.inflate(
            R.layout.fragment_navigation_drawer, container, false);
    mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            selectItem(position);
        }

    });
    getAllSms();
    mDrawerListView.setAdapter(new ArrayAdapter<String>(
            getActionBar().getThemedContext(),
            android.R.layout.simple_list_item_1,
            android.R.id.text1,
            new String[]{
                    getString(R.string.title_section1),
                    getString(R.string.title_section2),
                    getString(R.string.title_section3),
            }));
    mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
    return mDrawerListView;
}
public void getAllSms() {
Uri message = Uri.parse("content://sms/");
ContentResolver cr = getContentResolver();
Cursor c = cr.query(message, null, null, null, null);
int totalSMS = c.getCount();
List<String> names = new ArrayList<String>();
if (c.moveToFirst()) {
    for (int i = 0; i < totalSMS; i++) {
        names.add(getContactName(
                getApplicationContext(),
                c.getString(c
                        .getColumnIndexOrThrow("address"))));
        c.moveToNext();
    }
}
c.close();
}
seang96
  • 61
  • 1
  • 11
  • extend `BaseAdapter` and use [LRUCache](http://developer.android.com/reference/android/util/LruCache.html) for Recent Used. this is how i should do it if im only caching. – Spurdow Aug 09 '14 at 03:28
  • @Spurdow, what is BaseAdapter and how what do you mean by extending it? – seang96 Aug 09 '14 at 03:31
  • [here customize your listview](http://stackoverflow.com/questions/16333754/how-to-customize-listview-using-baseadapter) , making your class adapt/behave like an adapter. – Spurdow Aug 09 '14 at 03:37

0 Answers0