I have a gridView as seen here:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rl_drag_and_drop_app"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<SlidingDrawer
android:id="#+id/bottom"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:orientation="horizontal"
android:layout_marginTop="200dp"
android:content="#+id/content"
android:handle="#+id/handle" >
<Button
android:id="#+id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/arrow" />
<LinearLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#00FF00">
<!-- Editext for Search -->
<EditText android:id="#+id/inputSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/Search_applications"
android:inputType="textVisiblePassword"/>
<ListView
android:id="#+id/lvApps"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</SlidingDrawer>
<Button
android:id="#+id/btnLinkToPersonalize"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:background="#null"
android:text="#string/Personalize"
android:textColor="#21dbd4"
android:textStyle="bold" />
<GridView
android:id="#+id/GRIDVIEW1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dip"
android:numColumns="auto_fit"
android:columnWidth="60dp"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp"
android:gravity="center"
android:stretchMode="columnWidth"
>
</GridView>
<ImageView
android:id="#+id/trash_can"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:contentDescription="#string/trashcanDescription_Delete"
android:padding="40dip"
android:src="#drawable/trashcan"
android:visibility="gone" >
</ImageView>
</RelativeLayout>
And then have the coding set up in my GridView.java:
public class GridView extends Activity {
private int draggedIndex = -1;
private BaseAdapter adapter;
ArrayList<Integer> drawables = new ArrayList<Integer>();
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.drag_and_drop_app);
Log.d("GridView", "onCreate called");
drawables.add(R.drawable.pattern1);
drawables.add(R.drawable.pattern2);
android.widget.GridView gridView = (android.widget.GridView) findViewById(R.id.GRIDVIEW1);
// Instance of Adapter Class
gridView.setAdapter(new GridViewAdapter(this));
}
And then have the adapter in another class here:
package com.example.awesomefilebuilderwidget;
IMPORTS
public class GridViewAdapter extends BaseAdapter {
private Context mContextGV;
// Keep all Images in array list
public ArrayList<Integer> drawables = new ArrayList<Integer>();
// Constructor
public GridViewAdapter(Context c){
mContextGV = c;
}
#Override
// How many items are in the data set represented by this Adapter
public int getCount() {
return drawables.size();
}
#Override
// Get the data item associated with the specified position in the
// data set
public Object getItem(int position) {
return drawables.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// Try to reuse the views
ImageView view = (ImageView) convertView;
// if convert view is null then create a new instance else reuse it
if (view == null) {
view = new ImageView(mContextGV);
}
view.setImageResource(drawables.get(position));
view.setScaleType(ImageView.ScaleType.CENTER_CROP);
view.setLayoutParams(new android.widget.GridView.LayoutParams(70, 70));
view.setTag(String.valueOf(position));
return view;
}
}
And my Maniest set as so:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.awesomefilebuilderwidget"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<receiver android:name="com.example.awesomefilebuilderwidget.AFBWidget" android:label="#string/app_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="#xml/widget_stuff"/>
</receiver>
<activity android:name="com.example.awesomefilebuilderwidget.WidgetConfig" android:label="#string/app_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/>
</intent-filter>
</activity>
<activity android:name="com.example.awesomefilebuilderwidget.Drag_and_Drop_App" android:label="#string/app_name" android:windowSoftInputMode="stateHidden" android:screenOrientation="portrait"></activity>
<activity android:name="com.example.awesomefilebuilderwidget.AppInfoAdapter" android:label="#string/app_name" ></activity>
<activity android:name="com.example.awesomefilebuilderwidget.Feedback" android:label="#string/app_name" ></activity>
<activity android:name="com.example.awesomefilebuilderwidget.GridView" android:label="#string/app_name" ></activity>
<activity android:name="com.example.awesomefilebuilderwidget.SendMessageActivity" android:label="#string/app_name" ></activity>
<activity android:name="com.example.awesomefilebuilderwidget.Utilities" android:label="#string/app_name" ></activity>
<activity android:name="com.example.awesomefilebuilderwidget.Personalize" android:label="#string/app_name" ></activity>
<activity android:name="com.example.awesomefilebuilderwidget.SwipeDetector" android:label="#string/app_name"></activity>
</application>
</manifest>
However, when I run my program and get to the Drag_and_Drop_App layout (the layout shown above), the onCreate of the gridView is never called and therefore the images never show up. I've double checked everything and haven't been able to figure out why it is not showing up.
Please help!
You have to specify a way to GridView activity to be launched. There is no indication how you did started the GridView activity.
if GridView is the first activity of your app, you have to add an intent filter in your manifest declaration :
<activity android:name="com.example.awesomefilebuilderwidget.GridView" android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Related
I have created xml layout file. And when I give it as content to my Activity the TITLE BAR IS NOT VISIBLE. How can I make it visible. I tried to use setTitle("Title");
protected void onCreate(Bundle savedInstanceState) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
Bundle b = getIntent().getExtras();
int layoutId = b.getInt("layout");
Log.d("====>>>", " " + layoutId);
setContentView(layoutId);
setTitle("Title");
}
function in onCreate() method. I is not work. This is my xml file.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.universityapp.enrollee.FacultyInformationActivity"
android:scrollbars="vertical"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="#string/text_faculty_information_agro"
android:textSize="15dp"
android:textAlignment="center"
/>
</RelativeLayout>
</ScrollView>
I start activity via ListView:
profListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch (position){
case 0:
facultyInfoIntent = new Intent(getBaseContext(), FacultyInformationActivity.class);
Bundle b = new Bundle();
b.putInt("layout", facultyLayoutNames[position]);
facultyInfoIntent.putExtras(b);
startActivity(facultyInfoIntent);
}
Log.d("Selected faculty", facultiNames[position]);
}
});
This is my Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.universityapp.universityapp" >
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity android:name="com.universityapp.common.MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.universityapp.common.MenuActivity"
android:label="Главное меню" >
</activity>
<activity
android:name="com.universityapp.enrollee.ContacsActivity"
android:label="Наши контакты" >
</activity>
<activity
android:name="com.universityapp.enrollee.Map"
android:label="#string/title_activity_map" >
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="#string/google_maps_key" />
<activity
android:name="com.universityapp.enrollee.MapsActivity"
android:label="#string/title_activity_maps" >
</activity>
<activity
android:name="com.universityapp.bachelor.PlatonusActivity"
android:label="#string/title_activity_platonus" >
</activity>
<activity
android:name="com.universityapp.database.DatabaseActivity"
android:label="#string/title_activity_database" >
</activity>
<activity
android:name="com.universityapp.enrollee.EnrUniversityInfo"
android:label="#string/title_activity_enr_university_info" >
</activity>
<activity
android:name="com.universityapp.enrollee.ProfessionsActivity"
android:label="#string/title_activity_professions" >
</activity>
<activity
android:name="com.universityapp.enrollee.FacultyInformationActivity"
android:label="#string/title_activity_faculty_information" >
</activity>
</application>
</manifest>
Change:
public class MainActivity extends Activity{
}
in your class file to:
public class MainActivity extends AppCompatActivity{
}
I found the answer! I have changed Activity to ActionBarActivity and it works!
To show the title bar you can use this in your onCreate:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
You can do it by doing this (as suggested by HafizWaleedHussain):
public void showTitle() {
try {
((View) findViewById(android.R.id.title).getParent())
.setVisibility(View.VISIBLE);
} catch (Exception e) {
}
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
If this didn't work then open your Android Manifest file and remove this line if it exist:
android:theme="#android:style/Theme.NoTitleBar"
Got o styles.xml and make a new style
<style name="CustomWindowTitleBackground">
<item name="android:background">#323331</item>
<item name="android:windowNoTitle">false</item>
</style>
and call it from Manifest (You can also add other features inside item tags)
<activity
android:name=".st.activity.MyGoogleMap"
android:theme="#style/CustomWindowTitleBackground">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I removed the statement android:theme="#style/AppTheme" in the application tag and the bar started appearing
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
**android:theme="#style/AppTheme"**>
listView doesn't appear at all (the activity is white with few things I added (buttons)) and I don't know if its important but this is not my main activity.
edit: I added xml for main activity and items
public class CarsMenu extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cars_menu);
runListView();
clickFun();
}
private void clickFun() {
ListView list = (ListView) findViewById(R.id.MlistView);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View viewClicked, int position, long id) {
TextView textView = (TextView) viewClicked;
Toast.makeText(getApplicationContext(), "clicked", Toast.LENGTH_SHORT).show();
}
});
}
private void runListView(){
String[] getCars = {"blue", "green", "purple", "red"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.items, getCars);
ListView list = (ListView) findViewById(R.id.MlistView);
list.setAdapter(adapter);
}
}
activity xml
activity xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${packageName}.${activityClass}" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:onClick="btnCarClick"
android:text="Refresh" />
<ListView
android:id="#+id/MlistView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/button1"
android:layout_centerHorizontal="true" >
</ListView>
</RelativeLayout>
items xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</TextView>
android manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.http"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.http.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.http.Exception_Error"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/title_activity_exception__error"
android:theme="#style/FullscreenTheme" >
</activity>
<activity
android:name="com.example.http.Menu_Activity"
android:label="#string/title_activity_menu_" >
</activity>
<activity
android:name="com.example.http.Dev"
android:label="#string/title_activity_dev" >
</activity>
<activity
android:name="com.example.http.AllCars"
android:label="#string/title_activity_all_cars" >
</activity>
<activity
android:name="com.example.http.Cars"
android:label="#string/title_activity_cars" >
</activity>
<activity
android:name="com.example.http.CarsMenu"
android:label="#string/title_activity_cars_menu" >
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET" >
</uses-permission>
</manifest>
Your "items.xml" object has it's height equal to the parent - so only one item will be visible in your listview. Change it to:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TextView>
I am trying to write an app that has 4 menu buttons on the main screen. On clicking this each menu button, a new screen should appear. At the moment I have only written code to cater for the first button to be clicked, but it the app crashes/stops.
I think the problem is that I don't have the activity of TheCompany declared in the Android Manifest file, but I don't know how I would do that.
I am writing the app in Eclipse and so far I have the following files/sets of code:
MainActivity.Java:
public class MainActivity extends Activity {
public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View button = findViewById(R.id.TheCompany);
button.setOnClickListener(new OnClickListener(){
public void onClick (View v){
startIntent();
}
});
//getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// If your minSdkVersion is 11 or higher, instead use:
// getActionBar().setDisplayHomeAsUpEnabled(true);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_activity_actions, menu);
return super.onCreateOptionsMenu(menu);
}
/** Called when the user clicks the Company button */
private void startIntent() {
// Do something in response to button
Intent intent = new Intent(this, TheCompany.class);
startActivity(intent);
}
}
The Activity_main.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"
android:padding="10dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="The Company"
android:id="#+id/TheCompany"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Services"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Contacts" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Structure" />
</LinearLayout>
</LinearLayout>
Then I have the TheCompany Java file:
public class TheCompany extends Activity
{
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.company);
}
}
The Android.Manifest looks like:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfirstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:icon="#drawable/logo"
android:name="com.example.myfirstapp.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.myfirstapp.DisplayMessageActivity"
android:label="#string/title_activity_display_message"
android:parentActivityName="com.example.myfirstapp.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myfirstapp.MainActivity" />
</activity>
</application>
</manifest>
Simply add this in your Manifest "application" tag :
<activity
android:name="com.example.myfirstapp.TheCompany"
android:label="#string/app_name" >
</activity>
You need to declare each activity in the manifest file.
The result is this :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfirstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:icon="#drawable/logo"
android:name="com.example.myfirstapp.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.myfirstapp.TheCompany"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.myfirstapp.DisplayMessageActivity"
android:label="#string/title_activity_display_message"
android:parentActivityName="com.example.myfirstapp.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myfirstapp.MainActivity" />
</activity>
</application>
</manifest>
you did`t create any id like "TheCompany" in activity_main.xml, you have to declare id for button and then get the id using findViewById(...);
View button = findViewById(R.id.button1);
I have written an android application to display a list. Code has taken from an example. There is no error in compiling, but nothing is displayed on after running the application. Expecting you help to solve this problem thanks. Please find below code i used...
Main Activity
public class MainActivity extends ListActivity {
ArrayList<String> listItems=new ArrayList<String>();
ArrayAdapter<String> adapter;
int clickCounter=0;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listItems.add("Hello");
adapter=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listItems);
setListAdapter(adapter);
}
public void addItems(View v) {
listItems.add("Clicked : "+clickCounter++);
adapter.notifyDataSetChanged();
}
}
mainactivity.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="#+id/addBtn"
android:text="Add New Item"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="addItems"/>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"
/>
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testlistview"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="android.app.ListActivity" />
</activity>
</application>
</manifest>
Please add the following intentfilter to the manifest:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Android needs this intent filter to know which activity to start.
You may have set the wrong content view in MainActivity.
Try to replace the setContentView statement with the following one:
setContentView(R.layout.mainactivity.xml);
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
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