2012-07-18 43 views
0

大家好我有一個問題,當我點擊一個按鈕時,它保持原樣,而不是開始新的活動。我在這個網站搜索他的問題,並找到了一些解決方案,但他們都沒有爲我工作,所以我在這裏寫我的問題。安卓按鈕點擊不能在程序中工作

的XML佈局

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

    <TextView 
     android:id="@+id/profile_title" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/profile" /> 

    <Button 
     android:id="@+id/create_profile" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:text="@string/create_profile" /> 

    <Button 
     android:id="@+id/edit_profile" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_toRightOf="@id/create_profile" 
     android:text="@string/edit_profile" /> 

    <Button 
     android:id="@+id/delete_profile" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_toRightOf="@id/edit_profile" 
     android:text="@string/delete_profile" /> 

    <Button 
     android:id="@+id/activate" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_toRightOf="@id/delete_profile" 
     android:text="@string/activate" /> 

    <ListView 
     android:id="@id/android:list" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@id/create_profile" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@id/profile_title" /> 

    <TextView 
     android:id="@id/android:empty" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@id/create_profile" 
     android:layout_below="@id/profile_title" 
     android:gravity="center_vertical|center_horizontal" 
     android:text="@string/no_profiles" /> 

</RelativeLayout> 

和活動

package com.android.SmartSwitch; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 

public class Profile_Manager extends Activity { 
    private Button createButton; 
    private Button editButton; 
    private Button deleteButton; 
    private Button activateButton; 


    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.profile); 
     setUpViews(); 
    } 



    private void setUpViews() { 
     createButton = (Button)findViewById(R.id.create_profile); 
     editButton = (Button)findViewById(R.id.edit_profile); 
     deleteButton = (Button)findViewById(R.id.delete_profile); 
     activateButton = (Button)findViewById(R.id.activate); 

     createButton.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View view) { 
       Intent intent = new Intent(Profile_Manager.this, Add_Profile.class); 
       startActivity(intent); 
      } 
     }); 

     editButton.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View view) { 

      } 
     }); 

     deleteButton.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View view) { 

      } 
     }); 

     activateButton.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View view) { 

      } 
     }); 
    } 

} 

AndroidManifest.xml中

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.android.SmartSwitch" 

    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk android:minSdkVersion="8" /> 

    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" > 
     <activity 
      android:label="@string/app_name" 
      android:name=".SmartSwitchActivity" > 
      <intent-filter > 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity android:name=".Location_Manager" android:label="@string/app_name"/> 
     <activity android:name=".Profile_Manager" android:label="@string/app_name"/> 
     <activity android:name=".Schedule_Manager" android:label="@string/app_name"/> 
     <activity android:name=".Location_In_Map" android:label="@string/app_name"/> 
     <activity android:name=".Add_Profile" android:label="@string/app_name"/> 
     <uses-library android:name="com.google.android.maps" /> 

    </application> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
</manifest> 

當我點擊createButton,它沒有響應

+0

你能附上您的清單文件太 – 0x5f3759df 2012-07-18 23:35:36

+0

我連着這個 – 2012-07-18 23:40:12

+0

對不起,我在這裏看不到問題。除非其他人提供幫助,否則您需要使用調試器。 http://developer.android.com/tools/debugging/debugging-projects.html – 0x5f3759df 2012-07-18 23:50:58

回答

1

如您的主要活動即Profile_Manager包括以下代碼:

<activity 
     android:label="@string/app_name" 
     android:name=".SmartSwitchActivity" > 
     <intent-filter > 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 

你要注意,如果配置文件管理器類是將即推出了類,如果Profile_Manager類是第一個屏幕那麼,你應該與作爲機器人唯一的變化創建在AndroidManifest.xml上面的代碼:「 Profile_Manager」名稱與另外添加用於Add_Profile類的代碼=代替‘SmartSwitchActivity’如下

<activity 
     android:label="@string/app_name" 
     android:name=".Add_Profile" > 
     <intent-filter > 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
    </activity> 

我想通過這樣做改變,事情會正常工作。

如果你不能夠理解上述工作的話,這裏是一個完美的工作實例,並與現有源代碼 -鏈接Correct Working of Button Click