I want to create a menu the item, where when the item is clicked then he will disappears temporarily. as an example: I make a menu GpsOn and GpsOff, if the GpsOn clicked then he would disappears and the only remaining GpsOff, and conversely. is there any tutorial or code that can help me??
My Code :
#Override
public boolean onPrepareOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
if(isGpsOn){menu.getItem(MENU_GpsOn).setVisible(false);menu.getItem(MENU_GpsOff).setVisible(true);}
else { menu.getItem(MENU_GpsOn).setVisible(true);menu.getItem(MENU_GpsOff).setVisible(false);}
return super.onPrepareOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
session = new SessionManager(getApplicationContext());
session.checkLogin();
HashMap<String, String> user = session.getUserDetails();
String name = user.get(SessionManager.KEY_NAME);
switch (item.getItemId()) {
case MENU_Secure:
try {
sendSMS(name, "secure");
} catch (Exception e) {
Toast.makeText(this, "Gagal karena " + e.toString(),
Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
return(true);
case MENU_Unsecure:
try {
sendGPS(name, "notsec");
} catch (Exception e) {
Toast.makeText(this, "Gagal karena " + e.toString(),
Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
return(true);
case MENU_GpsOn:
try {
sendMobil(name, "gps on");
} catch (Exception e) {
Toast.makeText(this, "Gagal karena " + e.toString(),
Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
isGpsOn=true;
// ((MenuItem)findViewById(MENU_GpsOff)).setVisible(false);
return(true);
case MENU_GpsOff:
try {
sendGPSOff(name, "gpsoff");
} catch (Exception e) {
Toast.makeText(this, "Gagal karena " + e.toString(),
Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
isGpsOn=false;
return(true);
}
return(super.onOptionsItemSelected(item));
}
Try this,
public boolean checkHide = false
#Override
public boolean onOptionsItemSelected(MenuItem item){
switch(item.getItemId()){
case GPS:
if(checkHide){
checkHide=false;
item.setTitle("GPS_ON");
// ToDo your function
}
else{
checkHide=true;
item.setTitle("GPS_OFF");
// ToDo your function
}
}
What I think you need is Toggle Button. To create one such button, take a look at this tut here, as well as this one and this one.
This is of course, if I understood your requirements correctly.
Related
I am developing an app. My goal is that user can login online and offline both, but for the first time user should login online enters their credentials (userid and password) and save the user's credentials when user is valid for offline mode(remote location where internet is not available). To check the credentials I used a webservice which will check that user id and password whether valid or not. I am able to consume webservice, its also check whether user is valid or not and able to save the userid and encrypted password and also achieve to compare passwrod with store password in database. But the problem I am facing is that when the userid or password is not correct it saves the credentials in sqlite database. And when I'm on offline mode I can login with incorrect password. I don't want that I want it saves credential only when user is authenticated. Below I shared my code. Need help I don't get it in where line I have to call offline method. Thanks in advance.
Fuction for Login Button:
login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// preventing double, using threshold of 1000 ms
if (SystemClock.elapsedRealtime() - lastClickTimeBtnLogin < Utilities.BTN_DOUBLE_CLICK_STOP_TIME) {
return;
}
lastClickTimeBtnLogin = SystemClock.elapsedRealtime();
//
// Login Logic
try {
String mail = email.getText().toString().trim();
String pwd = password.getText().toString().trim();
if (iCD.checkMobileInternetConn()) {
if (isLocationEnabled) {
//
if (mail.equals("")) {
Toast.makeText(getApplicationContext(), "Please enter UserName", Toast.LENGTH_SHORT).show();
} else if (pwd.equals("")) {
Toast.makeText(getApplicationContext(), "Please enter Password", Toast.LENGTH_LONG).show();
}
else {
if (offlineMode.isChecked()){
boolean i =global.getDb().addUser(mail,pwd);
if (i== true){
Toast.makeText(getApplicationContext(), "Inserted", Toast.LENGTH_LONG).show();
}else {
Toast.makeText(getApplicationContext(), "Not inserted", Toast.LENGTH_LONG).show();
}
}
global.setUserName(email.getText().toString().trim());
srv = new GenericServiceCalling(mContext, cb);
JSONObject obj = new JSONObject();
obj.put("userID", mail);
obj.put("password", pwd);
JSONObject mainObj = new JSONObject();
mainObj.put("value", obj);
showCustomLoader();
srv.execute(Utilities.LOGIN, mainObj.toString());
}
} else {
Toast.makeText(getApplicationContext(), "Enable location", Toast.LENGTH_LONG).show();
}
}
//
else {
offlineLogin();
}
}
catch (JSONException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
//
}
}
});
Check response code==200:
#Override
public void onTaskComplete(String result) {
mCustomLoader.dismiss();
Log.e(TAG, "Response from url: " + result);
String[] resultResponse = result.split("\\|", 2);
int responseCode = Integer.valueOf(resultResponse[0].trim());
String responseBody = resultResponse[1].trim();
if (responseCode == 200) {
try {
JSONObject jsonObj = new JSONObject(responseBody);
if (jsonObj.has("LoginResult")){
parseLoginResult(jsonObj);
}
else {
}
} catch (final JSONException e) {
Log.e(TAG, "Json parsing error: " + e.getMessage());
runOnUiThread(new Runnable() {
#Override
public void run() {
Toast.makeText(getApplicationContext(),
"Json parsing error: " + e.getMessage(),
Toast.LENGTH_LONG).show();
}
});
}
}
else {
if(responseCode == Utilities.EXCEPTION_RESPONSE_CODE){
showCustomAlertOneBtn("Alert", "Something wrong Response Code: "+responseCode+" = "+responseBody );
}
else{
showCustomAlertOneBtn("Alert", "Internal server error. ResponseCode : "+responseCode +" Message "+ responseBody );
}
}
}
private void parseLoginResult(JSONObject object) {
try {
if(object.getString("LoginResult").equals("null")){
mCustomLoader.dismiss();
Log.e(TAG, "Authenticaion Failed" );
runOnUiThread(new Runnable() {
#Override
public void run() {
Toast.makeText(getApplicationContext(),
"Authenticaion Failed",
Toast.LENGTH_LONG).show();
}
});
}else {
if(object.getJSONObject("LoginResult").getString("responseCode").equals("200")) {
Intent intent = new Intent(MainActivity.this, list.class);
startActivity(intent);
}
else{
Toast.makeText(getApplicationContext(), object.getJSONObject("LoginResult").getString("responseMessage"),
Toast.LENGTH_LONG).show();
}
}
}catch (final JSONException e) {
mCustomLoader.dismiss();
Log.e(TAG, "Json parsing error: " + e.getMessage());
runOnUiThread(new Runnable() {
#Override
public void run() {
Toast.makeText(getApplicationContext(),
"Json parsing error: " + e.getMessage(),
Toast.LENGTH_LONG).show();
}
});
}catch (Exception e) {
mCustomLoader.dismiss();
Log.e(TAG, "Exception Occur: " + e.getMessage());
runOnUiThread(new Runnable() {
#Override
public void run() {
Toast.makeText(getApplicationContext(),
"Exception Occur: " + e.getMessage(),
Toast.LENGTH_LONG).show();
}
});
}
}
offline login Method:
public void offlineLogin(){
iCD.hideCustomAlert();
if (isLocationEnabled) {
String mail = email.getText().toString().trim();
String pwd = password.getText().toString().trim();
String pwd1 = md5(pwd);
if (mail.equals("")) {
Toast.makeText(getApplicationContext(), "Please enter UserName", Toast.LENGTH_SHORT).show();
} else if (pwd.equals("")) {
Toast.makeText(getApplicationContext(), "Please enter Password", Toast.LENGTH_LONG).show();
}
else{
Boolean res = global.getDb().checkUser(mail, pwd1);
// Boolean res = helper.checkUser(mail, pwd1);
if(res == true) {
Intent intent = new Intent(MainActivity.this, list.class);
startActivity(intent);
Toast.makeText(MainActivity.this, "Successfully Logged In", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "Login Error",
Toast.LENGTH_SHORT).show();
}
}
} else {
Toast.makeText(MainActivity.this, "enabled Location",
Toast.LENGTH_SHORT).show();
}
}
1> if (id == R.id.action_settings) {
return true;
}
// I am getting red text on action_settings
2> getMenuInflater().inflate(R.menu.homepage, menu);
// here i am getting red text on homepage
I had reused the following code but getting red text over those two lines of code
<Homepage.java>
tManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
tManager.listen(new CustomPhoneStateListener(this),
PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.homepage, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
This is the class file related to above file
<CustomPhoneStateListener.java>
public CustomPhoneStateListener(Context context) {
mContext = context;
}
#Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
super.onSignalStrengthsChanged(signalStrength);
Log.i(LOG_TAG, "onSignalStrengthsChanged: " + signalStrength);
if (signalStrength.isGsm()) {
Log.i(LOG_TAG, "onSignalStrengthsChanged: getGsmBitErrorRate "
+ signalStrength.getGsmBitErrorRate());
Log.i(LOG_TAG, "onSignalStrengthsChanged: getGsmSignalStrength "
+ signalStrength.getGsmSignalStrength());
} else if (signalStrength.getCdmaDbm() > 0) {
Log.i(LOG_TAG, "onSignalStrengthsChanged: getCdmaDbm "
+ signalStrength.getCdmaDbm());
Log.i(LOG_TAG, "onSignalStrengthsChanged: getCdmaEcio "
+ signalStrength.getCdmaEcio());
} else {
Log.i(LOG_TAG, "onSignalStrengthsChanged: getEvdoDbm "
+ signalStrength.getEvdoDbm());
Log.i(LOG_TAG, "onSignalStrengthsChanged: getEvdoEcio "
+ signalStrength.getEvdoEcio());
Log.i(LOG_TAG, "onSignalStrengthsChanged: getEvdoSnr "
+ signalStrength.getEvdoSnr());
}
try {
Method[] methods = android.telephony.SignalStrength.class
.getMethods();
for (Method mthd : methods) {
if (mthd.getName().equals("getLteSignalStrength")
|| mthd.getName().equals("getLteRsrp")
|| mthd.getName().equals("getLteRsrq")
|| mthd.getName().equals("getLteRssnr")
|| mthd.getName().equals("getLteCqi")) {
Log.i(LOG_TAG,
"onSignalStrengthsChanged: " + mthd.getName() + " "
+ mthd.invoke(signalStrength));
}
}
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
**The above code is related to measure signal **
Did you rebuild/clean the project? try build->clean project. make sure you also have these resources in the respective folders i.e. homepage.xml in your res/menu folder and should have an item with i.d action_settings
I understand that a similar question has been asked but I am seriously stuck on this problem.
When I close the application, it says "Saving Data" which means my on stop method is being called but when I re open the app, it fails to mention that it is "getting data" meaning my onStart method is not being called.
The middle block of code seems to be the most important, I just wanted to include all of it so that if someone were to bump into my situation again, they could see everything.
How do I use the sharedpreferences class in this situation to save the background color and call the onStart method when I reopen the application?
As of now, it always resorts to the default Colour.
Thank you for your time.
EditText ed;
String background_color;
String Color_Value;
String Message;
int datablock =100;
int selectedItem;
int Color_Position;
int change=0;
View root;
View someView;
SharedPreferences prefer;
SharedPreferences.Editor prefer_edit;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_check_box);
ActionBar bar = getActionBar();
bar.setDisplayShowTitleEnabled(false);
bar.setDisplayShowHomeEnabled(false);
//Hides app title and icon
if (Color_Value!= null){
onStart();
}
else {
}
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
//Creates a spinner
ed = (EditText)findViewById(R.id.edit);
final String[] dropdown = getResources().getStringArray(R.array.Colors);
ArrayAdapter <String> adapter = new ArrayAdapter<String>(bar.getThemedContext(),
android.R.layout.simple_spinner_item,android.R.id.text1,dropdown);
//sets up the drop down navigation list in the action bar
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
bar.setListNavigationCallbacks(adapter, new OnNavigationListener(){
#Override
public boolean onNavigationItemSelected(int selectedItem, long arg1) {
//Java always starts counting at zero
if (selectedItem == 0){
someView = findViewById(R.id.layout);
root = someView.getRootView();
root.setBackgroundColor((Color.parseColor("#005640")));
Color_Position =Color.parseColor("#005640");
//prefer_edit.putInt("background_color", ((Color.parseColor("#005640"))));
Toast.makeText(getBaseContext(), "Color Changed", Toast.LENGTH_SHORT).show();
Log.i("At", "Position "+selectedItem);
}
else if (selectedItem == 1){
someView = findViewById(R.id.layout);
root = someView.getRootView();
root.setBackgroundColor((Color.parseColor("#045345")));
Color_Position =Color.parseColor("#045345");
//prefer_edit.putInt("background_color", ((Color.parseColor("#045345"))));
Toast.makeText(getBaseContext(), "Color Changed", Toast.LENGTH_SHORT).show();
Log.i("At", "Position "+selectedItem);
}
else if (selectedItem == 2){
someView = findViewById(R.id.layout);
root = someView.getRootView();
Color_Position =Color.parseColor("#384355");
root.setBackgroundColor((Color.parseColor("#384355")));
//prefer_edit.putInt("background_color", ((Color.parseColor("#384355"))));
Toast.makeText(getBaseContext(), "Color Changed", Toast.LENGTH_SHORT).show();
Log.i("At", "Position "+selectedItem);
}
else if (selectedItem == 3){
someView = findViewById(R.id.layout);
root = someView.getRootView();
Color_Position =Color.parseColor("#990088");
root.setBackgroundColor((Color.parseColor("#990088")));
//prefer_edit.putInt("background_color",((Color.parseColor("#990088"))));
Toast.makeText(getBaseContext(), "Color Changed", Toast.LENGTH_SHORT).show();
Log.i("At", "Position "+selectedItem);
}
else if (selectedItem == 4){
someView = findViewById(R.id.layout);
root = someView.getRootView();
Color_Position =Color.parseColor("#026211");
root.setBackgroundColor((Color.parseColor("#026211")));
// prefer_edit.putInt("background_color", (Color.parseColor("#026211")));
Toast.makeText(getBaseContext(), "Color Changed", Toast.LENGTH_SHORT).show();
Log.i("At", "Position "+selectedItem);
}
return true;
}
});
}
public void onStart(){
super.onStart();
Log.i("Getting Data", "Color is equal to "+Color_Position);
SharedPreferences prefer = getSharedPreferences(Color_Value,0);
prefer.getInt(background_color, 0);
}
public void onStop(){
super.onStop();
Log.i("Saving Data", "Color is equal to "+Color_Position);
SharedPreferences prefer = getSharedPreferences(Color_Value, 0);
SharedPreferences.Editor prefer_edit = prefer.edit();
prefer_edit.putInt(background_color, Color_Position);
prefer_edit.commit();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.check_box, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case
R.id.action_settings:
//Pass data between activities here
break;
case
R.id.action_save:
SaveData();
break;
case
R.id.action_error:
LoadData();
break;
case
R.id.action_edit:
ChangeTextColor(change);
change++;
break;
}
return true;
}
public void SaveData(){
Message =ed.getText().toString();
try {
FileOutputStream out = openFileOutput("text.txt", MODE_PRIVATE);
OutputStreamWriter output = new OutputStreamWriter(out);
try{
output.write(Message);
output.flush();
output.close();
Toast.makeText(getBaseContext(), "Save successful", Toast.LENGTH_SHORT).show();
}
catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void LoadData(){
try {
FileInputStream fis = openFileInput("text.txt");
InputStreamReader ins = new InputStreamReader(fis);
//Deserialize the file
char[] Data = new char [datablock];
String final_data ="";
int size;
try {
while((size = ins.read(Data))>0){
String read_data = String.copyValueOf(Data, 0 ,size);
final_data+=read_data;
Data = new char[datablock];
}
Toast.makeText(getBaseContext(), "Message : " + final_data, Toast.LENGTH_SHORT).show();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//Methods galore!
public void ChangeTextColor(int change){
if ((change % 2) == 0) {
// number is even
ed.setHint("enter a message to save");
ed.setTextColor(getResources().getColor(android.R.color.holo_red_dark));
Toast.makeText(getApplicationContext(), "Text color changed to red", Toast.LENGTH_LONG).show();
change++;
}
else {
// number is odd
ed.setHint("enter a message to save");
ed.setTextColor(getResources().getColor(android.R.color.black));
Toast.makeText(getApplicationContext(), "Text color changed to black", Toast.LENGTH_LONG).show();
change++;
}
}
}
onStart is called after onCreate, please remove this
if (Color_Value!= null){
onStart();
}
else {
}
and you can retrieve the color fron SharedPreferences directly in onCreate.
I'm loading a text file into an EditText but the file only gets partially loaded. I've tried two different files and get the same result. One file gets cut off halfway through line 35 and the other line 37. No idea why.
<com.mobilewebtoolkit.EditTextLineNumbers
android:id="#+id/ide"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:ems="10"
android:gravity="left"
android:inputType="textMultiLine"
android:lineSpacingExtra="5dp"
android:textSize="15sp"
android:visibility="visible" >
code:
private void openFile(final File aFile) {
String nullChk = et.getText().toString();
if (!changed || nullChk.matches("")) {
try {
currentFile = aFile;
getExt();
et.setText(new Scanner(currentFile).useDelimiter("\\Z").next());
changed = false;
exists = true;
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Save first?");
alert.setMessage("(Will be saved in the current working directory)");
alert.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
String temptxt = et.getText().toString();
if (currentFile.exists()) {
try {
saveFile(currentFile.getPath(), temptxt);
currentFile = aFile;
getExt();
} catch (NullPointerException e) {
Log.i("NullPointer", currentFile.getName());
}
try {
et.setText(new Scanner(currentFile)
.useDelimiter("\\Z").next());
getExt();
if (extension.equals("txt")) {
Toast.makeText(MainActivity.this,
"Extension: " + extension,
Toast.LENGTH_LONG).show();
} else if (extension.equals("html")
|| extension.equals("htm")) {
Toast.makeText(MainActivity.this,
"Extension: " + extension,
Toast.LENGTH_LONG).show();
} else if (extension.equals("css")) {
Toast.makeText(MainActivity.this,
"Extension: " + extension,
Toast.LENGTH_LONG).show();
} else if (extension.equals("js")) {
Toast.makeText(MainActivity.this,
"Extension: " + extension,
Toast.LENGTH_LONG).show();
} else if (extension.equals("php")) {
Toast.makeText(MainActivity.this,
"Extension: " + extension,
Toast.LENGTH_LONG).show();
} else if (extension.equals("xml")) {
Toast.makeText(MainActivity.this,
"Extension: " + extension,
Toast.LENGTH_LONG).show();
}
changed = false;
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
saveAs(null);
}
}
});
final File tempFile = aFile;
alert.setNegativeButton("No",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
try {
et.setText(new Scanner(tempFile).useDelimiter(
"\\Z").next());
changed = false;
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
changed = false;
}
});
alert.setNeutralButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
changed = true;
dialog.cancel();
}
});
alert.show();
}
}
You should iterate over your Scanner until hasNext() return false to make sure the whole file is read. See more information here: Beware of using java.util.Scanner with ā/zā
StringBuilder sb = new StringBuilder();
Scanner scanner = new Scanner(tempFile).useDelimiter("\\Z");
while (scanner.hasNext()) {
sb.append(scanner.next());
}
et.setText(sb);
Firstly I wan't you to know that I search really hard for my problem but I found nothing ...
I can't connect to sql server express instance with android application however I try to connect with jdbc:jtds:sqlserver the driver of sourceforge.
I don't forget to add this line in the manifest file :
<uses-permission android:name="android.permission.INTERNET" />
And the error message is Unable to get information from sql server :HostName
Here my source code perhaps there is something wrong :
public class MainActivitySF extends Activity {
private Connection connection;
private Statement statement;
private ResultSet resultat;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void OnClick(View v) {
TextView tv = (TextView) findViewById(R.id.textView1);
EditText ehost = (EditText) findViewById(R.id.ehost);
EditText eport = (EditText) findViewById(R.id.eport);
EditText ebase = (EditText) findViewById(R.id.ebase);
EditText euser = (EditText) findViewById(R.id.euser);
EditText epasswd = (EditText) findViewById(R.id.epasswd);
switch (v.getId()) {
case R.id.Connection:
try {
Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
} catch (InstantiationException e){
Toast.makeText(this, "Instantiation failled",
Toast.LENGTH_LONG).show();
return;
} catch (ClassNotFoundException e1) {
Toast.makeText(this, "Instantiation failled",
Toast.LENGTH_LONG).show();
return;
} catch(IllegalAccessException e2){
Toast.makeText(this, "Instantiation failled",
Toast.LENGTH_LONG).show();
return;
}
try {
String connString = "jdbc:jtds:sqlserver://"+ehost.getText().toString()+"" +
":"+eport.getText().toString()+"/"+ebase.getText().toString()+"" +
";encrypt=false;user="+euser.getText().toString()+";" +
"password="+epasswd.getText().toString()+";instance=SQLEXPRESS;";
String username = euser.getText().toString();
String password = epasswd.getText().toString();
connection = DriverManager.getConnection(connString,username,password);
} catch (SQLException e) {
connection = null;
Toast.makeText(this, "connection failled",
Toast.LENGTH_LONG).show();
tv.setText(e.getLocalizedMessage());
return;
}
tv.setText("connection OK !!");
break;
case R.id.statement:
try {
statement = connection.createStatement();
} catch (SQLException e) {
statement=null;
Toast.makeText(this, "statement failled",
Toast.LENGTH_LONG).show();
return;
}
tv.setText("statement OK !!");
break;
case R.id.req:
try {
resultat = statement.executeQuery(
"SELECT * FROM produits");
tv.setText(resultat.getString("LIB_PRODUIT")+ " OK !!");
} catch (SQLException e) {
Toast.makeText(this, "req failled",
Toast.LENGTH_LONG).show();
return;
}
break;
default:
break;
}
}
}