android


pass the spinner selected value to mysql using php from response in android


Hi In My Application I have two spinners class and section names displaying with date and one submit Button. After click the submit button the class name,section Name,date available in database or not.If Exist I want response from php.
I tested this code by using toast message it showing whatever I selected data displaying.
Can any one please help me how to resolve this issues.
Attendance.class
public class Attendance extends Activity implements OnClickListener {
private EditText fromDateEtxt;
private DatePickerDialog fromDatePickerDialog;
private SimpleDateFormat dateFormatter;
InputStream is = null;
String result = null;
String line = null;
int class_id;
//String className = "";
String sectionName = "";
String[] class_name, section_name;
Spinner classSpinner, sectionSpinner;
private Map<String, Set<String>> classSectionMap = new HashMap<String, Set<String>>();
#TargetApi(Build.VERSION_CODES.GINGERBREAD)
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
}
// Spinner element
classSpinner = (Spinner) findViewById(R.id.spinner);
sectionSpinner = (Spinner) findViewById(R.id.spinner1);
Button submit = (Button) findViewById(R.id.button1);
submit.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(AndroidSpinnerExampleActivity.this,
"Result : " +
"\nclassName : "+ String.valueOf(classSpinner.getSelectedItem()) +
"\nSectionName : "+ String.valueOf(sectionSpinner.getSelectedItem()),
Toast.LENGTH_SHORT).show();
}
});
dateFormatter = new SimpleDateFormat("dd-MM-yyyy", Locale.US);
findViewsById();
setDateTimeField();
// Spinner click listener
// spinner.setOnItemSelectedListener(this);
// Spinner Drop down elements
final List<String> list1 = new ArrayList<String>();
final List<String> list2 = new ArrayList<String>();
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(
"http://10.0.2.2/android_connect/getuser.php");
HttpResponse response = httpclient.execute(httppost);
Log.e("Fail 1", "3");
HttpEntity entity = response.getEntity();
Log.e("Fail 1", "4");
is = entity.getContent();
Log.e("Pass 1", "connection success ");
} catch (Exception e) {
Log.e("Fail 1", e.toString());
Toast.makeText(getApplicationContext(), "Invalid IP Address",
Toast.LENGTH_LONG).show();
finish();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result = sb.toString();
} catch (Exception e) {
Log.e("Fail 2", e.toString());
}
try {
JSONArray JA = new JSONArray(result);
JSONObject json = null;
class_name = new String[JA.length()];
section_name = new String[JA.length()];
String className = "";
String sectionName = "";
Set<String> sections;
for (int i = 0; i < JA.length(); i++) {
json = JA.getJSONObject(i);
// class_name[i] = json.getString("class_name");
// section_name[i]=json.getString("section_name");
className = json.getString("class_name");
sectionName = json.getString("section_name");
//Toast.makeText(getApplicationContext(), "classname"+sectionName, Toast.LENGTH_LONG).show();
if (classSectionMap.containsKey(className)) {
sections = classSectionMap.get(className);
} else {
sections = new HashSet<String>();
//Toast.makeText(getApplicationContext(), "classname"+className, Toast.LENGTH_LONG).show();
}
sections.add(sectionName);
classSectionMap.put(className, sections);
}
Set<String> classKeys = classSectionMap.keySet();
class_name = classKeys.toArray(new String[classKeys.size()]);
Set<String> sectionkeys = classSectionMap.get(class_name[0]);
if (sectionkeys != null) {
section_name = sectionkeys.toArray(new String[sectionkeys
.size()]);
}
/*
* for(int i=0;i<class_name.length;i++) { list1.add(class_name[i]);
* list2.add(section_name[i]);
*
* }
*/
spinner_fn();
} catch (Exception e) {
Log.e("Fail 3", e.toString());
e.printStackTrace();
// login.this.finish();
}
}
private void spinner_fn() {
// TODO Auto-generated method stub
ArrayAdapter<String> dataAdapter1 = new ArrayAdapter<String>(
getApplicationContext(), android.R.layout.simple_spinner_item,
class_name);
dataAdapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
classSpinner.setAdapter(dataAdapter1);
classSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int position, long id) {
Log.e("Position new", class_name[position]);
Set<String> sectionkeys = classSectionMap
.get(class_name[position]);
if (sectionkeys != null) {
section_name = sectionkeys.toArray(new String[sectionkeys
.size()]);
//Toast.makeText(getApplicationContext(), "sectionName"+section_name, Toast.LENGTH_LONG).show();
}
ArrayAdapter<String> dataAdapter2 = new ArrayAdapter<String>(
getApplicationContext(), android.R.layout.simple_spinner_item,
section_name);
dataAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sectionSpinner.setAdapter(dataAdapter2);
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
sectionSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View arg1,
int position, long arg3) {
// TODO Auto-generated method stub
// spinner.setSelection(position);
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}
private void findViewsById() {
fromDateEtxt = (EditText) findViewById(R.id.etxt_fromdate);
fromDateEtxt.setInputType(InputType.TYPE_NULL);
fromDateEtxt.requestFocus();
// toDateEtxt = (EditText) findViewById(R.id.etxt_todate);
// toDateEtxt.setInputType(InputType.TYPE_NULL);
}
private void setDateTimeField() {
fromDateEtxt.setOnClickListener(this);
// toDateEtxt.setOnClickListener(this);
Calendar newCalendar = Calendar.getInstance();
fromDatePickerDialog = new DatePickerDialog(this,
new OnDateSetListener() {
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
Calendar newDate = Calendar.getInstance();
newDate.set(year, monthOfYear, dayOfMonth);
fromDateEtxt.setText(dateFormatter.format(newDate
.getTime()));
}
}, newCalendar.get(Calendar.YEAR),
newCalendar.get(Calendar.MONTH),
newCalendar.get(Calendar.DAY_OF_MONTH));
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
#Override
public void onClick(View view) {
if (view == fromDateEtxt) {
fromDatePickerDialog.show();
}
}
Thanks In Advance

Related Links

How can I change style of views dynamically? [duplicate]
Espresso.onData set inAdapterView to be AlertDialog
Android External storage handle unavailability
Does FirebaseDatabase Auto-Manage its Connection?
error while installing vs android emulator for visual surdio 2015
Creating and inserting into a database [duplicate]
how to solve error Xamarin Android player Beta has expired ,Please update
Unity play video on Android
Data on fragment is not loaded when i implement toolbar
Firebase Manage Multiple auth provider
Android SeekBar Error. while playing music.?
Myo android first connection
Is it possible to make onBackPressed only for activity but not for the fragments containg it?
requestLocationUpdates does nothing
I am getting java.io.FileNotFoundException when try to capture the screen
Not getting API response after 1K Live active users on android App

Categories

HOME
scikit-learn
prism
jax-rs
components
gradient
replace
aws-cli
scripting
pyqt4
nested-if
iis-6
elasticsearch-5
discrete-mathematics
extjs4.2
google-chrome-app
fhir
rtf
comsol
mongodb-csharp
easyphp
database-connection
microsoft-ocr
asciidoctor-pdf
visual-glitch
rubymotion
r-mice
angular-routing
joptionpane
php-mysqlidb
exploit
expressionengine3
ms-access-web-app
jasmine-node
underscore.js
linked-data
intersystems-cache
exchangewebservices
google-earth
calculation
panoramas
linkedhashmap
jett
joomla2.5
protege4
playframework-2.1
git-rewrite-history
sessionstorage
branching-and-merging
softmax
claims
show-hide
ntvs
rserve
page-replacement
semantic-logging
ngmaterial
oozie-coordinator
atlas
grails-plugin
pacemaker
lean
refinerycms
jtwig
project-organization
realsense
concept-insights
atan2
java-money
themoviedb-api
pax-exam
ember-cli-rails
finalbuilder
zscript
entity-framework-4.3
android-broadcast
user-permissions
android-cookiemanager
uncaught-typeerror
jbake
android-vibration
filesplitting
strawberry-perl
xml-namespaces
unix-socket
gae-quotas
clickbank
high-resolution
bin
workitem
pagedown
cuda-gdb
procedures
jquery-tools
vs-android
dsl-tools
lobo-cobra

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App