Is it possible to use the SlidingMenu (seen https://github.com/jfeinstein10/SlidingMenu) without the use of fragments? In my app i am using GreenDroid, and seeing it doesn't yet have support for GDFragmentActivities or anything of the sort. So i am just using the example of attaching the SlidingMenu to my activity using the following code:
SlidingMenu slide = new SlidingMenu(this );
slide.setMode(SlidingMenu.LEFT);
slide.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
slide.setTouchModeBehind(SlidingMenu.TOUCHMODE_FULLSCREEN);
slide.setBehindOffset(150);
slide.setFadeDegree(0.3f);
slide.setShadowWidth(5);
slide.setOnClickListener(this);
slide.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
slide.setMenu(R.layout.simpleframelayout);
ListView v = (ListView)slide.getMenu().findViewById(R.id.simpleFrameLayoutList);
v.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, new String[]{"Hello"}));
My problem is that though this will make the SlidingMenu appear properly, the ListView will be completely unresponsive to any touches. I was wondering if there were anything i could possibly be missing or if in fact i definitely do need to use fragments?
Cheers
Instead of this
(ListView)slide.getMenu().findViewById(R.id.simpleFrameLayoutList);
Try this
(ListView)findViewById(R.id.simpleFrameLayoutList);
It worked for me
Related
I have an activity called PeopleActivity, with a layout xml of activity_people.xml.
This activity is using the Android Studio Navigation Drawer Activity template.
I have a list view in the content_people.xml file named people_list. When I attempt to associate this control in the back end, it is unable to find the id. I am attempting it as:
peopleList = (ListView) findViewById(R.id.people_list);
Any insight would be greatly appreciated.
EDIT: Did an update to the code section to reflect the correct control referenced.
you should declare your listview like this:
peopleSearch = (ListView) findViewById(R.id.people_list);
not as EditText
I found the answer. You cannot use capital letters in the naming of your controls. Once I fixed this, everything worked fine.
I'm using the sliding menu library here: https://github.com/jfeinstein10/SlidingMenu/
and I have an activity that inherits from SlidingMenuActivity with a sliding menu that works perfectly, but I also want to add SlidingMenus to each row in a list fragment that is shown as part of this SlidingMenuActivity subclass. It seems that the way I'm doing it doesn't work at all; the touches get intercepted and they don't let me click on a list row, but I can't swipe the sliding menu into appearance, nor can I see the SlidingMenu when it's closed.
This is the code that I'm using to add the sliding menu to each list row:
private void makeSlidingMenu(View view) {
FrameLayout menuClosedFrame = // ... the above view
RelativeLayout menuLayout = // ... the behind view
SlidingMenu slidingMenu = new SlidingMenu(view.getContext());
slidingMenu.setContent(menuClosedFrame);
slidingMenu.setMenu(menuLayout);
slidingMenu.setBackgroundColor(Color.RED);
slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
slidingMenu.setTouchModeBehind(SlidingMenu.TOUCHMODE_FULLSCREEN);
slidingMenu.setBehindScrollScale(1.0f);
slidingMenu.setFadeDegree(0.0f);
RelativeLayout layout = (RelativeLayout)view;
layout.addView(slidingMenu, new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT) {{
addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
}});
}
It's not pretty, but it seems to get the job done on a normal activity that doesn't have a list view and is not a SlidingMenuActivity. It just doesn't work in a nested scenario with a ListView for me. Is there anything else I could be doing wrong? If posting more code would help let me know. Thanks!
Figured it out; the way I was adding the sliding menu to the row was causing it to be sized improperly I think; I fixed it by adding it to a framelayout instead that also contains the contents I want to show since i want the cell's main content to remain static.
I am new to Android Development and I have a simple list app which I have been asked to create.I have had no problems having the app as activity based however I have to extend the functionality and use fragments for a 'universal' app. My main activity is:
I was able to successfully compile your code by taking the following steps:
It looks like this line is the problem (inside Main.java):
contactCursor = contactDBAdapter.getAllContactsCursor();
I looked at how your contactDBAdapter gets initialized and it turns out you initialize it after you setContentView for your activity. However, your view involves calls to contactDBAdapter. So in Main.java you need to move the following two lines to the TOP of the onCreate window:
public void onCreate(Bundle savedInstanceState)
{
contactDBAdapter = new ContactDBAdapter(this);
contactDBAdapter.open();
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
....
}
Furthermore, the following line in Main.java needs to be removed (or commented out):
contact.clear();
Also, I had to make two further changes to how you call ListView
In list_view.xml, the way you identify a ListView for Android is :
android:id="#+id/android:list"
In ContactListFragment.java, then call the ListView this way :
parent.myListView = (ListView)v.findViewById(android.R.id.list);
have you not just tried using the Eclipse Template which set up everything for you just copy in your existing code?
File>New>Android Application Project then under the Create Activity Step select
Your Fragment class needs an empty default constructor. See Android Reference
I have a SherlockFragmentActivity using tabhost and viewpager. Calling
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
in the fragmentactivity creates the spinner, and calling
setSupportProgressBarIndeterminateVisibility(false);
won't disable it. I also don't seem to be able to call getActivity().setSupportProgressBarIndeterminateVisibility(false);
from the fragments;
I get the error "The Method setSupportProgressBarIndeterminateVisibility(boolean) is undefined for the type FragmentActivity."
What am I doing wrong, can someone show me the way how to use it properly in fragments? I want to be able to create the progressbar in my asynctask pre execute and stop it in postexecute.
I'm using2.2 emulator and importing import com.actionbarsherlock.view.Window; instead of the android.view one.
[Edit] I just confirmed using setProgressBarIndeterminateVisibility works in the 4.1 emulator. Anyway, I need to get this work in 2.2
"I also don't seem to be able to call getActivity().setSupportProgressBarIndeterminateVisibility(false); from the fragments;"
You need to be calling getSherlockActivity() instead of getActivity().
"I'm using2.2 emulator and importing import com.actionbarsherlock.view.Window; instead of the android.view one."
Plus one for that, hadn't spotted that import and came across this post which fixed my bug - wasn't showing the progress indicator in Gingerbread before, many thanks :)
This works perfect for me:
getActivity().setProgressBarIndeterminate(true);
ProgressDialog progressDialog = new ProgressDialog(getActivity());
progressDialog.show(getActivity(), "This is", " a message...");
May you help ;)
The spinner comes up with but with nothing in it
what am I doning wrong?
cbookmarks = Browser.getAllBookmarks(getContentResolver());
SimpleCursorAdapter ABM = new SimpleCursorAdapter(this,android.R.layout.simple_spinner_item, cbookmarks,new String[] {android.provider.Browser.BookmarkColumns.URL},new int[]{R.id.Spinner});
ABM.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
SpinnerBM.setAdapter(ABM);
Thanks.
Is R.id.Spinner a TextView? Perhaps you can post the XML you have defined for the layout of the entries?
UPDATE
According to the documentation the array of id's that you pass into the SimpleCursorAdapter constructor need to be TextView. Most examples I have seen use the built-in id of android.R.id.text1, but I think you can define your own custom layouts too.