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?
Related
I have multiple arraylist in my Android studio project (Java) like :
firstArray = [1,2,3]
secondtArray = [A,B,C]
thirdArrayt = [X,Y,Z]
Now I want to populate my recyclerview with the items from these arraylist.Each time i want to show the spicific index from all the lists.
For example, in my first view i want to show firstArray[0],secondArray[0] and thirdArray[0] in my viewholder.
How do I get that?
I have 2 spinners and 1 edit text. How to get selected spinner item. I need to know witch ones are selected, so I could show conversion resoult in other activity.
First spinner have 2 items ( Celsius and Fahrenheit) second also. How to call one of 2 methods depending on spinner item select.
Create a reference for your spinners. Extract the selected value of the spinners like this:
String spinnerValue = String.valueOf(spinnerReference.getSelectedItem());
Considering that spinnerValue can contain either "Farenheit" or "Celsisus", you can use a switch block to call the appropriate method.
If you want to check currently selected item in the spinner you should have an instance of it. If you don't make sure you assign an id (for example "unitSpinner") to it in the layout file and then in the Activity's onCreate method call Spinner spinner = (Spinner) findViewById(R.id.<idYouAssigned>). Then you can call spinner.getSelectedItem() which will return either "Celsuius" or "Fahrenheit" depending on which one the user selected.
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.
Hi All I need your help.
I am currently having problems regarding to Android spinner.
Well, I have two spinners, one for source language and the other for target language. these two spinners values contain language list retrieved from database. For example in database I have list of language:
language_code(en,kr,jp,chinese), description (English,Korean,Japanese,Chinese).
The first spinner will contain all the language description whereas the second one will contain all except the selected one in the 1st spinner.
if the selected item in the 1st spinner is English then the values in 2nd spinner must be only the rest exclude English.
What I want is the user can change the languages any time they want, so when the spinner value is changed, user have to click a button to trigger the change and then using the intent to pass to the same class but with the different spinner value. And what I want is the spinner selected item for source and target are from the previous selection.
I have done with the spinner but I have idea with the dynamic change. Any idea?
Thank you
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)