2012-07-18 42 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