android java sdk, loading bookmarks into spinner? - java

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.

Related

Android get id for an edit text field from a context xml file

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.

Android: filter ListView without the adapter

I have a ListView that gets filled by SimpleAdapter, this adapter is local variable inside the procedure that fills the ListView.
Now, I want to filter the ListView, but I have no access to the adapter in the EditText events
is there a way to do that?
I tried MyListView.getAdapter().getFilter().Filter("some text");
but that gives error as getFilter does not exist for MyListView.getAdapter()
How can I fix this?
Declare adapter as global, setting adapter as global will let you filter it:
YourActivity.this.adapter.getFilter().filter("some text");
Did you try this?, it should works:
Adapter adapter= MyListView.getAdapter();
adapter.getFilter().filter("some text");
Too you can post your code to check what are you doing wrong, if you're using a custom adapter you have to implement the getFilter method
This post might answer your question. You have to create getFilter() in your adapter.

Populating listview from arraylist

I want to populate a list view with an array list. The array list is fetched from a soap web service response. I have used it as following:
mylistview = (ListView)findViewById(R.id.list);
listAdapter = new ArrayAdapter<Plant>(MainActivity.this,
android.R.layout.simple_list_item_1, array_books);
mylistview.setAdapter(listAdapter);
It display following in list view:
Book{id=1; name= C++; imagepath=https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GW3ixVIGHLrrXb2yN_6i;}
Book{id=2; name= Java; imagepath=https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GW3ixVyN_6i;}
Book{id=3; name=Android; imagepath=https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GW3HLrrXb2yN_6i;}
I want to display the image by retrieving it from its path in Image View and display only name of book like:
image ................ Java
When I change the layout in
listAdapter = new ArrayAdapter<Book>(MainActivity.this,
android.R.layout.row, array_books);
it gives error that row cannot resolved as a resource. But row.xml is present in the layout folder. How can I correct this error and display the items I want in the list view?
Try this
listAdapter = new ArrayAdapter<Plant>(MainActivity.this,
R.layout.row, array_books);// Change android.R.layout.row to R.layout.row
Your row is present in your layout so need to find using R.layout.row
Use R.layout.row instead of android.R.layout.row
As #Giru pointed out, if your xml file row.xml is in your layout folder, you can't reference it by android.R
The android.R object has references to the resources bundled with Android.
Your resources are simply under your.package.R so in your file just remove the "android." and have
listAdapter = new ArrayAdapter<Plant>(MainActivity.this,
R.layout.row, array_books);
and you should be good to go.

SlidingMenu without fragments

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

Spinner not a view that can be bounds(sp) by this SimpleCursorAdapter

I'm trying to adapt my query to my spinner object with some trouble, I get the error listed as the title. Here is the code portion where it crashes:
Spinner classDropDown = (Spinner) this.findViewById(R.id.classDropDown);
int[] to = new int[] { R.id.classDropDown };
String[] classFields = new String[] { "className" };
SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(this, R.layout.main, cursor, classFields, to);
cursorAdapter.setDropDownViewResource(R.id.classDropDown);
classDropDown.setAdapter(cursorAdapter);
I had a problem where the cursor wasn't being filled but fixed that now. Can someone give me help on debugging this issue?
Edit: I think my problem is the "to" field. What should this be?
Edit 2: Also, here is the XML for the spinner object:
<Spinner
android:id="#+id/classDropDown"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Edit 3: I've fixed the above to reflect fixing the code. This fixes this particular problem. I'm not getting the error, but I also have nothing displayed in the spinner.
To is a list of resource ids that you want to put your data into, such as R.id.textview1, and they meed to be contained in the layout you specify in the adapter. The number of elements should also match the number of elements in your from array ( you called it classfields).
So, you have two pieces of data and only specified one target resource id. Either remove one of the fields in your classfields array or add a widget to your layout and call.it in your to array and it should work.

Categories