I am using Horizontal ScrollView to get facebook like side navigation
Like this:

But how to show that “2” beside the Event item in the menu?
In my application i am using a ViewUtil class to get this menu:
public class ViewUtils {
private ViewUtils() {
}
public static void setViewWidths(View view, View[] views) {
int w = view.getWidth();
int h = view.getHeight();
for (int i = 0; i < views.length; i++) {
View v = views[i];
v.layout((i + 1) * w, 0, (i + 2) * w, h);
printView("view[" + i + "]", v);
}
}
public static void printView(String msg, View v) {
System.out.println(msg + "=" + v);
if (null == v) {
return;
}
System.out.print("[" + v.getLeft());
System.out.print(", " + v.getTop());
System.out.print(", w=" + v.getWidth());
System.out.println(", h=" + v.getHeight() + "]");
System.out.println("mw=" + v.getMeasuredWidth() + ", mh="
+ v.getMeasuredHeight());
System.out.println("scroll [" + v.getScrollX() + "," + v.getScrollY()
+ "]");
}
public static void initListView(Context context, ListView listView,
String prefix, int numItems, int layout) {
// By using setAdpater method in listview we an add string array in
// list.
String[] arr = new String[numItems];
arr[0] = "Feed";
arr[1] = "Friends";
arr[2] = "Notifications";
arr[3] = "Feedback";
arr[4] = "Logout";
listView.setAdapter(new ArrayAdapter<String>(context, layout, arr));
}
}
and set the adapter like this in the Activity:
ViewUtils.initListView(this, myListView, "Menu ", 5,
android.R.layout.simple_list_item_1);
I what my “Notifications” Text to be something like “Notification n” where n is like the “2” in the above pic. I tried to use Spannable String but i cannot set the Spannable String to the String Array “arr”
Thank You
I’m assuming those categories (News Feed, Messages,…) are items of a
ListView.Also, for displaying that “2” I’m assuming you will need a custom adapter.
In this case you just need to add a
TextViewto your row XML file and set the appropriate value in thegetView()method of your custom Adapter, or, if you are create the TextView programaticaly in thegetView()method.