Need to make another EditText and Button, but dont know where to put it in java file so it does the same function

时间:2019-01-07 13:55:59

标签: copying

I have created second EditText and second Button there but I dint know where to put code about second EditText and button in java file?

enter code herepackage com.example.martins.dailytask;

import android.content.Context;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    EditText textView;
    Button button;
    EditText textView2;
    Button button2;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        textView = (EditText) findViewById(R.id.textView);
        button = (Button) findViewById(R.id.button);



        final SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);
        String oldItem = sharedPref.getString("oldItem", "Nothing created yet");


    textView.setText(oldItem);

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            SharedPreferences.Editor editor = sharedPref.edit();
            editor.putString("oldItem", textView.getText().toString());
            editor.commit();

            Animation animation = new AlphaAnimation(1.0f, 0.0f);
            animation.setDuration(700);
            button.startAnimation(animation);

        }



    });
   }
}

0 个答案:

没有答案