Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void onClick(View v) {
- if (v.getId()==R.id.loadDataId){
- try {
- FileInputStream fileInputStream = openFileInput("Mydata.txt");
- StringBuffer buffer = new StringBuffer();
- int read = -1;
- while ((read =fileInputStream.read())!=-1){
- buffer.append((char) read);
- }
- //get user name by indet of string
- String userName =buffer.substring(0,buffer.indexOf(" "));
- String userPass = buffer.substring(buffer.indexOf(" ")+1);
- unamrTextView.setText(userName);
- passTextView.setText(userPass);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- Toast.makeText(this, "Data retrive successfully", Toast.LENGTH_SHORT).show();
- }else if (v.getId()==R.id.gotoBackId){
- Intent intent = new Intent(SecondActivity.this,MainActivity.class);
- startActivity(intent);
- Toast.makeText(this, "Go to Main Activity", Toast.LENGTH_SHORT).show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement