0

Hello everybody i have a problem that when i click a button it remains as it is instead of starting new activity. I searched he problem in this site and found some solutions but none of them worked for me so i am writing my problem here.

the xml layout is

<?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> 

and the activity is

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> 

When i click createButton, it doesn't respond

4
  • could you attach your manifest file too Commented Jul 18, 2012 at 23:35
  • Sorry, I can't see the problem here. you need to use debugger unless someone else helps. developer.android.com/tools/debugging/debugging-projects.html Commented Jul 18, 2012 at 23:50
  • hmm try adding logs in the click listener to see of the button is getting its click event. And i also noticed ur package name com.android.SmartSwitch. U shouldn't use that, as it is used by android. And it can create conflicts if they have the same files. Commented Jul 19, 2012 at 0:26
  • Finally i solved the problem but don't know how this worked. I changed the order of Views in xml file. Now the button starts responding. I moved ListView and TextView from bottom of the file to top and amazingly it worked Commented Jul 19, 2012 at 1:12

1 Answer 1

1

As your Main Activity i.e., Profile_Manager consists of the following Code:

<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> 

You have to note if the Profile Manager class is the class which will be launched i.e., if Profile_Manager Class is the First Screen then, you should create the above code in AndroidManifest.xml with the only change as android:name=".Profile_Manager" instead of "SmartSwitchActivity" with the code additionally added for Add_Profile class as follows

<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> 

I suppose by doing this changes,things will work fine.

If you are not able to understand the above working then,Here is the Link with Perfect Working Example and with available Source Code-Correct Working of Button Click

Sign up to request clarification or add additional context in comments.

Comments