Button Listener not get registered on first click In android

后端 未结 3 1623
死守一世寂寞
死守一世寂寞 2021-01-22 00:36

As i am new to android here i got the problem for button listeners I am using OnClickListener for busttons but it doesnot performs after first click once i clic

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-22 00:59

    **

    try this

    **

     public class DashbordActivity extends Activity {
    
    ImageButton btnLogout, btnSearch, btnOENew, btnAENew,btnSync;
    // Session Manager Class
    SessionManager session = null;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dashbord_activity);
    
    // Session Manager
    session = new SessionManager(getApplicationContext());
    
    /* Action Bar Color change on create*/
    ColorDrawable colorDrawable = new ColorDrawable(Color.parseColor("#FF7F24"));
    ActionBar actionBar = getActionBar();
    actionBar.setBackgroundDrawable(colorDrawable);
    
    /* get Resources from Xml  file */
    btnOENew = (ImageButton) findViewById(R.id.btnOENew);
    btnAENew = (ImageButton) findViewById(R.id.btnAENew);
    btnSearch = (ImageButton) findViewById(R.id.btnSearch);     
    btnLogout = (ImageButton) findViewById(R.id.btnLogout);
    btnSync = (ImageButton)findViewById(R.id.btnSync);
     btnOENew.setOnClickListener(new OnClickListener() {         
        public void onClick(View v) {
            Intent intent = new Intent(getBaseContext(),           OceanSalesActivity.class);
            startActivity(intent);
        }
    });
    
    btnAENew.setOnClickListener(new OnClickListener() {         
        public void onClick(View v) {
            Intent intent = new Intent(getBaseContext(), AirSalesActivity.class);
            startActivity(intent);
        }
    });
    
    btnSearch.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getBaseContext(), SearchActivity.class);
            startActivity(intent);
        }
    });
    
    
    btnLogout.setOnClickListener(new OnClickListener() {            
        public void onClick(View v) {               
            onLogout();
        }
    });
    
    btnSync.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent( getBaseContext() , SyncActivity.class);                                                
            startActivity(intent);
        }
    });
    
    
    
    }
    

提交回复
热议问题