Skip to content

Instantly share code, notes, and snippets.

@mdsami
Created October 30, 2017 16:08
Show Gist options
  • Select an option

  • Save mdsami/93f4a3a3aaaf1f50a1bf1356c6651cba to your computer and use it in GitHub Desktop.

Select an option

Save mdsami/93f4a3a3aaaf1f50a1bf1356c6651cba to your computer and use it in GitHub Desktop.
package com.example.demoapp;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.example.demoapp.dbhelper.DBHandler;
import java.util.ArrayList;
import java.util.HashMap;
public class MainActivity extends AppCompatActivity {
Button btnSub;
Button btnEdit;
EditText et1,et2,et3,et4;
String q1,q2,q3,q4;
DBHandler db;
SharedPreferences sharedpreferences;
String student = "student";
ArrayList<HashMap<String,String>> arrProductAndDeficiencyEdit=new ArrayList<HashMap<String,String>>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et1 =(EditText)findViewById(R.id.et1);
et2 =(EditText)findViewById(R.id.et2);
et3 =(EditText)findViewById(R.id.et3);
et4 =(EditText)findViewById(R.id.et4);
btnSub = (Button) findViewById(R.id.btnSub);
btnEdit = (Button) findViewById(R.id.btnEdit);
sharedpreferences = getSharedPreferences("checklist-101", Context.MODE_PRIVATE);
q1 = sharedpreferences.getString("q1", null);
q2 = sharedpreferences.getString("q2", null);
q3 = sharedpreferences.getString("q3", null);
q4 = sharedpreferences.getString("q4", null);
q1.setText(qt1);
q2.setText(qt30);
q3.setText(qt31);
q4.setText(qt32);
btnSub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
et1 = q1.getText().toString();
et2 = q2.getText().toString();
et3 = q3.getText().toString();
et4 = q4.getText().toString();
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString("q1", q1);
editor.putString("q2", q2);
editor.putString("q3", q3);
editor.putString("q4", q4);
editor.commit();
HashMap<String,String> map1= new HashMap<String,String>();
map1.put("q1", et1+"");
map1.put("q2", et2+"");
map1.put("q3", et3+"");
map1.put("q4", et4+"");
db.InsertTable(map1, "student");
//Log.e(qt27,"db insert >"+qt27);
Intent i = new Intent(MainActivity.this, MainActivity.class);
startActivity(i);
Toast.makeText(getApplicationContext(),
"All Data Successfully Save ",
Toast.LENGTH_LONG).show();
finish();
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment