2015-06-15 22 views
0

我有一個應用程序有2個活動,主要活動(HomeActivity)有一個列表與不同對象的信息,我可以點擊這個對象和一個警報對話框將會出現,可以啓動我的第二個活動(ServerConfig),它將顯示所選對象的信息以及其他一些功能,現在問題在於,當我編譯該項目並將其稱爲第一個活動時魅力,但如果我回去,然後選擇列表上的相同或其他對象,並調用這個Activity ServerConfig,它會加載並顯示新的信息,但我放在底部的按鈕不再工作,他們只是什麼都不做,這個按鈕是單獨的,但另一個LinearLayout上的按鈕工作得很好。這個應用程序的服務告訴我,當我點擊按鈕時發送了這個工作,但是沒有任何更改。安卓系統 - 當我第二次致電活動時按鈕不工作

這裏是文件:

ServerConfig活動的XML。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" > 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

      <TextView 
       android:id="@+id/serConfig_Title" 
       style="@style/textHeading" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerHorizontal="true" 
       android:text="@string/serConfig_title" /> 

      <TableLayout 
       android:id="@+id/serConfig_serDetailsTable" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/serConfig_Title" 
       android:layout_centerHorizontal="true" 
       android:padding="10dp" > 

       <TableRow> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:text="@string/serConfig_server_name" /> 

        <TextView 
         android:id="@+id/serConfig_serverName" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:text="@string/server_name_dummy" /> 
       </TableRow> 

       <TableRow> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:text="@string/serConfig_server_address" /> 

        <TextView 
         android:id="@+id/serConfig_serverAddress" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:text="@string/server_address_dummy" /> 
       </TableRow> 

       <TableRow> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:text="@string/port_title" /> 

        <TextView 
         android:id="@+id/serConfig_port" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:text="@string/port_dummy" /> 
       </TableRow> 

       <TableRow> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:text="@string/protocol_title" /> 

        <TextView 
         android:id="@+id/serConfig_protocol" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:text="@string/port_dummy" /> 
       </TableRow> 

       <TableRow> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:text="@string/notification_title" /> 

        <TextView 
         android:id="@+id/serNotif_email" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:text="@string/port_dummy" /> 

        <TextView 
         android:id="@+id/serNotif_sms" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:text="@string/port_dummy" /> 
       </TableRow> 

       <Button 
        android:id="@+id/serConfig_historyButton" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center_horizontal" 
        android:layout_marginTop="5dp" 
        android:text="@string/serConfig_hist_Butt" /> 
      </TableLayout> 

      <LinearLayout 
       android:id="@+id/serConfig_welcomeLayout" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/serConfig_serDetailsTable" 
       android:layout_marginTop="5dp" 
       android:orientation="vertical" > 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/serConfig_welcomeMsgOld" 
        android:textStyle="bold" /> 

       <TextView 
        android:id="@+id/serConfig_welcomeMsgOld" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:padding="10dp" 
        android:textIsSelectable="true" /> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/serConfig_welcomeMsg" 
        android:textStyle="bold" /> 

       <TextView 
        android:id="@+id/serConfig_welcomeMsg" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:padding="10dp" 
        android:textIsSelectable="true" /> 
      </LinearLayout> 

      <ProgressBar 
       android:id="@+id/serConfig_progBar" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/serConfig_welcomeLayout" 
       android:layout_centerHorizontal="true" 
       android:visibility="gone" /> 
     </RelativeLayout> 
    </ScrollView> 

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0" > 

     <Button 
      android:id="@+id/serConfig_connButton" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:text="@string/serConfig_conn_Butt" /> 

     <LinearLayout 
      android:id="@+id/serConfig_accpLayout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:visibility="gone" > 

      <Button 
       android:id="@+id/serConfig_accpButton" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:clickable="true" 
       android:layout_weight="1" 
       android:text="@string/serConfig_accept_Butt" /> 

      <Button 
       android:id="@+id/serConfig_rejButton" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:clickable="true" 
       android:layout_weight="1" 
       android:text="@string/serConfig_reject_Butt" /> 
     </LinearLayout> 
    </FrameLayout> 

</LinearLayout> 

部分SERVERCONFIG活動

public class ServerConfigActivityP extends Activity { 

    /** 
    * View/Helper for this Activity. 
    */ 
    private ServerConfigView m_ServerView; 
    /** 
    * Selected Server that will be display in this Activity. 
    */ 
    private ServerDetails m_SelectedServer; 
    /** 
    * Selected servers position in the DatabaseManager. 
    */ 
    private int m_ServerPosition; 

    private boolean m_serviceIsBound = false; 
    private ServerService m_service = null; 

    private static final String TAG_DEBUG ="SERVER_CONFIG_ACTIVITY"; 

    private Button AcceptButton,RejectButton,ConnectButton,HistoryButton; 
    /** 
    * Activity life cycle onCreate. 
    * 
    * Gets the ServerDetails that we are going to use for this Activity. 
    * Display the information of the selected ServerDetails. 
    * 
    * @see Activity 
    */ 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.layout_server_config_activity_p); 


     this.AcceptButton = (Button) findViewById(R.id.serConfig_accpButton); 
     this.RejectButton =(Button) findViewById(R.id.serConfig_rejButton); 
     this.ConnectButton= (Button) findViewById(R.id.serConfig_connButton); 
     this.HistoryButton =(Button) findViewById(R.id.serConfig_historyButton); 

     AcceptButton.setOnClickListener(myListener); 
     RejectButton.setOnClickListener(myListener); 
     ConnectButton.setOnClickListener(myListener); 
     HistoryButton.setOnClickListener(myListener); 



     // Create the ServerConfigView for this Activity 
     m_ServerView = new ServerConfigView(this); 

     // Get the selected ServerDetails from the Intent. 
     Bundle recBundle = new Bundle(); 
     recBundle = getIntent().getBundleExtra(ServerDetails.TAG_SELECTED_SERVER); 

     // Get the position in the List of the ServerDetaisl that we are going to use for this activity. 
     m_ServerPosition = recBundle.getInt(ServerDBM.TAG_SERVER_POSITION); 

     // Get the ServerDetails Object that we are going to use for this activity We Make a deep Copy. 
     m_SelectedServer = new ServerDetails(ServerDBM.getServerAtPosition(m_ServerPosition)); 

     // Show the information of the Selected ServerDetails on this Activity. 
     m_ServerView.ShowOnScreen(m_SelectedServer); 

     m_SelectedServer.setSerName("JobConfigActivity"); 
     //Bind This Activity with the Service 
     doBindService(); 

    } 

    private OnClickListener myListener = new View.OnClickListener(){ 

     @Override 
     public void onClick(View v) { 

      switch (v.getId()) { 

      case R.id.serConfig_connButton: 
       executeJobOnService(); 
       m_ServerView.WaitForResponce(); 
       Log.i(TAG_DEBUG,"Connect Button Pressed"); 
       break; 
      // Show History Button: Displays the History of the selected ServerDetails Initialize a new Activity. 
      case R.id.serConfig_historyButton: 
       m_ServerView.showHistory(m_SelectedServer.getIpAdd()); 
       break; 

      case R.id.serConfig_accpButton: 
       storeNewMessage(); 
       storeMonResult(); 
       HomeView.refreshListView(); 
       finish(); 
       break; 

      case R.id.serConfig_rejButton: 
       storeMonResult(); 
       m_ServerView.ShowAcceptAndRejetButtons(false); 
       m_ServerView.ShowConnectButton(true); 
       m_ServerView.resetEverything(); 
       break; 

      } 

     } 

    }; 

    @Override 
    protected void onDestroy() { 
     super.onDestroy(); 
     doUnbindService(); 
     HomeView.refreshListView(); 
     Log.d(TAG_DEBUG, "Server Config Activity Destroyed"); 

    } 
//More Code !! 
} 

從HomeActivity

final Intent configIntent = new   
Intent(m_presenter,ServerConfigActivityP.class); 
Bundle selServer = new Bundle(); 
selServer.putInt(ServerDBM.TAG_SERVER_POSITION,position); 
configIntent.putExtra(ServerDetails.TAG_SELECTED_SERVER,selServer); 
// Start the Server ConfigActivity 
m_presenter.startActivity(configIntent); 
+1

沒有人會讀這樣一個胖的問題。如果他也讀了他會感到困惑。用緊湊的代碼或其中的一部分提供Short,Working和Compact問題更好 – mustangDC

回答

0

從你所示的代碼調用SERVERCONFIG活動,我不能看到你連接myListener與按鈕界定。

要正確操作,您應該在OnCreate()OnResume()方法中爲按鈕定義OnClick-listenters(連接它們)。

相關問題