I have three tabs and the first one is where the ListView should show up. I wanted to keep my code clean so I structure my app like this:
TabContainer: This contains the tabs and this hosts all the tab items
Activity1: ListView activity
Activity2: . another activity
The small part of tabContainer looks like this:
<LinearLayout
android:id="#+id/tabVegetables"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<include
android:id="#+id/vegetable_list"
android:layout_width="fill_parent"
android:layout_height="match_parent"
layout="#layout/activity_vegetable_list" >
</include>
</LinearLayout>
As you can see that I am including a layout "activity_vegetable_list" which is where the ListView resides. I put a break point in the onCreate method in the VegetableListActivity and that is never hit. Any ideas why the onCreate method of the VegetableListActivity which is the java class for activity_vegetable_list layout not invoked.
VegetableListActivity.java:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_vegetable_list);
// set the title
setTitle("Vegetable Tree");
populateVegetables();
}
AndroidManifest.xml:
<activity
android:name="com.example.someapp.app.Activities.TabContainerActivity"
android:label="#string/title_activity_tab_container" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Related
I am building an app that has 3 pages to display. To do so, I'm using a tabbed activity.
My tabbed activity works fine with textviews, buttons, etc. By works fine I mean that I can see the tabs bar at all times and can navigate between tabs.
Now, I'm trying to populate a listview within one of the tabs. This listview uses custom rows I built. I am populating this listview upon launch using an arraylist and an adapter then displaying it.
Now, the problem is that whenever the listview populates the page using my custom rows(routelistingrow.xml), the list view immediately takes over the activity full screen and covers the tabs bar and the app is stuck in this listview.
I then tried doing these steps using a basic activity (without any tabs) just to see if the listview would stay in the right place and avoid taking control of the screen. And this worked, the action bar was always visible.
So the problem is when I try to display this listview among one of many pages.
I used this video for the tabs
https://www.youtube.com/watch?v=ediklbippkA
I also tried using fragments within a navigation drawer rather than tabs and still got the same problem.
So I would like to know what's causing this problem and why the listview acts this way when I try to populate it from main.
I also found that this problem occurs when I try to dynamically add rows upon a button click
I left my Main2Activity as default and added the following:
#Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.tab_routelistings);
listView = findViewById(R.id.routelistingslistview);
dataModels= new ArrayList<>();
dataModels.add(new RouteTemplate("Canada", "USA"));
dataModels.add(new RouteTemplate("USA", "Canda"));
dataModels.add(new RouteTemplate("Canada", "USA"));
dataModels.add(new RouteTemplate("USA", "Canda"));
dataModels.add(new RouteTemplate("Canada", "USA"));
dataModels.add(new RouteTemplate("USA", "Canda"));
adapter = new RouteAdapter(dataModels, getApplicationContext());
listView.setAdapter(adapter);
}
//i only added the switch statement within this method found in main2activity.
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a PlaceholderFragment (defined as a static inner class below).
switch(position)
{
case 0:
TabRouteListings tabRouteListings = new TabRouteListings();
return tabRouteListings;
case 1:
TabCreateRoute tabCreateRoute = new TabCreateRoute();
return tabCreateRoute;
default:
TabRouteListings tabRouteListings2 = new TabRouteListings();
return tabRouteListings2;
}
}
TabCreateRoute.java
public class TabCreateRoute extends Fragment {
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, ViewGroup container, #Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.tab_createroute, container, false);
return view;
}
}
TabRouteListings.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">
<ListView
android:id="#+id/routelistingslistview"
android:layout_width="wrap_content"
android:layout_height="match_parent"></ListView>
</LinearLayout>
routelistingrow.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">>
<TextView
android:id="#+id/txtstartaddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="Start Address"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#android:color/black" />
<TextView
android:id="#+id/txtendaddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txtstartaddress"
android:layout_marginTop="5dp"
android:text="End Address"
android:textColor="#android:color/black" />
<ImageView
android:id="#+id/item_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="#android:drawable/ic_dialog_info" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<!--<Button-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:text="Modify"-->
<!--android:textColor="#android:color/black"-->
<!--android:textStyle="bold" />-->
<!--<Button-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:text="Delete"-->
<!--android:textAppearance="?android:attr/textAppearanceButton"-->
<!--android:textColor="#android:color/black"-->
<!--android:textStyle="bold" />-->
</LinearLayout>
</RelativeLayout>
AndroidMainfest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ca.mcgill.ecse321.driver">
<uses-permission android:name="android.permission.INTERNET" />
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".LoginActivity"
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=".MainActivity"
android:label="#string/title_activity_main"
android:theme="#style/AppTheme.NoActionBar" />
<activity android:name=".RegisterActivity" />
<activity
android:name=".Main2Activity"
android:label="#string/title_activity_main2"
android:theme="#style/AppTheme.NoActionBar"></activity>
</application>
</manifest>
I've been struggling with this for the past 3 days and would like to know if I'm better off proceeding with a different method (in case you can't find a solution).
As u mentioned ur tab view is overlapped by list view, Try below solution
U can put android:paddingBottom= "10dp" in root linearLayout in TabRouteListings.xml
And change android:layout_width="match_parent" in listView in TabRouteListings.xml . This change is not directly related for ur requirement
i need to use the theme
android:theme="#android:style/Theme.Holo.NoActionBar.Fullscreen"
in an activity where there is a
android.support.design.widget.BottomNavigationView
but everytime i run the app it crashes because BottomNavigationView need Theme.AppCompat. How can i fix this?
My Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tfdev.avventuratestuale">
<application
android:name=".Main.MyApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#android:style/Theme.Holo.NoActionBar.Fullscreen">
<activity android:name=".Main.Main.menu_principale"
android:theme="#android:style/Theme.Holo.NoActionBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Main.Main.scene_manager"
android:theme="#style/Theme.AppCompat"
></activity>
</application>
</manifest>
BottomNavigationView activity:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#layout/main_background">
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="#color/colorPrimary"
app:itemIconTint="#FFFFFF"
app:itemTextColor="#FFFFFF"
app:menu="#menu/bottom_navigation_main" />
</RelativeLayout>
BottomNavigation Activity:
public class scene_manager extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
setContentView(R.layout.activity_scene_manager);
}
Well you can certainly use the BottomNavigationView with the Holo theme even though I don't know why you would want to do something like this.
First of all: Not only the BottomNavigationView but also the AppCompatActivity from which your Activity extends require an AppCompat theme. Following what you need to change in order to make this work:
1 - Extend from Activity not AppCompatActivity
public class scene_manager extends Activity {
// ....
}
Note: Class names in Java shouldn't use snake_case but upper camelCase
2 - Apply an AppCompat Theme to the BottomNavigationView directly
<RelativeLayout ... >
<android.support.design.widget.BottomNavigationView
...
android:theme="#style/Theme.AppCompat"
/>
</RelativeLayout>
This way it will work but you'll use certain features like the Toolbar since you're not extending AppCompatActivity.
You can't. BottomNavigationView requires that you use an AppCompat theme.
One possibility is to use a third-party library that duplicates the functionality you need (instead of using the Google view).
I've fixed adding
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
in all the activity
after months of developing on the Android platform, I still have an unanswered question. I noticed a long time ago that I have ONE single Activity that doesn't conform to the rest of the app theme. This means that by default, the font color of the Activity is white (not black), and Checkboxes don't show up when not checked, you can't see them at all. Very peculiar behavior. Recently, I changed the colorAccent attribute of my theme, which changed ALL accent colors to orange (including Checkboxes), but this Activity remains unchanged. Has anybody ever experienced this?
I made this Activity into a fragment once, and it then magically conformed to the theme. After switching back to the Activity, even making a brand new Activity to host the logic, nothing has changed. Here's the Activity layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/white"
>
<android.support.design.widget.AppBarLayout android:id="#+id/appbar"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:paddingTop="#dimen/appbar_padding_top"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar android:id="#+id/toolbar"
android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" app:popupTheme="#style/AppTheme.PopupOverlay"
app:layout_scrollFlags="scroll|enterAlways">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<me.core.utility.TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:textSize="24sp"
android:id="#+id/title_bar"
android:textColor="#android:color/white"
android:text="Edit"
/>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#id/appbar"
android:id="#+id/listview"
android:scrollbars="none"
android:layout_above="#+id/buttons_layout"
android:layout_gravity="center_horizontal|top"
/>
<LinearLayout
android:weightSum="2"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:background="#android:color/transparent"
android:id="#+id/buttons_layout"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CANCEL"
android:layout_weight="1"
android:layout_margin="#dimen/activity_vertical_margin"
android:id="#+id/cancel_editing_button"
android:background="#drawable/custom_button_logout"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DONE"
android:layout_weight="1"
android:layout_margin="#dimen/activity_vertical_margin"
android:id="#+id/done_editing_button"
android:background="#drawable/custom_button_logout"
android:textColor="#android:color/white"
/>
</LinearLayout>
</RelativeLayout>
And here's an image of what this all looks like:
Does anybody have any ideas why this Activity has gone rogue??
EDIT: Added Manifest
<application
tools:replace="android:icon"
android:allowBackup="true"
android:icon="#mipmap/ic_trans2"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
android:name=".utility.AppInit"
>
<!-- [START gcm_receiver] -->
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="software.gcm" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
</intent-filter>
</receiver>
<!-- [END gcm_receiver] -->
<!-- [START gcm_listener] -->
<service
android:name=".gcm.GcmListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<!-- [END gcm_listener] -->
<!-- [START instanceID_listener] -->
<service
android:name=".gcm.InstanceIDListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID" />
</intent-filter>
</service>
<!-- [END instanceID_listener] -->
<!-- [START registration_service] -->
<service
android:name=".gcm.RegistrationIntentService"
android:exported="false" >
</service>
<!-- [END registration_service] -->
<!-- [START application activities] -->
<activity
android:name=".userinterface.MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".session.InitSessionActivity"
android:label="#string/app_name"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".userinterface.ProfileActivity"
android:label="#string/title_activity_profile"
android:screenOrientation="portrait"
android:parentActivityName=".userinterface.MainActivity"
>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="me.core.userinterface.MainActivity" />
</activity>
<activity
android:name=".userinterface.AddBuddyActivity"
android:label="Add Buddy"
android:screenOrientation="portrait"
android:parentActivityName=".userinterface.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".userinterface.MainActivity" />
</activity>
<activity
android:name=".userinterface.ModifyActivity"
android:label=""
android:screenOrientation="portrait"
android:parentActivityName=".userinterface.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".userinterface.MainActivity" />
</activity>
<activity
android:name=".userinterface.BuddyRequestsActivity"
android:label=""
android:screenOrientation="portrait"
android:parentActivityName=".userinterface.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".userinterface.MainActivity" />
</activity>
<activity
android:name=".userinterface.ThreadDetailsActivity"
android:label="#string/title_activity_messages"
android:screenOrientation="portrait"
android:parentActivityName=".userinterface.MainActivity"
android:windowSoftInputMode="stateHidden|adjustResize">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".userinterface.MainActivity" />
</activity>
<!-- [END application activities] -->
</application>
EDIT: Added source
public class ModifyActivity extends AppCompatActivity implements DeleteConfirmationDialog.DeleteConfirmationListener {
private static String LOG_TAG = ModifyActivity.class.getCanonicalName();
private DatabaseHelper databaseHelper;
private BusProvider busProvider;
/** UI references*/
private ProgressDialog progressDialog;
TextView title;
private Obj selectedObj; // The obj to be edited
private ModifyActivityListAdapter modifyActivityListAdapter;
private ArrayList<Buddy> buddiesToAdd; // Buddies to be added
private ArrayList<Buddy> buddiesToRemove; // Buddies to be removed
// Allows these two processes to keep track of one another, and go back to buddies activity when both are done
private boolean additionDone;
private boolean deletionDone;
private boolean actionTaken;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_modify);
busProvider = BusProvider.getInstance();
databaseHelper = DatabaseHelper.getInstance(getApplicationContext());
title = (TextView)findViewById(R.id.title_bar);
int id = Integer.valueOf(getIntent().getStringExtra(ConstantValues.IntentArguments.ARG_ID));
// The object to be edited
selectedObj = databaseHelper.selectObjWithId(id);
// if (selectedObj!=null) {
// title.setText(selectedObj.getName());
// }
// Get all members of chosen obj
ArrayList<Member> membersOfSelectedObj = databaseHelper.selectMembersOfObj(id);
//Instantiate
ListView editListView = (ListView)findViewById(R.id.edit_listview);
// Create adapter
modifyActivityListAdapter = new ModifyActivityListAdapter(getApplicationContext(), membersOfSelectedObj);
// Attach adapter
editListView.setAdapter(modifyActivityListAdapter);
Button doneButton = (Button)findViewById(R.id.done_editing_button);
Button cancelButton = (Button)findViewById(R.id.cancel_editing_button);
ImageButton deleteButton = (ImageButton)findViewById(R.id.delete_button);
ImageButton renameButton = (ImageButton)findViewById(R.id.rename_button);
doneButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
analyzeUserInput(modifyActivityListAdapter.getAllBuddies());
}
});
cancelButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
onBackPressed();
}
});
deleteButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
createDeleteConfirmDialog();
}
});
renameButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
createRenameConfirmDialog();
}
});
}
EDIT: posting code of the list item, which is the thing that's really discolored. The checkbox should be orange, and font black, but they show up totally invisible (white), so I need to change the text color manually.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:minHeight="?android:attr/listPreferredItemHeight"
tools:context=".userinterface.ModifyActivity"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:text="howdy"
android:textColor="#android:color/black"
android:textSize="20sp"
android:layout_centerVertical="true"
android:id="#+id/edit_list_item_textview"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:shadowColor="#color/lb_orange"
android:layout_centerVertical="true"
android:id="#+id/edit_list_item_checkbox"
android:focusable="false"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
It is because of how you construct your ModifyActivityListAdapter. You are giving it an application context, which the adapter uses to inflate its item views. Try passing in the activity context instead.
// Create adapter
modifyActivityListAdapter = new ModifyActivityListAdapter(this, membersOfSelectedObj);
By default, an application context does not hold theme information. As such, views inflated with it will not have your customized theme.
When you specify android:theme in your manifest's <application> element, it is not applied on the Application object, but rather at the activity level. The attribute is just for the convenience of specifying one theme that should be applied to all <activity> elements. You can use Context.setTheme(..) to apply a theme to your application context object, but that is not recommended. Instead, you should use an activity context whenever you work with views.
For more check out Dave Smith's detailed article about the Context class. It's from 2013, but Contexts didn't really change much since then.
On the xml layout file that is being used on setContentView go to the visual design portion and look at the top header in that window. You can set your theme by clicking the button to the left of the activity name tab.
have you checked if its a issue in code, like you might have an issue with view holder design pattern in your listview implementation. As the adapter code has not been posted
I have written an app with XML and still I don't write Classes by java code. But the emulator can show my app by its name and after that it says " unfortunately, app has stopped." What I have to do for this problem??!
This is my code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Textview
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/TextView2"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Button"
/>
</LinearLayout>
You must have at least one activity (Java class) in your application so that manifest.xml could recognize that and run it.
You have to use an activity to show this xml :
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
As you can see your xml is called by the setContentView method.
This activity must be declared in your AndroidManifest.xml with
<activity
android:name="YOURPACKAGE.ACTIVITY_NAME"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
How can I display a button on screen? I have defined it as
final Button nappi = (Button) findViewById(R.id.soita);
and
<Button
android:layout_width="100px"
android:layout_height="wrap_content"
android:text="#+string/Soita"
android:id="#+id/soita"
/>
You need to create the layout of the view in which you want the button to appear. Even something like
Let's say you're storing the definition in a file called main.xml in your res/layout directory.
<?xml version="1.0" encoding="utf-8"?>
<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:text="Button01" android:id="#+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
Then within your activity, you need to do the following:
public class Main extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Replace this with the name of your xml file dictating layout
setContentView(R.layout.main);
}
}
See the Hello Views tutorial; very useful. http://developer.android.com/guide/tutorials/views/index.html
If you're asking something different, like programmatically adding a button to an existing view, I'm not sure about that. In that case you might want to have the button start off as hidden and then reveal it when you need it.
I don't see why this displays nothing. I tried to make my own simple user interface.
main:
package com.xyz;
import android.app.Activity;
import android.os.Bundle;
public class NewHomeScreen extends Activity {
/** Called when the activity is first created. */
#Override public void onCreate(Bundle state) {
super.onCreate(state);
setContentView(R.layout.main);
}
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="#string/hello"
>
</TextView>
<Button android:text="Soita"
android:id="#+id/soita"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
</Button>
</LinearLayout>
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xyz"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name="NewHomeScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="3" />
</manifest>
Your textview gets all screen place...
try this
XML:
<TextView
android:text="#string/hello"
android:layout_width="match_parent" android:layout_height="291dp">
</TextView>