项目之间的跳转

Main5Activity.java 代码如下:

//每点击一次按钮,Button都会+1;
public class Main5Activity extends AppCompatActivity {
    private Button button;
    private TextView textView;
    private Button button1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main5);

        button=findViewById(R.id.button);
        textView=findViewById(R.id.textView);
        button1=findViewById(R.id.button1);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(Main5Activity.this,"sll",Toast.LENGTH_LONG).show();
                textView.setText(String.valueOf(Integer.parseInt((String)textView.getText())+1));
            }
        });
        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent =new Intent(Main5Activity.this,Main3Activity.class);
                intent.putExtra("data","hello world");
                startActivity(intent);
            }
        });
    }
}

activity_main5.xml 代码如下:



    

    

Main3activity.java 代码如下:


public class Main3Activity extends AppCompatActivity {

    private EditText editText;
    private ImageView imageView;
    private TextView textView;
    private ProgressBar progressBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);
        Button button = (Button) findViewById(R.id.button);
        editText = (EditText) findViewById(R.id.edit_text);
        imageView =(ImageView) findViewById(R.id.image_View);
        progressBar=(ProgressBar)findViewById(R.id.progress_bar);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()){
                    case R.id.button:
                        imageView.setImageResource(R.drawable.banbana);
                        AlertDialog.Builder dialog=new AlertDialog.Builder(Main3Activity.this);
                        dialog.setTitle(" not allow");
                        dialog.setMessage("Loading...");
                        dialog.setCancelable(true);
                        dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                            }
                        });
                       dialog.setPositiveButton("Cancel", new DialogInterface.OnClickListener() {
                           @Override
                           public void onClick(DialogInterface dialog, int which) {
                           }
                       });
                       dialog.show();
                        int progress=progressBar.getProgress();
                        progress=progress+10;
                        progressBar.setProgress(progress);
                        if (progressBar.getVisibility()==View.GONE){
                            progressBar.setVisibility(View.VISIBLE);
                        }else {
                            progressBar.setVisibility(View.GONE);
                        }
                        break;
                        default:
                            break;
                }
            }
        });

        String s=getIntent().getStringExtra("data");
    }
    }

activity_main3.xml 代码如下:


    

    

你可能感兴趣的:(项目之间的跳转)