Results 1 to 3 of 3
  1. #1

    Setcontentview after onClick(View v) not work back button on phone

    Hi
    After setcontetnview via onclick(view v) , success full
    But on click back button , close program and
    My Code :
    Code:
    public class ActivityEnhanced extends Activity {
    
        @Override
        protected void onResume() {
            G.currentActivity = this;
            super.onResume();
    
            if (isNetworkConnected()) {
                //setContentView(R.layout.activity_main);
    
            }
    
            View clcAbout = (View) findViewById(R.id.clcAbout);
            View clcContact = (View) findViewById(R.id.clcContact);
    
            clcAbout.setOnClickListener(oclBtn);
            clcContact.setOnClickListener(oclBtn);
        }
    
        OnClickListener oclBtn = new OnClickListener() {
    
                                   @Override
                                   public void onClick(View v) {
                                       setContentView(R.layout.activity_page);
                                       //startActivity(new Intent(currentActivity.this, ActivityEnhanced.class));
                                       final TextView txtText = (TextView) findViewById(R.id.txtText);
    
                                       Log.i("Click : ", "1" + v.getId());
                                       switch (v.getId()) {
                                           case R.id.clcAbout:
                                               txtText.setText("About");
                                               break;
                                           case R.id.clcContact:
                                               txtText.setText("Contact");
                                               break;
                                       }
                                   }
                               };
    
    
        private boolean isNetworkConnected() {
            ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo ni = cm.getActiveNetworkInfo();
            if (ni == null) {
                return false;
            } else
                return true;
        }
    }

  2. #2
    do you mean that when the user press the back button content view will be displayed?

    have you tried looking on "onbackpressed" method?

    http://developer.android.com/referen.../Activity.html



  3. #3
    just for update..

    in your androidmanifest.xml set this [android:noHistory="true"] attribute in those <activity> you want.

    then on the onbackpressed method, throw an alert dialog, to confirm closing or exiting the program, if they want to exit then put this: this.finish(); to exit.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •