android searching the list view? - java

i have created listview as follows...
lv = (ListView) findViewById(R.id.listview);
lv.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_checked, mDisplay));
my question is that i need to make the listview searchable such that if the user enters an alphabet the listview must scroll to that item starting with that alphabet (i dont want it to be filtered) with all the list items visible ...
for example if the user press "f" i want the list to scroll to the 1st item with "f" as follows
i DONT want it to be as follows:
i am sorry if the question is not understandable because i dont know how to put it
ask me if u need more details...
thanks :)

following link might help you Android search list while typing

I don't know if something for your requirement in readly available. But you can implement it through a logic like this.
Whenever user presses say f, check in your arraylist from which position words from f starts. say from 5th position it starts.
and use
listview.smoothScrollToPosition(int position)

Related

ListView inside ListView item

I want to ask one question, should I use ListView inside ListView item? Or I should redesign and remake my idea?
Example of ListView, but should be with couple sub items:
A ListView inside a ListView item is never a good idea. If you want sublists inside your list you can, for example, use a ExpandableListView. However, with the migration from ListViews to RecyclerViews I would recommend you go and implement this instead.
A ListView will never work correctly embedded as an item in another ListView. In fact, scrolling things inside other scrolling things is almost never what you really want to do, as it would be confusing to the user how to actually navigate your screen.

Is it possible to reduce number of pages in android?

I am making an android app. this app consist of list. by clicking each item of list a new page opens.
this list contains 50 items.I should make 50 activity and their corresponding XML file.
so, is there any way that make this process easier that don't force me to make all this 50 activity one by one?
my reputation is not enough. so I upload related picture.
http://uupload.ir/files/oh1o_1.png
http://uupload.ir/files/zam9_2.png
Not sure what you mean by creating 50 pages. You have NOT to create a new class for each item in the list, instead you will create a new instance of a class. This is what programming, and OOP (Object Oriented Programming) comes into play.. Basically what you need to do is:
Create a "main_activity" class which will contain your list
Create a "item_detail_activity" which will show the details about your clicked item
What you need to write is the logic of "passing" the correct data depending on the clicked item. When an item in the "main_activity" is clicked, you will create a new instance of "item_detail_activity", passing the correct data (through a bundle).
BTW there are a lot of tutorials out there that will help you understand better the logic of an Android application.
If you have a list of items probably means that you have a list of objects which are of the same kind with same structure.
Due to this, you will have 50 pages which show to the user the same item with different values to variables, with the same structure.
You can make the objects in your list parcelable (refer to this), then pass it with the Intent to a second Activity you create, receive it, and at last populate the screen with the item you passed.
If you have troubles or doubts feel free to ask :)
EDIT:
Imagine your listview is called ListView, and the List of items you used to fill the listview is called list in the MainActivity do this:
ListView listView = (ListView) findViewById(R.Id.ListView);
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// position is the index of selected item
// Launching new Activity on selecting single List Item
Intent i = new Intent(MainActivity.this, SecondActivity.class);
// sending data to new activity
i.putExtra("item", list.get(position));
startActivity(i);
}
});
in your SecondActivity, with getParcelableExtra("item") you retreieve the item clicked. Here with the variables of this item you can populate the page.
here is the doc for intents.
In secondActivity, if something must disappear if a variable has a certain value or is null, play with visibility or fragment: create an Activity with all case shown, than work with visibility or with fragments and adjust it ;)
Change your activity to fragment activity and write code to display the details corresponding listview click. it easy to follow.

Spinner shows the selected item in Android

In my program I have a spinner that show three Strings taken from an Arraylist<String>. I use this code:
pinnerArray = new ArrayList<String>();
spinnerArray.add("IT");
spinnerArray.add("EN");
spinnerArray.add("PR");
ArrayAdapter lenguageAdapter=new ArrayAdapter(convertView.getContext(), R.layout.lenguage_item_layout, spinnerArray);
holder.spinnerLenguage.setAdapter(lenguageAdapter);
My spinner initially shows IT and, when I click on it, opens the list of items. In this list there are all 3 items (IT, EN, PR) but I want show the selected item (in this case IT) only one time and not two times.
How can I correct my code?

Checkbox in ListView with odd checking behaviour

I am new to Java and Andriod development.
I have a view within my app which contains a ListView
I then have a custom Adapter which inherits from an ArrayAdapter
within the view in the getView method I return a row which contains some text and a checkbox
now so far this all works great my list is populated and I can check my items, and all the events seem to fire as expected.
My problem that I am having is that I check the first 3 items and then I notice that the 11th, 12th and 13th items are checked and as I scroll I see that at regular intervals other checkboxes also seem to be checked in the same pattern.
If I check about 10 checkboxes then it will end up checking all the items in the list of about 80...
can anyone explain what I have done wrong?
I dont think any code will help explain this as I do not set the checkstate of the checkbox anywhere, this is all handled itself, so the fact items are being checked is puzzling me.
Thanks in advance
This is happening because Android recycles list items for performance purposes, here you have the solution of this problem:
ListView reusing views when ... I don't want it to
Hope to help :)
This is expected behavior. ListView reuses views in the adapter.
So what you want is to keep a Set of "selected items" and add an item or remove it when the CheckBox is clicked and then in your getView add the following code:
if(mSelected.contains(getItem(position)) {
checkBox.setChecked(true);
} else {
checkBox.setChecked(false);
}
This way when the row is reused the CheckBox will be the proper status.

to get checked items from listview and store it in array

I am new to android..please help me.
how to get the checked items from listview and store it an array and display it in another listview in the next layout in the same activity?pls help....
Hi if you are using listView with check box then you can follow this
linkhttp://appfulcrum.com/?p=281
Rather than create checked list box, create custom list view. You can easily detect whether checked box is checked or not.

Categories