I created an Android app where users can save data to Google Spreedsheet using Google Form. I followed this POST which I found is very useful for me, but I'm having some trouble. I'm not able to save data of RadioButton , CheckBox, Date....To upload data we need Key-Value pair.. for TextView its easy to find as ID field is using Inspect Element, But for RadioButton , CheckBox there are multiple IDs.. How to set data for that..
Can anyone please tell me, how to make it possible??
I wanted to work with Radion Buttons, but as there are number of Id's for different radio buttons. So i just opted for "Choose from a List" in google form. There in list you will have one Id for spinner and multiple options. Take the Entry_Id from form and attached with your spinner id. Here is the code
s = (Spinner) findViewById(R.id.spinner);
list.add("Male");
list.add("Female");
ArrayAdapter<String> ad = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_spinner_item, list);
ad.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s.setAdapter(ad);
s.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
result = list.get(position);
Toast.makeText(getApplicationContext(), "you selected:" + result, Toast.LENGTH_SHORT).show();
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
And in Your Post() method add this lines
gender = String.valueOf(s.getSelectedItem()); String data ="entry_1008323309=" + URLEncoder.encode(gender);
Hope this Will help you out.
Related
I am new to android and i want to make 3 spinner, 1 is to work, 2 is stain and 3rd is price. The data should come from server through JSON. If i select Metier example plumber then by selection of plumber i should get the list of tasks related to the plumber. . Price should get the price. The spinner should change according to 1st spinner.
All you have to do that give a network call on first spinner selection
for example:
if plumber is selected in first spinner post this string to server and get the data regarding this string "plumber"
after you get the data populate the data with second and third spinner
Hope its help :)
final Spinner spinner = (Spinner)findViewById(R.id.spinner);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
String items = spinner.getSelectedItem().toString();
//Here give a network call
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
I am trying to take an AutoCompleteTextView and, through an OnListItemClickListener, return an ID from a database. To be more specific, I want a user to be able to type something in, click on one of the options that pops up, and then, rather than completing the typed word, the click returns an ID associated with that word to the user.
I know that, through a custom adapter, I can return an id through a Spinner, but I want a user to be able to type in what they're looking for. Is there some way to do this through AutoCompleteTextView, or does another class exist where I can do this?
Thank you!
AFIK there is no such class with both the functionalities.
You can try the following code which does that...
final AutoCompleteTextView mAutoCompleteTextView;
final ArrayAdapter<String> mAdapter = new ArrayAdapter<String>(
getActivity(), android.R.layout.simple_dropdown_item_1line,
getResources().getStringArray(R.array.items));
mAutoCompleteTextView = (AutoCompleteTextView) view.findViewById(R.id.name_txt);
mAutoCompleteTextView.setAdapter(mAdapter);
mAutoCompleteTextView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(final View arg0) {
mAutoCompleteTextView.showDropDown();
}
});
I have implemented multiple(seven) spinners and populated them with three options: Yes, No, and Unknown. And "Unknown" is the default option. Now I want to know whether user clicked spinner or not. Since the default option can also be a valid answer, I could not work with getSelectedItemPosition() in Spinner class.
All I want to know is whether user clicked that particular spinner or not, so that I can generate alert message depending on this Info.
The first thing you should do is read the Spinners guide on the Android developer site. Having done that, you'll find this handy example:
public class MySpinnerActivity extends Activity implements OnItemSelectedListener {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Spinner spinner = (Spinner) findViewById(R.id.spinner);
spinner.setOnItemSelectedListener(this);
}
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
// An item was selected. You can retrieve the selected item using
// parent.getItemAtPosition(pos)
}
public void onNothingSelected(AdapterView<?> parent) {
// Another interface callback
}
}
Simpy,
First Set OnItemSelectedListener to each Spinner and then check in method,
if you have more spinner then getSelectedItem() using below code inside onItemSeleted Method,
String str1= (String) spinner1.getSelectedItem().toString();
String str2= (String) spinner2.getSelectedItem().toString();
Up front: This is my first attempt at an Android app. I'm in that strange place of not knowing what to search for to find the answer to my question.
What I have accomplished is:
Created a custom class myCustomClass with properties of 'title' and 'youTubeUrl'
Created an ArrayList<myCustomClass>
Added multiple elements to ArrayList<myCustomClass>
Created a custom ArrayAdapter and attached it to the the arraylist.
Added an onItemClickListener to the custom ArrayAdapter.
All of that works good. I would like to show the title in the ListView and then when the user clicks the list view item, I'd like to get a reference to the youtubeUrl property.
Here's what I have for the adapter code:
MyListAdapter myListAdapter = new MyListAdapter(this, R.layout.my_list, elements);
myList.setAdapter(myListAdapter);
myList.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String item = ((TextView)view).getText().toString();
Toast.makeText(getBaseContext(), item, Toast.LENGTH_LONG).show();
}
});
myListAdapter.notifyDataSetChanged();
Thanks for your help.
You can use the position property in onItemClick to go back to your data source and find the relevant item. From there you should be able to retrieve the Url.
As another poster implied, it depends on what you are using in your adapter. Assuming it's MyCustomClass. You can do something like this in your onItemClick method:
MyCustomClass selection = (MyCustomClass) getListView().getItemAtPosition(position);
So my situation is this. I have two tables. A main table where data is added using a form, this form has a spinner which is powered from the second table (this part is working correctly). I then want the selected item in the spinner to be stored in a foreignkey field in the main table.
I have been using the following code:
private Spinner mSpinner;
mSpinner = (Spinner) findViewById(R.id.spinCat);
and in my populate fields method I have the following:
mSpinner.getSelectedItem();
but this stores something like "android.database.sqlite.SQLiteCursor#43e5be60" in to the database rather than the name.
If anyone can offer some help it would be great, this has been bothering me for some days now and has halted development somewhat. If you need to see more code, then please don't hesitate to ask.
Any help is much appreciated.
EDIT: new code:
mSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View vw,
int pos, long id) {
LinearLayout rowll = (LinearLayout) vw;
TextView test = (TextView) rowll.getChildAt(0);
Toast t = Toast.makeText(parent.getContext(), test
.getText().toString(), Toast.LENGTH_SHORT);
t.show();
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// Do nothing..
}
});
getSelectedItem returns an Object (which is what your output looks a lot like).
Did you try simply calling toString like this?
mSpinner.getSelectedItem().toString();
I personally just set a variable in the onItemSelected listener, but this should work too. What I use is:
#Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
myIP = parent.getItemAtPosition(position).toString();
}
Variable is then continuously updated and I just add it to the DB when I connect to the IP in question.
Cursor data extraction:
while (cursor.moveToNext()) {
ipList.add(cursor.getString(1));
}
getString(int columnIndex) does: Returns the value of the requested column as a String.
http://developer.android.com/reference/android/database/Cursor.html
Don't use .getChildAt(), use .getItemAtPositon(). See how the code does it at http://developer.android.com/resources/tutorials/views/hello-spinner.html.