How to start new activity on button click

后端 未结 24 2259
傲寒
傲寒 2020-11-21 05:54

In an Android application, how do you start a new activity (GUI) when a button in another activity is clicked, and how do you pass data between these two activities?

24条回答
  •  没有蜡笔的小新
    2020-11-21 06:39

    Implement the View.OnClickListener interface and override the onClick method.

    ImageView btnSearch;
    
     @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_search1);
            ImageView btnSearch = (ImageView) findViewById(R.id.btnSearch);
            btnSearch.setOnClickListener(this);
        }
    
    @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.btnSearch: {
                    Intent intent = new Intent(Search.this,SearchFeedActivity.class);
                    startActivity(intent);
                    break;
                }
    

提交回复
热议问题