Notice I edited the XML File!!!!
I got an Activity that create a button and when you click on the button it calls to another Activity but when i run the app it's shows just a blank page.
Activity:
package com.elichai.tfillin;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
public void OnCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
}
private void displayCamera() {
Intent i = new Intent(this, CameraActivity.class);
startActivityForResult(i, 0);
}
public void addListenerOnButton() {
final Button button1 = (Button) findViewById(R.id.button1);
//Button button2 = (Button) findViewById(R.id.button2);
//Button button3 = (Button) findViewById(R.id.button3);
//Button button4 = (Button) findViewById(R.id.button4);
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
displayCamera();
//finish();
}
});
}
}
And here is 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" >
<Button
android:id="#+id/button1"
android:layout_width="166dp"
android:layout_height="216dp"
android:layout_marginLeft="7dp"
android:text="#string/button" />
<Button
android:id="#+id/button2"
android:layout_width="166dp"
android:layout_height="216dp"
android:layout_marginLeft="182dp"
android:text="#string/button" />
<Button
android:id="#+id/button3"
android:layout_width="166dp"
android:layout_height="216dp"
android:layout_marginLeft="7dp"
android:layout_marginTop="260dp"
android:text="#string/button" />
<Button
android:id="#+id/button4"
android:layout_width="166dp"
android:layout_height="216dp"
android:layout_marginLeft="182dp"
android:layout_marginTop="260dp"
android:text="#string/button" />
<TextView
android:id="#+id/textView1"
android:layout_width="223dp"
android:layout_height="52dp"
android:layout_marginLeft="85dp"
android:layout_marginTop="215dp"
android:text="#string/switch_cam"
android:textSize="30sp" />
</LinearLayout>
Thanks!
There is nothing wrong with the layout. In your MainActivity class, the onCreate() method signature is written incorrectly. Use onCreate() instead of OnCreate(). (small 'o')
The system calls onCreate() when creating your activity.
Replace the FrameLayout with a vertical LinearLayout
Try using A RelativeLayout in place of FrameLayout unless there was relay a need of using it.
or if you want to use FrameLayout try this
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/camera_preview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
<Button
android:id="#+id/button1"
android:layout_width="166dp"
android:layout_height="216dp"
android:layout_gravity="top"
android:layout_marginLeft="7dp"
android:text="#string/button" />
<Button
android:id="#+id/button2"
android:layout_width="166dp"
android:layout_height="216dp"
android:layout_gravity="top"
android:layout_marginLeft="182dp"
android:text="#string/button" />
<Button
android:id="#+id/button3"
android:layout_width="166dp"
android:layout_height="216dp"
android:layout_gravity="top"
android:layout_marginLeft="7dp"
android:layout_marginTop="260dp"
android:text="#string/button" />
<Button
android:id="#+id/button4"
android:layout_width="166dp"
android:layout_height="216dp"
android:layout_gravity="top"
android:layout_marginLeft="182dp"
android:layout_marginTop="260dp"
android:text="#string/button" />
<TextView
android:id="#+id/textView1"
android:layout_width="223dp"
android:layout_height="52dp"
android:layout_gravity="top"
android:layout_marginLeft="85dp"
android:layout_marginTop="215dp"
android:text="switchcam"
android:textSize="30sp" />
</FrameLayout>
layout_ margins does not work in FrameLayout until you also set your subviews layout gravity e.g.
android:layout_gravity="top"
( for framelayout)
Related
So, the problem I am facing over here is when I click on the login button it should redirect to the three_sections page but that is not happening. Same I did with the sign-in now but that worked. Clicking on the sign-in now button is redirecting me to the next page. But the login button is not! I have attached all the code below.
This is my loginpage.xml code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".loginpage"
android:background="#drawable/ic_launcher_background">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:layout_marginEnd="152dp"
android:layout_marginBottom="549dp"
android:text="USER LOGIN"
android:textColor="#color/black"
android:textSize="30dp"
android:typeface="sans" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="37dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="205dp"
android:layout_marginBottom="449dp"
android:text="USERNAME"
android:drawableLeft="#drawable/username_foreground"
android:textColor="#color/Purple"
android:textSize="20dp" />
<EditText
android:layout_width="283dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="88dp"
android:layout_marginBottom="393dp"
android:hint="ENTER USERNAME" />
<TextView
android:id="#+id/t3"
android:layout_width="144dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="200dp"
android:layout_marginBottom="340dp"
android:text="PASSWORD"
android:drawableLeft="#drawable/password_foreground"
android:textColor="#color/Purple"
android:textSize="20dp" />
<EditText
android:layout_width="284dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="85dp"
android:layout_marginBottom="273dp"
android:hint="ENTER PASSWORD" />
<Button
android:id="#+id/login"
android:layout_width="161dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="163dp"
android:layout_marginBottom="188dp"
android:background="#android:color/transparent"
android:text="LOGIN"
android:textColor="#color/Purple"
android:textSize="20dp" />
<ImageView
android:layout_width="100dp"
android:layout_height="110dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="-15dp"
android:layout_marginBottom="525dp"
android:src="#drawable/imaagee" />
<ImageView
android:layout_width="100dp"
android:layout_height="110dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="-15dp"
android:layout_marginBottom="408dp"
android:src="#drawable/image" />
<ImageView
android:layout_width="100dp"
android:layout_height="110dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="-15dp"
android:layout_marginBottom="292dp"
android:src="#drawable/iimagee" />
<ImageView
android:layout_width="100dp"
android:layout_height="110dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="-15dp"
android:layout_marginBottom="176dp"
android:src="#drawable/imagee" />
<ImageView
android:layout_width="100dp"
android:layout_height="110dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="-15dp"
android:layout_marginBottom="61dp"
android:src="#drawable/imageee" />
<Button
android:id="#+id/signnow"
android:layout_width="188dp"
android:layout_height="58dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="143dp"
android:layout_marginBottom="119dp"
android:background="#android:color/transparent"
android:text="SIGN IN NOW"
android:textColor="#color/Purple"
android:textSize="20dp" />
</RelativeLayout>
This is my loginpage.java class
public class loginpage extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.loginpage);
TextView signnow = (TextView) findViewById(R.id.signnow);
signnow.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent p = new Intent(loginpage.this,new_user_register.class);
startActivity(p);
}
});
TextView login = (TextView) findViewById(R.id.login);
login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent i = new Intent(loginpage.this,three_sections.class);
startActivity(i);
}
});
}
}
This is my three_sections.xml code
<?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"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".three_sections"
>
<TextView
android:layout_width="match_parent"
android:layout_height="180dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="429dp"
android:alpha="0.4"
android:background="#color/Purple" />
<TextView
android:layout_width="match_parent"
android:layout_height="72dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="-14dp"
android:layout_marginBottom="472dp"
android:freezesText="true"
android:text=" BEGINNERS CALLIGRAPHY"
android:textSize="25dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="180dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="238dp"
android:alpha="0.4"
android:background="#color/DeepPink" />
<TextView
android:layout_width="match_parent"
android:layout_height="72dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="-27dp"
android:layout_marginBottom="90dp"
android:text=" ADVANCED CALLIGRAPHY"
android:textSize="25dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="180dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="47dp"
android:alpha="0.4"
android:background="#color/DarkBlue" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="0dp"
android:layout_marginBottom="315dp"
android:freezesText="true"
android:text=" INTERMEDIATE CALLIGRAPHY"
android:textSize="25dp" />
</RelativeLayout>
// in OnCreate in loginpage.java
Button signNow = (Button)findViewById(R.id.signnow);
mClickButton1.setOnClickListener(this);
Button login = (Button)findViewById(R.id.clickButton2);
mClickButton2.setOnClickListener(this);
// somewhere else in your code
public void onClick(View v) {
switch (v.getId()) {
case R.id.clickButton1: {
// do something for button 1 click for example
Intent intent = new Intent(this, signNow.class);
startActivity(intent);
break;
}
case R.id.clickButton2: {
// do something for button 2 click
break;
}
}
}
Kotlin Code
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
class LoginPage : AppCompatActivity(), View.OnClickListener {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login_page)
//for sign button click listener
val signNow = findViewById<View>(R.id.signnow) as Button
signNow.setOnClickListener(this)
//for login button click listener
val login = findViewById<View>(R.id.login) as Button
login.setOnClickListener(this)
}
override fun onClick(v: View) {
when (v.id) {
R.id.signnow -> {
// Navigate to New User Register screen.
startActivity(Intent(this, NewUserRegister::class.java))
}
R.id.login -> {
// Navigate to Three Section screen.
startActivity(Intent(this, ThreeSections::class.java))
}
}
}
}
Just change the type cast of your TextView to Button in your loginpage.java code.
Change this
TextView login = (TextView) findViewById(R.id.login);
To this
Button login = (Button) findViewById(R.id.login);
I am trying to go back to previous activity after a linear layout or back button is touched however I am getting the nullpointer exception error even tough I have initialized the button and layout in onCreate method
java.lang.NullPointerException: Attempt to invoke virtual method 'void
android.widget.LinearLayout.setOnClickListener(android.view.View$OnClickListener)'
on a null object reference
My Java file
package com.profile;
import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import com.R;
public class AboutActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
LinearLayout backlayout=(LinearLayout) findViewById(R.id.back_button_linear_layout);
ImageButton backButton=(ImageButton) findViewById(R.id.back_profile_btn);
backlayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
onBackPressed();
}
});
backButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
onBackPressed();
}
});
}
}
My XML file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
tools:context="com.profile.AboutActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="#color/colorPrimaryDark">
<LinearLayout
android:id="#+id/back_profile_layout"
android:layout_width="55dp"
android:layout_height="match_parent"
android:gravity="start|center_vertical"
android:orientation="vertical">
<ImageButton
android:id="#+id/back_profile_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/activity_horizontal_margin"
android:adjustViewBounds="true"
android:background="#color/transparentBackgroundPrimaryDark"
android:maxHeight="20dp"
android:maxWidth="20dp"
android:scaleType="centerInside"
android:src="#drawable/back_100px" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="About"
android:textAllCaps="true"
android:textColor="#color/colorPrimary"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
<android.support.v4.widget.Space
android:layout_width="10sp"
android:layout_height="20sp" />
<Button
android:id="#+id/Terms"
android:layout_width="345dp"
android:layout_height="wrap_content"
android:background="#drawable/rounded_button_primary"
android:drawable="#color/colorPrimary"
android:clickable="true"
android:textAllCaps="false"
android:layout_gravity="center"
android:text="Terms and Conditions"
android:textColor="#color/colorPrimaryDark"
android:textSize="18sp"
/>
<android.support.v4.widget.Space
android:layout_width="10sp"
android:layout_height="20sp" />
<Button
android:id="#+id/Data_policy"
android:layout_width="345dp"
android:layout_height="wrap_content"
android:background="#drawable/rounded_button_primary"
android:color="#color/colorPrimary"
android:clickable="true"
android:textAllCaps="false"
android:layout_gravity="center"
android:text="Data policy"
android:textColor="#color/colorPrimaryDark"
android:textSize="18sp"
/>
<android.support.v4.widget.Space
android:layout_width="10sp"
android:layout_height="20sp" />
<Button
android:id="#+id/Licences"
android:layout_width="345dp"
android:layout_height="wrap_content"
android:background="#drawable/rounded_button_primary"
android:drawable="#color/colorPrimary"
android:clickable="true"
android:textAllCaps="false"
android:layout_gravity="center"
android:text="Licences"
android:textColor="#color/colorPrimaryDark"
android:textSize="18sp"
/>
<android.support.v4.widget.Space
android:layout_width="10sp"
android:layout_height="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="209dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Version 1.1.1000"
android:gravity="center"
android:textColor="#color/colorAccent"
android:textSize="16sp"
android:textStyle="bold"
android:layout_weight="0.87" />
</LinearLayout>
Change this line
LinearLayout backlayout=(LinearLayout) findViewById(R.id.back_button_linear_layout);
to this
LinearLayout backlayout=(LinearLayout) findViewById(R.id.back_profile_layout);
because you are assign wrong id to LinearLayout that's why it give you NullPointerExecption.
and also Remove this import com.R; is not require.
I created an application, my first, and am having problems running it on an AVD. Won't load the first activity, just says 'Unfortunately, FussyFestivalrV7 has stopped. This is the main starting activity:
package com.example.fussyfestivalr;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button switchButton = (Button) findViewById(R.id.button1);
switchButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, News.class);
startActivity(intent);
}
});
}
}
And my layout
<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:background="#string/title"
tools:context="${relativePackage}.${activityClass}" >
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="#string/title"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/newsbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/title"
android:layout_centerHorizontal="true"
android:layout_marginTop="35dp"
android:text="#string/news" />
<Button
android:id="#+id/exit"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="17dp"
android:layout_toRightOf="#+id/title"
android:text="#string/exit" />
<Button
android:id="#+id/bands"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/exit"
android:layout_centerHorizontal="true"
android:layout_marginBottom="44dp"
android:text="#string/bands" />
<Button
android:id="#+id/fafq"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/bands"
android:layout_centerHorizontal="true"
android:layout_marginBottom="53dp"
android:text="#string/fafq" />
<Button
android:id="#+id/profiles"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/fafq"
android:layout_centerHorizontal="true"
android:layout_marginBottom="41dp"
android:text="#string/festivals" />
Check whether you have </RelativeLayout>.
I hope to help.
Paul.
I've followed a tutorial to realise a calculator. It seems that my buttons objects that i define, and instantiate with the ID are not instantiated because when i add a listener on them, they return a null pointer exception.
here's the java code:
package com.example.calculette;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
//Variables declaration
Button b0;
Button b1;
Button b2;
Button b3;
Button b4;
Button b5;
Button b6;
Button b7;
Button b8;
Button b9;
Button bC;
Button bCE;
Button bEgal;
Button bPlus;
Button bMoins;
Button bDiviser;
Button bMultiplier;
EditText saisie;
private double number1 = 0;
private boolean clicOperateur = false;
private boolean update = true;
private String operateur = "";
//onCreate is the first procedure called by the activity
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b0 = (Button) findViewById(R.id.button0);
b1 = (Button) findViewById(R.id.button1);
b2 = (Button) findViewById(R.id.button2);
b3 = (Button) findViewById(R.id.button3);
b4 = (Button) findViewById(R.id.button4);
b5 = (Button) findViewById(R.id.button5);
b6 = (Button) findViewById(R.id.button6);
b7 = (Button) findViewById(R.id.button7);
b8 = (Button) findViewById(R.id.button8);
b9 = (Button) findViewById(R.id.button9);
bC = (Button) findViewById(R.id.buttonC);
bCE = (Button) findViewById(R.id.buttonCE);
bEgal = (Button) findViewById(R.id.buttonEgal);
bPlus = (Button) findViewById(R.id.buttonPlus);
bMoins = (Button) findViewById(R.id.buttonMoins);
bDiviser = (Button) findViewById(R.id.buttonDiviser);
bMultiplier = (Button) findViewById(R.id.buttonMultiplier);
saisie = (EditText) findViewById(R.id.EditText01);
//Listeners declaration
b0.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
numberClick("0");
}
});
(i don't link the whole code because it's still the same for the 9 buttons and after it's simple methods).
here you can see the XML associated:
<?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="wrap_content"
>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="3">
<EditText android:id="#+id/EditText01"
android:layout_width="fill_parent"
android:layout_height="80px"
android:textSize="20px"
android:editable="false"
android:cursorVisible="false"
/>
<View
android:layout_height="3dip"
android:background="#FF999999"
/>
<TableRow>
<Button android:id="#+id/buttonCE"
android:text="CE"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_span="2"
style="#style/button_text"
android:background="#drawable/button"
/>
<Button android:id="#+id/buttonC"
android:text="C"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_span="2"
style="#style/button_text"
android:background="#drawable/button"
/>
</TableRow>
<TableRow>
<Button android:id="#+id/button7"
android:text="7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/button_text"
android:background="#drawable/button"
/>
<Button android:id="#+id/button8"
android:text="8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/button_text"
android:background="#drawable/button"
/>
<Button android:id="#+id/button9"
android:text="9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/button_text"
android:background="#drawable/button"
/>
<Button android:id="#+id/buttonPlus"
android:text="+"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="#style/button_text"
android:background="#drawable/button"
/>
</TableRow>
<TableRow>
<Button android:id="#+id/button4"
android:text="4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/button_text"
android:background="#drawable/button"
/>
<Button android:id="#+id/button5"
android:text="5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/button_text"
android:background="#drawable/button"
/>
<Button android:id="#+id/button6"
android:text="6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/button_text"
android:background="#drawable/button"
/>
<Button android:id="#+id/buttonMoins"
android:text="-"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="#style/button_text"
android:background="#drawable/button"
/>
</TableRow>
<TableRow>
<Button android:id="#+id/button1"
android:text="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/button_text"
android:background="#drawable/button"
/>
<Button android:id="#+id/button2"
android:text="2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/button_text"
android:background="#drawable/button"
/>
<Button android:id="#+id/button3"
android:text="3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/button_text"
android:background="#drawable/button"
/>
<Button android:id="#+id/buttonMultiplier"
android:text="*"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="#style/button_text"
android:background="#drawable/button"
/>
</TableRow>
<TableRow>
<Button android:id="#+id/button0"
android:text="0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/button_text"
android:background="#drawable/button"
/>
<Button android:id="#+id/buttonPoint"
android:text="."
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/button_text"
android:background="#drawable/button"
/>
<Button android:id="#+id/buttonEgal"
android:text="="
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/button_text"
android:background="#drawable/button"
/>
<Button android:id="#+id/buttonDiviser"
android:text="/"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="#style/button_text"
android:background="#drawable/button"
/>
</TableRow>
</TableLayout>
<ImageView
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:src="#drawable/logosafran"
android:id="#+id/imageView1"
></ImageView>
</LinearLayout>
The logcat says that i have a nullPointerException on the first listener declaration with b0.
Thank you guys!
The problem is that in your activity you're trying to inflate the activity_main.xml file which obviously doesnt'hold your button declaration. You told that your buttons are defined into a button_classical.xml file.
You would have to change
setContentView(R.layout.activity_main);
in
setContentView(R.layout.button_classical);
How to make this kind of tab in Android [http://i.stack.imgur.com/rIbUX.png]
just mention that see the overlap area, when you click on of the tab, the overlap changed.
here is one chinese version example in which I think that's what I want to have, but they don't provide the complete code, and I have no idea how to go on this project.
http://www.oschina.net/question/54100_29061
I am currently using Android 3.2 and ICS 4+ to implement this project, so welcome if that's possible to implement competible with Framgment.
I finally I made the solution by myself. I just leave the native tab host implementation, make up my own.
here is the screen shot:
[http://i.stack.imgur.com/1mXLZ.png]
here is the Activity code:
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;
public class PelesysTabHostActivity extends Activity {
private ImageView ib1, ib2, ib3, last;
private Drawable pressed, released;
private TextView tv,tv1,tv2,tv3;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ib1 = (ImageView) this.findViewById(R.id.imageView1);
ib2 = (ImageView) this.findViewById(R.id.imageView2);
ib3 = (ImageView) this.findViewById(R.id.imageView3);
tv = (TextView) this.findViewById(R.id.textView1);
tv1= (TextView) this.findViewById(R.id.textView11);
tv2= (TextView) this.findViewById(R.id.textView22);
tv3= (TextView) this.findViewById(R.id.textView33);
pressed = getResources().getDrawable(R.drawable.ui_table_tab_button);
released = getResources().getDrawable(
R.drawable.ui_table_tab_button_disabled);
ib1.setImageDrawable(pressed);
last = ib1;
ib1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
last.setImageDrawable(released);
ib1.setImageDrawable(pressed);
last = ib1;
tv.setText("I am super 1");
ib1.bringToFront();
tv1.bringToFront();
}
});
ib2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
last.setImageDrawable(released);
ib2.setImageDrawable(pressed);
last = ib2;
tv.setText("TWO!!! I am super 2");
ib2.bringToFront();
tv2.bringToFront();
}
});
ib3.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
last.setImageDrawable(released);
ib3.setImageDrawable(pressed);
last = ib3;
tv.setText(" III !!! I am super 3");
ib3.bringToFront();
tv3.bringToFront();
}
});
}
}
here is the layout file I used (main.xml)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="fill_parent"
android:layout_height="330dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" >
<ImageView
android:id="#+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#drawable/ui_table_bg_coursedetail" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/relativeLayout2"
android:layout_alignParentLeft="true"
android:layout_marginLeft="326dp" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="#drawable/ui_table_tab_button_disabled" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="90dp"
android:src="#drawable/ui_table_tab_button_disabled" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="180dp"
android:src="#drawable/ui_table_tab_button_disabled" />
<TextView
android:id="#+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageView1"
android:layout_marginLeft="50dp"
android:text="1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000" />
<TextView
android:id="#+id/textView22"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageView2"
android:layout_marginLeft="50dp"
android:text="2"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000" />
<TextView
android:id="#+id/textView33"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageView3"
android:layout_marginLeft="50dp"
android:text="3"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000" />
</RelativeLayout>
Just a week now I used this : https://github.com/AdilSoomro/Iphone-Tab-in-Android
Very well worked! You can customize it as its in your first picture