I'm currently bereft at the moment. I'm working on an application (Android) using a spinner but "incredible is nothing" it doesn't work at all. I mean, It displays the title but the list of items doesn't show up. It would be really nice if you could give me an explanation. (I'm a newbie in this tech ...). I followed all possible deals but nothing ...
Here is my source (of the activity) :
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.form_find_layout);
/********************** Les composants ********************/
String[] listLoyer = {"200","250","300","350","400","450","500","550","600","650","700"};
String[] listType = {"T1", "T2", "T3", "T4"};
// ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, listLoyer);
Spinner loyersMin = (Spinner)findViewById(R.id.min_spin);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.les_prix, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
loyersMin.setAdapter(adapter);
loyersMin.setOnItemSelectedListener(this);
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(
this, android.R.layout.simple_spinner_item, listLoyer);
Spinner loyersMax = ((Spinner) findViewById(R.id.max_spin));
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
loyersMax.setAdapter(adapter1);
loyersMax.setOnItemSelectedListener(this);
ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(
this, android.R.layout.simple_spinner_item, listType);
Spinner type_appart = ((Spinner) findViewById(R.id.type_spin));
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
type_appart.setAdapter(adapter2);
type_appart.setOnItemSelectedListener(this);
Button loginBtn = (Button)findViewById(R.id.find_btn);
loginBtn.setOnClickListener(this);
}
Thanks for all
I've solved my trouble. For those who get the same trouble with thier spinner, make sure that your "setContentView" targets the right layout, besides, that you correctly called your activity by the "mother" (or the caller class) activity (in my case).
Hope it helps you!
Related
I have a listview that I want to show several items. However, after the program compiles, nothing shows up and I am unsure as to why.
ListView listView = findViewById(R.id.quikList);
ArrayList<String> list = new ArrayList<String>();
list.add("Hello");
list.add("Is it me youre looking for?");
list.add("I can see it in your smile and I want so badly to make this listview work");
ArrayAdapter<String> aa = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, list);
listview.setAdapter(aa);
I don't know why this pretty basic task is not working. I think it might be due to android.R.id.text1, but I'm not sure as to why. Any sort of light anyone can shed on this topic would be fantastic.
No need of 3rd param just remove this line android.R.id.text1
ArrayAdapter<String> aa = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, list);
listView.setAdapter(aa);
Solution 2:
May be your theme issues which means your Textview color same as Listview background color..
so just change your listview background color...
android:background="#android:color/holo_red_dark"
Try this:
ListView listView = (Listview)findViewById(R.id.quikList);
String list[] = {"Hello","Is it me youre looking for?","I can see it in your smile and I want so badly to make this listview work"};
ArrayAdapter<String> aa = new ArrayAdapter<String>(this, R.layout.simple_list_item_1, R.id.textView, list);
listview.setAdapter(aa);
I have a spinner that's populated like this:
Spinner spinner = (Spinner) findViewById(R.id.m_spinner);
final ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(mContext, android.R.layout.simple_spinner_item, spinnerValuesList);
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(spinnerAdapter);
spinner.setPrompt("CPU Frequency Governor");
It's created like this:
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:spinnerMode="dialog"
android:id="#+id/my_spinner"/>
Everything works fine, but I'd like to align the text of the dialog title and the spinner items. I attached a picture to show what it currently looks like and what I'm looking to achieve.
Thanks
Instead of
final ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(mContext, android.R.layout.simple_spinner_item, spinnerValuesList);
Try this:
final ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(mContext, android.R.layout.simple_list_item_1
, spinnerValuesList);
Let me know if it works for you.
I am trying to make "Select one" on Spinner. I saw all answer regarding this subject but I am still having some issues. Usual way of making custom spinner is:
ArrayAdapter<CharSequence> dataAdapter1 = ArrayAdapter.createFromResource(this, R.array.entries,
android.R.layout.simple_spinner_item);
dataAdapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner1.setAdapter(dataAdapter1);
spinner1.setAdapter(
new NothingSelectedSpinnerAdapter(
dataAdapter1,
R.layout.contact_spinner_row_nothing_selected,
this));
In this code I have to define R.array.entries in Strings.xml, but my app is populating spinner from MySQL and I am having a list grad[i]=json.getString("Grad");. How can I create this ArrayAdapter.createFromResource with that list instead of Entries that are defined in Strings.xml? Tnx
Query the data, put it in a List or Array and use this constructor of Array Adapter
ArrayAdapter<CharSequence> dataAdapter1 = new ArrayAdapter(this,
android.R.layout.simple_spinner_item, yourArrayOrList);
More here: http://developer.android.com/reference/android/widget/ArrayAdapter.html#ArrayAdapter(android.content.Context, int, java.util.List)
I use two Spinner and get data from asyncTask when I get first spinner and want get the 2th spinner but when setadapter .. two spanner's data are the same...
This is i setadapter first time.
List<String> none=new ArrayList<String>();
none.add("none");
ArrayAdapter<String> adapterchoseTime =
new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, none);
adapterchoseTime.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item);
ArrayAdapter<String> adapterchoseProm =
new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, none);
adapterchoseProm.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item);
choseTime.setAdapter(adapterchoseTime);
choseProm.setAdapter(adapterchoseProm);
I get Spinner 1's data
ArrayAdapter<String> adapterchoseTime=(ArrayAdapter<String>)choseTime.getAdapter();
adapterchoseTime.clear();
adapterchoseTime.addAll(time);
choseTime.refreshDrawableState();
and i get spinner2's data
ArrayAdapter<String> adapterchoseTime = (ArrayAdapter<String>)choseTime.getAdapter();
adapterchoseTime.clear();
adapterchoseTime.addAll(time);
ArrayAdapter<String> adapterchoseProm = (ArrayAdapter<String>)choseProm.getAdapter();
adapterchoseProm.clear();
adapterchoseProm.addAll(prom);
choseTime.setAdapter(adapterchoseTime);
choseProm.setAdapter(adapterchoseProm);
And then I get two same spinner...
It looks like you're referencing the same spinner from your setDropDownViewResource.
adapterchoseTime.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item);
One of these needs to reference the second spinner.
I'm trying to input an array into a ListView. I've gotten it to work for a spin box with this code:
Spinner spinner = (Spinner) findViewById(R.id.location_spinner);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, model.getLocationsArray());
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
When I run the next block of code the program closes unexpectedly. Strangely if I remove model.getLocationsArray() it runs but the view won't update.
ListView listView = (ListView) findViewById(R.id.available_locations_list);
adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, model.getLocationsArray());
listView.setAdapter(adapter);
Thanks in advance!
model.getLocationsArray() instead this... you can use directly Arraylist object. If you have.Nullpointer Exc. because of from your EditText value cant be added to your ArrayList.