Iam using Sherlock fragment to make a Action Bar. and I have ListView in action bar, but I will my listview can call activity .. Please help me Thanks.. :)
in this code
You need to use setOnItemClickListener() on your listview
listview.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0,View arg1, int position, long arg3) {
Intent n = null;
switch (position){
case 0:
n = new Intent(getActivity(), Class0.class);
break;
case 1:
n = new Intent(getActivity(), Class1.class);
break;
}
if(null!=n)
startActivity(n);
}
});
List navigation in the ActionBar does not require a ListFragment (or a SherlockListFragment in your case). Your code is setting the adapter for the ListView that is the content of the Activity. What you want is to set the ActionBar's navigation mode and provide the adapter to the ActionBar. In your onCreate:
ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
actionBar.setListNavigationCallbacks(adapter, navigationListener);
adapter
is a SpinnerAdapter
implementation. navigationListener is a ActionBar.OnNavigationListener
implementation. When the user presses an item from the dropdown list in the ActionBar, your navigationListener's onNavigationItemSelected
method gets called and it passes in the position and the id of the selected item. In that callback you can implement starting another activity.
See ActionBar and ActionBar.OnNavigationListener -- ActionBarSherlock mirrors the standard Android ActionBar APIs.