i want to have a set of buttons and the focus on buttons should change periodically first i want to try it with 2 buttons.this is my main.xml file.
<?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" >
<Button
android:id="#+id/number_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.72"
android:focusable="true"
android:gravity="center"
android:text="#string/number"
android:textSize="10pt" android:clickable="true"
android:focusableInTouchMode="true"/>
<Button
android:text="#string/contact"
android:textSize="10pt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/contact_button"
android:layout_weight="1" android:layout_gravity="center"
android:focusable="true" android:gravity="center"
android:focusableInTouchMode="true"/>
</LinearLayout>
in the source code i have used FOCUS_LEFT,RIGHT and all other options ,but i am getting a run time exception. the orientation is set as vertical in linear layout.Please help me to sort out this problem, if anybody know how to set the timer option as well post it here
here is the code
package com.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
public class HelloandroidActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Object o=null;
// o.toString();
// TextView tv = new TextView(this);
// tv.setText("Hello Andriod");
setContentView(R.layout.main);
Button mybtn= (Button)findViewById(R.id.number_button);
mybtn.requestFocus();
try
{
Button mybtn2= (Button)mybtn.focusSearch(View.FOCUS_DOWN);
mybtn2.requestFocus();
}
catch(Exception e)
{
Log.e("focus change","focus failed",e);
}
}
}
The problem is that you is finding a control in mybtn. Inside your activity you should call focusSearch in Activity context. Try this:
Button mybtn2 = (Button) focusSearch(View.FOCUS_DOWN);
if (mybtn2 != null)
mybtn2.requestFocus();
Related
In following code shown below
I am trying open a new activity(memo.class to view.class) when click view button.but showing an error "activity not found exception: unable to find explicit activity class".
what is wrong in my code??
please help me
my code:
memo.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="match_parent">
<TextView android:text="Titile" android:id="#+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<EditText android:id="#+id/question" android:layout_width="match_parent" android:layout_height="wrap_content" android:text=""></EditText>
<TextView android:text="Text" android:id="#+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<EditText android:minLines="6" android:maxLines="10" android:id="#+id/answer" android:layout_width="match_parent" android:layout_height="wrap_content" android:text=""></EditText>
<TableLayout android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_gravity="center"
android:stretchColumns="*">
<TableRow>
<Button android:id="#+id/add" android:layout_width="wrap_content" android:text="ADD" android:layout_height="wrap_content"></Button>
<Button android:id="#+id/view" android:layout_width="wrap_content" android:text="VIEW" android:layout_height="wrap_content"></Button>
</TableRow>
</TableLayout>
</LinearLayout>
memo.java
package quesansw.the1;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
public class Memo extends Activity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Dialog d1 = new Dialog(this);
Window window = d1.getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
d1.setTitle("Register Questions");
d1.setContentView(R.layout.memo);
d1.show();
Button view1 = (Button) d1.findViewById(R.id.view);
Button add = (Button) d1.findViewById(R.id.add);
add.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
EditText add = (EditText) d1.findViewById(R.id.question);
EditText view = (EditText) d1.findViewById(R.id.answer);
System.out.println(add.getText());
System.out.println(view.getText());
}
});
view1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
Intent intent = new Intent(getBaseContext(), View.class);
startActivity(intent);
}
});
}
}
view.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="match_parent">
<EditText android:id="#+id/question" android:layout_width="match_parent" android:layout_height="wrap_content" android:text=""></EditText>
</LinearLayout>
view.java
package quesansw.the1;
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
public class View extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Dialog d1 = new Dialog(this);
Window window = d1.getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
d1.setTitle("Login");
d1.setContentView(R.layout.view);
d1.show();
}
}
You should declare the Activity in the manifest:
<activity
android:name="com.yourpackagename.View"/>
Basically, your AndroidManifest.xml file (found in the root package folder) acts as a "settings" or "main controller" for your entire application, and so the system needs to be aware of each activity (essentially a page) that you will transition to or use.
Here are other things that can go within the Activity tag in the Manifest file.
Side Note: as #Tyler M. says, you should use another name than "View" for your Activity.
Rename your Activity subclass to something other than View.
It is generally a bad idea to use names of existing classes - it is a reference disaster waiting to happen.
You most likely forgot to include it in the Manifest.xml
Ok so... I've been trying to affect text to TextView (because it's meant to show text, right?)
But for some unknown to me reason it refuses to print whatever I put into it.
My application has two activities, the MainAcivity, or a welcoming screen, per se, and a GameActivity (the project is a Domino game).
I create my previously written java objects at the beginning of the GameActivity class, trying then to show player's name within a TextView.
Player player1 = new Player("Hulk");
creates a player with name Hulk, as you can imagine. I have a method within Player.java to return player's name:
player1.getName()
returns string "Hulk"
I then try to set my TextView's text to hulk, first off by creating a handle to it with:
TextView p1v = (TextView) findViewById(R.textviews.p1view);
then doing the following:
p1v.setText("Player 1 : " + player1.toString());
the p1view is defined as follows within game.xml layout:
<LinearLayout
...
<LinearLayout
...
<TextView
android:id="#+textviews/p1view"
android:text="Board"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</LinearLayout>
I tried p1view.textAppend, tried using android:editable="true". Nothing seems to work.
Funnily enough though, when I try doing the same thing, within MainActivity, it works, as so:
public class
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
with the TextView defined within main.xml as follows:
<TextView
android:id="#+textviews/mainview_player"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
Following are the full codes of the files, just to avoid answers like: Give us the full code D:
GameActivity.java:
package domino.asd;
import LI260.*; import android.app.Activity; import android.os.Bundle;
import android.widget.TextView;
public class GameActivity extends Activity {
private Player player1 = new Player("HULK");
private Player player2 = new Player("CPU");
private Pioche bag = new Pioche();
private Plateau board = new Plateau();
private Game game1 = new Game(bag, board, player1, player2);
TextView p1name = null;
TextView p2name = null;
/**
* Called when the activity is first created.
*
* #param savedInstanceState
*/
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.game);
TextView tv = (TextView) findViewById(R.textviews.p1view);
tv.setText(player1.getName());
} }
game.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"
android:weightSum="10"
>
<!-- Played layout -->
<LinearLayout
android:id="#+drawable/gameview_Scores"
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_gravity="top"
android:layout_weight="2"
android:layout_marginBottom="10px"
android:orientation="horizontal"
android:background="#ff0000"
android:gravity="center"
>
<Button
android:id="#+buttons/exitButton"
android:text="Exit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
/>
<Button
android:id="#+buttons/drawButton"
android:text="Draw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:id="#+buttons/scoresButton"
android:text="Show scores"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<!-- Board layout -->
<LinearLayout
android:id="#+textviews/gameview_Table"
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_gravity="center"
android:layout_weight="6"
android:layout_marginBottom="10px"
android:background="#ffff00"
>
<TextView
android:id="#+textviews/p1view"
android:text="Board"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<!-- At hand layout -->
<LinearLayout
android:id="#+drawable/gameview_Playable"
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="2"
android:layout_gravity="bottom"
android:background="#ff00ff"
>
<TextView
android:id="#+textviews/gameview_AtHandText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</LinearLayout>
MainActivity.java:
package domino.asd;
import LI260.*;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
Player p1 = new Player("Hulk");
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView p1view = (TextView) findViewById(R.textviews.mainview_player);
p1view.setText(p1.getName());
}
public void btnClick_Name(View view) {
if (view.getId() == R.buttons.B_EnterName) {
EditText playersname = (EditText) findViewById(R.string.playerNameInput);
Toast.makeText(this, "Your name: " + playersname.getText().toString(), Toast.LENGTH_SHORT).show();
}
setContentView(R.layout.game);
}
}
and lastly 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"
android:gravity="center"
>
<EditText
android:id="#+string/playerNameInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:lines="1"
/>
<TextView
android:id="#+textviews/mainview_player"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:id="#+buttons/B_EnterName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Save name and start game."
android:onClick="btnClick_Name"
/>
</LinearLayout>
When you are first loading the activity, you are calling this code:
setContentView(R.layout.main);
TextView p1view = (TextView) findViewById(R.textviews.mainview_player);
p1view.setText(p1.getName());
Yet when the user click's the button you are only calling this code:
setContentView(R.layout.game);
Because you have reset the main content view the child view mainview_player has been destroyed and replaced with a new one when inflated from R.layout.game.
You would need to call this code again to find the new view in the game layout and populate it with your player name:
TextView p1view = (TextView) findViewById(R.textviews.mainview_player);
p1view.setText(p1.getName());
You would be better to look into how activities relate to one another and start a new activity for R.layout.game
I'm very new with android development. I'm trying to develop an application, I decided to try out the code below but I keep getting errors when I try to open it on the emulator. please can anyone tell me what I'm doing wrong?
package hajara.android.MyRecipes;
import android.app.Activity;
import android.os.Bundle;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MyRecipesActivity extends Activity {
Button btn;
TextView t1, t2;
EditText e;
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
t1 = (TextView)findViewById(R.id.text1);
t2 = (TextView)findViewById(R.id.text2);
e = (EditText)findViewById(R.id.edit1);
btn=(Button)findViewById(R.id.button1);
btn.setOnClickListener((OnClickListener) this);
}
}
My main.xml file is
<?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" >
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter a string:"
/>
<EditText android:id="#+id/edit1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cursorVisible="true"
android:editable="true"
android:singleLine="true"
/>
<Button android:id="#+id/button1"
android:text="OK"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/text2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
/>
</LinearLayout>
Your onClick listener is done incorrectly. I find it easier to simply create a method such as:
public void buttonOnClick(View v) {
// Do something
}
and within your XML layout file (ie. main.xml) invoke the onClick attribute:
<Button
...
android:onClick="buttonOnClick"
...
/>
I think you haven't Declared button Properly.
btn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// Your Code Goes here
}
});
And Hope you have Declared your Activity in Manifest File.
I'm creating a toolbar that toggles the visibility of buttons when you click a button from a toolbar. So, if the user clicks on the "Draw" button, invisible buttons "Pencil" and Pen" will become visible above the "Draw" button. If you click the "Draw" button again, the buttons "Pencil" and "Pen" will become invisible again.
Within my xml file I have set the visibilty of some buttons to be "invisible" so when I launch the activity they won't be seen. This part is straight forward.
.xml file of btnDrawLine - (Update # 12:21)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent" >
<com.odhranlynch.testSection.UserInterface
android:id="#+id/UserInterface"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true" />
<Button
android:id="#+id/btnDraw"
android:layout_width="80dip"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Draw" />
<Button
android:id="#+id/btnDrawLine"
android:layout_width="80dip"
android:layout_height="wrap_content"
android:layout_above="#+id/btnDraw"
android:layout_alignParentLeft="true"
android:visibility="visible"
android:text="Line" />
<Button
android:id="#+id/btnDrawCurve"
android:layout_width="80dip"
android:layout_height="wrap_content"
android:layout_above="#+id/btnDrawLine"
android:layout_alignParentLeft="true"
android:visibility="visible"
android:text="Curve" />
<Button
android:id="#+id/btnCutout"
android:layout_width="80dip"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/btnDraw"
android:text="Cutout" />
<Button
android:id="#+id/btnCutInner"
android:layout_width="80dip"
android:layout_height="wrap_content"
android:layout_above="#+id/btnDraw"
android:layout_toRightOf="#+id/btnDraw"
android:visibility="visible"
android:text="Inner" />
<Button
android:id="#+id/btnCutOutter"
android:layout_width="80dip"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/btnDrawCurve"
android:layout_alignBottom="#+id/btnDrawCurve"
android:layout_toLeftOf="#+id/btnCancel"
android:visibility="visible"
android:text="Outter" />
<Button
android:id="#+id/btnCancel"
android:layout_width="80dip"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="#+id/btnFinish"
android:text="Cancel" />
<Button
android:id="#+id/btnFinish"
android:layout_width="80dip"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="Finish" />
</RelativeLayout>
Next, when the user clicks a button that is visible, I'd like the invisible buttons to appear.
Here's the thing, they won't reappear!lol I'm confused by it.
I would be very grateful if someone would be kind enough to shed so light onto this for me :)
testActivity.java
package com.odhranlynch.testSection;
import com.odhranlynch.testSection.R;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
public class testActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.new_product);
// Find buttons and give them a name.
final View btnDraw = findViewById(R.id.btnDraw);
final View btnCutOut = findViewById(R.id.btnCutout);
final View btnDrawLine = findViewById(R.id.btnDrawLine);
final View btnDrawCurve = findViewById(R.id.btnDrawCurve);
final View btnCutInner = findViewById(R.id.btnCutInner);
final View btnCutOutter = findViewById(R.id.btnCutOutter);
//Draw Button clicked (UI Toolbar).
btnDraw.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
//Treat button as a toggle button
//So if a sub-button (e.g. Draw Line) is visible, then we know the button has
//been toggled to visible so lets now make it invisible.
if (btnDrawLine.getVisibility()== View.VISIBLE) {
//Its visible.
btnDrawLine.setVisibility(View.INVISIBLE);
btnDrawCurve.setVisibility(View.INVISIBLE);
Log.d("TAG", "INVISIBLE");
} else {
// Either gone or invisible
btnDrawLine.setVisibility(View.VISIBLE);
btnDrawCurve.setVisibility(View.VISIBLE);
Log.d("TAG", "VISIBLE");
}
}
});
}
}
As a further point to mention, if I set the visibilty of the buttons to be visible within the .xml file I can toggle the visibilty perfectly fine during runtime!
Again, I would be grateful of some help :)
Try replacing View.INVISIBLE to View.GONE.
Your code is working fine..
The XML file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello" />
<Button
android:id="#+id/btnDrawLine"
android:layout_width="80dip"
android:layout_height="wrap_content"
android:layout_above="#+id/btnDraw"
android:layout_alignParentLeft="true"
android:visibility="invisible"
android:text="Line" />
<Button
android:id="#+id/draw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="draw" />
</LinearLayout>
The activity
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
public class DrawCanvasActivity extends Activity {
private static final String Number1 = "9686801147";
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final View btnDrawLine = findViewById(R.id.btnDrawLine);
Button btnDraw = (Button) findViewById(R.id.draw);
btnDraw.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
if (btnDrawLine.getVisibility()== View.VISIBLE) {
btnDrawLine.setVisibility(View.INVISIBLE);
Log.d("TAG", "INVISIBLE");
} else {
btnDrawLine.setVisibility(View.VISIBLE);
Log.d("TAG", "VISIBLE");
}
}
});
}
}
The button line appears when the draw button is clicked.Guess there may be problem in the view formatting in your code.
If you want ot use gone/visible, just add a LinearLayout around your buttons, which you want to hide. LinearLayout will have a layout_width=wrap_content; and you referer position of other element to this Layout.
After you free to change visibility to gone/visible of your buttons.
I have a custom Dialog that shows a few buttons. The idea is to have a scrollable Dialog where one can choose a number or letter from 0 to 9, or 0 to F or 0 to Z ...
So my first problem is how do I add these buttons through code and not xml since there is a variable number of buttons each time. Even the simplest code crashes on me so I'm probably not doing anything right.
Also the code I have with a few xml buttons chrashes when I click on the buttons saying it can't find the onClick function. As you can see I have android:onClick="onClickDialogbutton" in my button xml and the function does exist in my java code but still it crashes.
Hope someone can take look at the code and help me with adding buttons programatically and get the onClick to work.
Here is my code:
DialogTestActivity.java:
package com.test.dialog;
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.LinearLayout;
public class DialogTestActivity extends Activity {
Dialog dialog;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void onClickStartDialog( View view ) {
dialog = new Dialog( this );
dialog.requestWindowFeature( Window.FEATURE_NO_TITLE );
dialog.setContentView( R.layout.dialog );
dialog.setCancelable( true );
dialog.show();
// I here wish to add buttons through code and not xml.
// This gives an error as it is now.
Button button = new Button( this );
( ( LinearLayout )findViewById( R.id.Buttons ) ).addView( button );
}
public void onClickDialogButton( View view ) {
dialog.dismiss();
}
}
Main.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" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:onClick="onClickStartDialog"
android:text="Start Dialog" />
</LinearLayout>
Dialog.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="54dip"
android:layout_height="150dip"
android:gravity="center" >
<ScrollView
android:layout_width="48dip"
android:layout_height="144dip" >
<LinearLayout
android:id="#+id/Buttons"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="#+id/ButtonId0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:onClick="onClickDialogbutton"
android:text="0"
android:textSize="32dip" />
<Button
android:id="#+id/ButtonId1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:onClick="onClickDialogbutton"
android:text="1"
android:textSize="32dip" />
<Button
android:id="#+id/ButtonId2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:onClick="onClickDialogbutton"
android:text="2"
android:textSize="32dip" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
You probably need to call findViewById on the dialog. Simply calling findViewById inside of your Activity will try to find a view or child view currently being displayed in your activity with the specified id. In this case that is probably returning null, hence the crash. Try it again with dialog.findViewById...