|
1 | 1 | package in.ac.dtu.subtlenews; |
2 | 2 |
|
3 | | -import android.support.v7.app.ActionBarActivity;; |
| 3 | +import android.content.Context; |
| 4 | +import android.graphics.Color; |
| 5 | +import android.support.v7.app.ActionBarActivity; |
4 | 6 | import android.app.Activity; |
5 | 7 | import android.support.v7.app.ActionBar; |
6 | 8 | import android.support.v4.app.Fragment; |
|
18 | 20 | import android.view.View; |
19 | 21 | import android.view.ViewGroup; |
20 | 22 | import android.widget.AdapterView; |
21 | | -import android.widget.ArrayAdapter; |
| 23 | +import android.widget.BaseAdapter; |
| 24 | +import android.widget.ImageView; |
22 | 25 | import android.widget.ListView; |
23 | | -import android.widget.Toast; |
| 26 | +import android.widget.TextView; |
| 27 | + |
| 28 | +import java.lang.reflect.Array; |
24 | 29 |
|
25 | 30 | /** |
26 | 31 | * Fragment used for managing interactions for and presentation of a navigation drawer. |
@@ -97,11 +102,7 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id) |
97 | 102 | selectItem(position); |
98 | 103 | } |
99 | 104 | }); |
100 | | - mDrawerListView.setAdapter(new ArrayAdapter<String>( |
101 | | - getActionBar().getThemedContext(), |
102 | | - android.R.layout.simple_list_item_1, |
103 | | - android.R.id.text1, |
104 | | - Utils.categoryMap)); |
| 105 | + mDrawerListView.setAdapter(new NavigationDrawerAdapter(Utils.categoryMap)); |
105 | 106 | mDrawerListView.setItemChecked(mCurrentSelectedPosition, true); |
106 | 107 | return mDrawerListView; |
107 | 108 | } |
@@ -270,4 +271,54 @@ public static interface NavigationDrawerCallbacks { |
270 | 271 | */ |
271 | 272 | void onNavigationDrawerItemSelected(int position); |
272 | 273 | } |
| 274 | + |
| 275 | + private class NavigationDrawerAdapter extends BaseAdapter { |
| 276 | + |
| 277 | + String[] mCategoryMap; |
| 278 | + |
| 279 | + public NavigationDrawerAdapter( String[] mCategoryMap ){ |
| 280 | + |
| 281 | + this.mCategoryMap = mCategoryMap; |
| 282 | + } |
| 283 | + |
| 284 | + @Override |
| 285 | + public int getCount() { |
| 286 | + // TODO Auto-generated method stub |
| 287 | + return Array.getLength(mCategoryMap); |
| 288 | + } |
| 289 | + |
| 290 | + @Override |
| 291 | + public String getItem(int pos) { |
| 292 | + // TODO Auto-generated method stub |
| 293 | + return mCategoryMap[pos]; |
| 294 | + } |
| 295 | + |
| 296 | + @Override |
| 297 | + public long getItemId(int pos) { |
| 298 | + // TODO Auto-generated method stub |
| 299 | + return pos; |
| 300 | + } |
| 301 | + |
| 302 | + @Override |
| 303 | + public View getView(int pos, View convertView, ViewGroup parent) { |
| 304 | + |
| 305 | + View rowView; |
| 306 | + |
| 307 | + if(convertView == null){ |
| 308 | + LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
| 309 | + rowView = inflater.inflate(R.layout.row_navigation_drawer, null); |
| 310 | + } else { |
| 311 | + rowView = convertView; |
| 312 | + } |
| 313 | + |
| 314 | + ImageView navigationIcon = (ImageView) rowView.findViewById(R.id.icon_navigation); |
| 315 | + TextView navigationTitle = (TextView) rowView.findViewById(R.id.title_navigation); |
| 316 | + |
| 317 | + navigationTitle.setText(mCategoryMap[pos]); |
| 318 | + navigationTitle.setTextColor(Color.WHITE); |
| 319 | + navigationIcon.setBackgroundResource(R.drawable.ic_launcher); |
| 320 | + |
| 321 | + return rowView; |
| 322 | + } |
| 323 | + } |
273 | 324 | } |
0 commit comments