2 Frames/layout in 1 Activity - java

I very a newbie at android programming. I'm here because i want your help. Im designing an activity for my Thesis.
Heres the Image
I want to have an activity that has 2 Frames/Layout. The upper frame have buttons, the lower frame will display something when i click the button on the upper frame.
What would i use to make this happen?
Thank you in advance.

You can split the layout in half using LinearLayout and layout_weight param, like this:
<LinearLayout
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"></FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"></FrameLayout>
</LinearLayout>
layout_weight parameter functions as a priority in deciding who gets the space, given the other desciption would cause any of FrameLayouts to fill entire parent. You can find more in documentation.

Here is the complete solution:
step1:
create main_layout.xml file into layout folder:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="bottom">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button1"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button2"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="New Text"
android:id="#+id/textView" />
</LinearLayout>
step2: create MainActivity:
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends Activity {
private View mBtn1;
private View mBtn2;
private TextView mTxt;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
mBtn1 = findViewById(R.id.button1);
mBtn2 = findViewById(R.id.button2);
mTxt = (TextView)findViewById(R.id.textView);
mBtn1.setOnClickListener(mBtnClickListener);
mBtn2.setOnClickListener(mBtnClickListener);
}
View.OnClickListener mBtnClickListener = new View.OnClickListener() {
/**
* This is all sync because we want to have only one event at a time
* #param v
*/
#Override
public synchronized void onClick(View v) {
switch (v.getId()) {
case R.id.button1:
mTxt.setText("button1");
break;
case R.id.button2:
mTxt.setText("button2");
break;
}
}
} ;
}
step3: add the activty into your AndroidManifest.xml:
<activity
android:name=".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>

Related

setOnItemClickListener() not working on ExpandableHeightGridView in Fragment

Hello good morning in my view i cant handled the setOnItemClickListener
I am trying to create an application which dynamically lists installed applications in a gridview.I am able to display the applications in a gridview form but not able to make these items clickable. Nothing happens when i click these items. The code inside the setOnItemClickListener does not get triggered on click event.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Tab2profile">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="UselessParent">
//my scrollview
<ScrollView
android:layout_width="match_parent"
android:fillViewport="true"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/MainRLyout"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/girislayout"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/usernameTv"
android:layout_alignParentStart="true"
android:layout_width="wrap_content"
android:layout_margin="10dp"
android:layout_centerVertical="true"
android:textSize="#dimen/text_size_Orta"
android:textColor="#color/cardview_dark_background"
android:layout_height="wrap_content"
tools:ignore="PrivateResource" />
<Button
android:id="#+id/Login_LogOut_Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="0dp"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:layout_marginEnd="5dp"
android:background="#drawable/logout_rounded"
android:drawableRight="#drawable/logout_icon"
android:padding="0dp"
android:text="#string/Logout_Text_str"
android:textColor="#android:color/white"
android:textSize="12sp"
tools:ignore="RelativeOverlap,RtlHardcoded" />
</RelativeLayout>
//in here i cant handled the item click funktşon
<syr13.comapp4.Custum_Adapters.ExpandableHeightGridView
android:id="#+id/Your_Apps_Li"
android:numColumns="3"
android:layout_below="#id/Your_Apps_Tv"
android:horizontalSpacing="6dp"
android:layout_margin="5dp"
android:verticalSpacing="6dp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent">
</syr13.comapp4.Custum_Adapters.ExpandableHeightGridView>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
</FrameLayout>
I think you can Change your Code
from
button.setOnItemClickListener(this);
To
button.setOnClickListener(this);
for example :-
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = findViewById(R.id.button);
button.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId())
{
case R.id.button:
//Do Something
break;
}
}
}

Stopwatch buttons crash in Android Studio

Happy day to all of you.
I have been attempting to make a stopwatch application as my first one, while using the Chronometer function. The problem is, when I click on the Start button (while the app is running on tablet), it crashes. The situation is similar to the others.
I am not sure how I should fix this, and I greatly appreciate your help.
activity_main.xml :
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true">
<ImageView
android:id="#+id/body"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:srcCompat="#color/colorPrimaryDark" />
<LinearLayout
android:id="#+id/navcon"
android:layout_width="match_parent"
android:layout_height="92dp"
android:orientation="vertical">
<ImageView
android:id="#+id/navbar"
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="#color/colorPrimary" />
</LinearLayout>
<LinearLayout
android:id="#+id/navtextcon"
android:layout_width="match_parent"
android:layout_height="80dp"
android:orientation="vertical">
<TextView
android:id="#+id/navtext"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:text="rocket.studios"
android:textColor="#android:color/white"
android:textSize="24sp"
android:textStyle="bold" />
</LinearLayout>
</FrameLayout>
<LinearLayout
android:id="#+id/chronocon"
android:layout_width="match_parent"
android:layout_height="95dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="78dp"
android:orientation="vertical">
<Chronometer
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:textColor="#android:color/white"
android:textSize="60sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/startbcon"
android:layout_width="match_parent"
android:layout_height="118dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="155dp"
android:orientation="vertical"
android:padding="20dp">
<Button
android:id="#+id/startb"
android:layout_width="match_parent"
android:layout_height="68dp"
android:background="#color/colorPrimary"
android:text="#string/start"
android:textColor="#android:color/white"
android:textSize="24sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/stopbcon"
android:layout_width="match_parent"
android:layout_height="118dp"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:orientation="vertical"
android:padding="20dp">
<Button
android:id="#+id/stopb"
android:layout_width="match_parent"
android:layout_height="68dp"
android:background="#color/colorPrimary"
android:text="#string/stop"
android:textColor="#android:color/white"
android:textSize="24sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/resetbcon"
android:layout_width="match_parent"
android:layout_height="118dp"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="158dp"
android:orientation="vertical"
android:padding="20dp">
<Button
android:id="#+id/resetb"
android:layout_width="match_parent"
android:layout_height="68dp"
android:background="#color/colorPrimary"
android:text="#string/reset"
android:textColor="#android:color/white"
android:textSize="24sp"
android:textStyle="bold" />
</LinearLayout>
MainActivity.java :
package testing.ezekieralt.com.stopwatcher;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.ButtonBarLayout;
import android.view.View;
import android.widget.Button;
import android.widget.Chronometer;
import android.os.SystemClock;
//chronometer is...guess it
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private Chronometer chronometer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.startb).setOnClickListener(this);
findViewById(R.id.resetb).setOnClickListener(this);
findViewById(R.id.stopb).setOnClickListener(this);
chronometer = findViewById(R.id.chronometer);
}
#Override
public void onClick(View v) {
switch(v.getId()){
case R.id.stopb:
chronometer.stop();
break;
case R.id.startb:
chronometer.setBase(SystemClock.elapsedRealtime());
chronometer.start();
break;
case R.id.resetb:
chronometer.setBase(SystemClock.elapsedRealtime());
break;
}
}
}
AndroidManifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="testing.ezekieralt.com.stopwatcher">
<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=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
You didn't added id to your Chronometer. Add id to your Chronometer
<Chronometer
android:id="#+id/chronometer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:textColor="#android:color/white"
android:textSize="60sp"
android:textStyle="bold" />

Android application crashes, here's the code

I did everything that was needed like registering in the manifest. But the application crasher at launch with the usual android error. Appreciating any help.
import android.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class Tabs extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(com.example.R.layout.tabs);
TabHost th = (TabHost) findViewById(android.R.id.tabhost);
th.setup();
TabSpec specs = th.newTabSpec("tag1");
specs.setContent(com.example.R.id.tab1);
specs.setIndicator("Stop Watch");
th.addTab(specs);
specs = th.newTabSpec("tag2");
specs.setContent(com.example.R.id.tab2);
specs.setIndicator("Tab 2");
th.addTab(specs);
specs = th.newTabSpec("tag3");
specs.setContent(com.example.R.id.tab3);
specs.setIndicator("Add a Tab");
th.addTab(specs);
}
}
Here is the XML part. Code for xml starts here. please check this out too.
<?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" >
<TabHost
android:id="#+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:id="#+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:id="#+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
Please help.
Either Change
TabHost th = (TabHost) findViewById(android.R.id.tabhost);
to
TabHost th = (TabHost) findViewById(com.example.R.id.tabhost);
or
<TabHost
android:id="#+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
to
<TabHost
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
setContentView(R.layout.tabs);
TabHost th = (TabHost) findViewById(R.id.tabhost);
th.setup();
TabSpec specs = th.newTabSpec("tag1");
specs.setContent(R.id.tab1);
Change this # all com.example.R to R. something either it is R.id or R.layout
hope this will hepls you

Google Map V2 on Top half of the android screen and list view on the bottom half of the android screen

I am working on a Android project in which I need to show Google Map v2 on top half of the Android Screen and in the bottom half of the same android screen, I need to show a ListView.
Below is the code, I have so far which will be launched as soon as I launch my Application. I have setup properly the AndroidManifest.xml file for Google Map V2 key.
public class SampleActivity extends Activity {
#TargetApi(11)
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sample);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
getActionBar().hide();
}
findViewById(R.id.sample_button).setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
int width = (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 40, getResources()
.getDisplayMetrics());
SlideoutActivity.prepare(SampleActivity.this,
R.id.inner_content, width);
startActivity(new Intent(SampleActivity.this,
MenuActivity.class));
overridePendingTransition(0, 0);
}
});
}
}
And below is the sample.xml file which I need to modify so that I can add stuff which will have Google Map v2 in top half of the android screen and in the bottom half, I will have ListView
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/inner_content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/bg_android" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="45dip"
android:paddingLeft="2dip"
android:paddingRight="2dip"
android:background="#bb000000">
<Button style="#android:style/Widget.Button.Small"
android:id="#+id/sample_button"
android:layout_width="35dip"
android:layout_height="wrap_content"
android:layout_marginRight="10dip"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:text=">" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/sample_button"
android:layout_centerVertical="true"
android:textSize="19sp"
android:textColor="#ffffff"
android:text="Facebook-like slide-out nav"/>
</RelativeLayout>
</RelativeLayout>
Can anyone help me with this? I am done with all my settings related to setting up the Google Map API v2 key. I just need to plugin the code to start showing the google map v2 on the TOP half of the android screen and list view on the bottom half of the android screen.
Any help will be appreciated on this. Thanks
Update:-
Will this updated XML file will work to have Google Map v2 on top half of the android screen and ListView on bottom half of the android screen?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/inner_content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/bg_android" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="45dip"
android:background="#bb000000"
android:paddingLeft="2dip"
android:paddingRight="2dip" >
<Button
android:id="#+id/sample_button"
style="#android:style/Widget.Button.Small"
android:layout_width="35dip"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dip"
android:text=">" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#id/sample_button"
android:text="Proximity Application"
android:textColor="#ffffff"
android:textSize="19sp" />
</LinearLayout>
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.8"
android:orientation="horizontal" >
<ListView
android:id="#+id/mylist"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
</ListView>
</LinearLayout>
</LinearLayout>
This layout should present you a map in the top half of the screen an a ListView in the bottom half:
<?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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:orientation="vertical" >
<fragment
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:orientation="vertical" >
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/list">
</ListView>
</LinearLayout>
</LinearLayout>

How to add fixed buttons above a ListView android?

I want to have two buttons top of a listview. If I scroll below the listview I want that the buttons stay at top. I searched through many solutions on stackoverflow however I could not find the exact one for my case.
My layout xml(mainlayout.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/latest_news_button" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/tracked_news_button" />
</LinearLayout>
<ListView
android:id="#+id/mylist"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
The graphical layout produced is just what I wanted:
Here is my code to use this layout, in case I might fail to bind the Java code to layout;
public class MainActivity extends ListActivity{
Button latestButton;
Button trackedButton;
ListView lv = null;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainlayout);
latestButton = (Button)findViewById(R.id.button1);
latestButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Latest Button!", Toast.LENGTH_LONG).show();
}
});
trackedButton = (Button)findViewById(R.id.button2);
trackedButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Tracked Button!", Toast.LENGTH_LONG).show();
}
});
this.lv = getListView();
String[] values = new String[]{"asdfa","qwerqwer","banbn"};
lv.setAdapter(new ArrayAdapter<String>(BilTrackerMainActivity.this, android.R.layout.simple_expandable_list_item_1, values));
}
however when this activity is called from my other activity my app unfortunately closed. LogCat says:
Your content must have a ListView whose id attribute is 'android.R.id.list'
But I try adding lv = (ListView)findViewById(R.id.mylist); instead of this.lv = getListView();. I could not solve this issue.
I am aware of ListView#addHeaderView but I want to solve my particular problem with using this kind of layout.
Just change your listview id to android:id="#android:id/list"
Use a RelativeLayout. Place the second button to the right of the first button using layout_toRightOf then place the listview beneath button one using layout_below. Something like this (I haven't tested it, apologies for any typos)
<?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="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/latest_news_button" />
<Button
android:id="#+id/button2"
android:layout_toRightOf="#id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/tracked_news_button" />
<ListView
android:id="#+id/mylist"
android:layout_below="#id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
Here is the xml you are looking for
<?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"
android:background="#FF394952">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
style="#android:style/ButtonBar">
<Button
android:id="#+id/btn_AddMore"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/newItem"
android:textColor="#FF394952"/>
</LinearLayout>
<ListView
android:id="#+id/game_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_weight="1.0" />
</LinearLayout>
And when you design Activity for this dont use List activity directly use Activity and set adapter on the ListView.
ListView lv = (ListView) findViewById(R.id.game_list);
ArrayAdapter<String> listItem = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, ALBUM_NAME);
lv.setAdapter(listItem);
lv.setTextFilterEnabled(true);
Use below xml file for that
<?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">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="#+id/mLlayout1" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/latest_news_button" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/tracked_news_button" />
</LinearLayout>
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/mLlayout1" >
</ListView>
</RelativeLayout>
Create FrameLayout with [your ListView] and [LinearLayout with your buttons].
Do once something like this within onCreate()
LinearLayout myButtons = ...;
myButtons.bringToFront();
So, your ContentView will have a FrameLayout with two child, one of those is in foreground.
That's all. Hope it helped))

Categories

Resources