Android Open Source - AndroidStudioProjects My Activity






From Project

Back to project page AndroidStudioProjects.

License

The source code is released under:

GNU General Public License

If you think the Android project AndroidStudioProjects listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.tictactoe.smashkun.tictacandroid;
/*from  w w w .j ava 2s  .  c om*/
import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;


public class MyActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);
        if (savedInstanceState == null) {
            getFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment())
                    .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.my, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_guardar) {
            try {
                OutputStreamWriter fout =
                        new OutputStreamWriter(
                                openFileOutput("test.txt", Context.MODE_PRIVATE));
                EditText edit = (EditText) findViewById(R.id.cuadroTexto);
                String palabra = edit.getText().toString();
                fout.write(palabra);
                fout.close();

                Toast toast1 =
                        Toast.makeText(getApplicationContext(),
                                "Guardado", Toast.LENGTH_SHORT);
                toast1.show();
            } catch (Exception ex) {
                Log.e("Ficheros", "Error al escribir fichero a memoria interna");
            }
            return true;
        }
        if (id == R.id.action_cargar) {
            try {
                BufferedReader fin = new BufferedReader(new InputStreamReader(openFileInput("test.txt")));
                String texto = fin.readLine();
                EditText edit = (EditText) findViewById(R.id.cuadroTexto);
                edit.setText(texto);
                fin.close();

                Toast toast2 =
                        Toast.makeText(getApplicationContext(),
                                "Cargado", Toast.LENGTH_SHORT);
                toast2.show();
            } catch (Exception ex) {
                Log.e("Ficheros", "Error al leer fichero desde memoria interna");
            }
            return true;
        }
        return super.onOptionsItemSelected(item);
        /**
         * A placeholder fragment containing a simple view.
         */
    }
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_my, container, false);
            return rootView;
        }
    }
}




Java Source Code List

com.buttoms.cfgs.aplicationwithbuttoms.ApplicationTest.java
com.buttoms.cfgs.aplicationwithbuttoms.MyActivity.java
com.perritos.perritos.ApplicationTest.java
com.perritos.perritos.MyActivity.java
com.smashkun.myfirstapplication.BuildConfig.java
com.tictactoe.smashkun.tictacandroid.ApplicationTest.java
com.tictactoe.smashkun.tictacandroid.MyActivity.java