I'm writing an app for my android device that contains three buttons at the bottom of the screen. In my onCreate method I am setting three Button objects to their corresponding views using findViewById(). Here's the code I have written:
public class MainActivity extends AppCompatActivity {
Button btnAdd = null;
Button btnEdit = null;
Button btnDelete = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnAdd = (Button) findViewById(R.id.btnAdd);
btnEdit = (Button) findViewById(R.id.btnEdit);
btnDelete = (Button) findViewById(R.id.btnDelete);
init(getApplicationContext());
btnAdd.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
EventWriter.writeToFile(eventFile, getApplicationContext());
}
});
}
...
}
My XML looks like the following, with the button elements declared within a RelativeLayout:
<Button
android:id="#+id/btnDelete"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/scrollView1"
android:layout_alignRight="#+id/scrollView1"
android:layout_alignParentBottom="true"
android:text="#string/txtBtnDelete" />
<Button
android:id="#+id/btnAdd"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/scrollView1"
android:layout_alignLeft="#+id/scrollView1"
android:layout_alignParentBottom="true"
android:text="#string/txtBtnAdd" />
<Button
android:id="#+id/btnEdit"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="#string/txtBtnEdit" />
When I try to run the application using the emulator in Eclipse, I get the following LogCat error at line #36 (btnDelete = (Button) findViewById(R.id.btnDelete);):
Caused by: java.lang.ClassCastException: android.widget.TableLayout cannot be cast to android.widget.Button
I do have a TableLayout earlier in the code (located inside a ScrollView) but that does not contain the buttons:
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="300dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="#+id/actvSearchEvent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/actvSearchEvent"
android:layout_above="#+id/btnAdd"
android:layout_marginTop="32dp"
android:background="#drawable/scrollview_border" >
<TableLayout
android:id="#+id/tlTable"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TableLayout>
</ScrollView>
I don't see where it's getting that I'm trying to cast the TableLayout to a Button. Anybody have any ideas?
Try doing a clean and clean build folder, then run the build again.
The error means that you are still pointing to the layout with the scroll view and the table layout. And there are no buttons in it.
You can easily fix this by pasting your buttons inside your table layout, e.g.
<TableLayout...>
<Button
android:id="#+id/btnDelete"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/scrollView1"
android:layout_alignRight="#+id/scrollView1"
android:layout_alignParentBottom="true"
android:text="#string/txtBtnDelete" />
<Button
android:id="#+id/btnAdd"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/scrollView1"
android:layout_alignLeft="#+id/scrollView1"
android:layout_alignParentBottom="true"
android:text="#string/txtBtnAdd" />
<Button
android:id="#+id/btnEdit"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="#string/txtBtnEdit" />
</TableLayout>
Related
I created an empty activity in my Android project, and added one TextView and one Button to it, like so:
<?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="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:onClick="onClick"
tools:context="com.radical.pillbox.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/CloseActivityCross"
android:text="#string/cross"
android:textSize="50sp"
android:padding="10dp"
android:fontFamily="#font/montserrat_bold"
android:textColor="#color/pillbox_green_primary_dark" />
<TextView
android:id="#+id/IntroString"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/CloseActivityCross"
android:fontFamily="#font/montserrat_light"
android:padding="10dp"
android:text="Welcome to Pillbox."
android:textColor="#000000"
android:textSize="30sp"
android:gravity="left"
android:textAlignment="gravity"/>
<EditText
android:id="#+id/EmailEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/IntroString"
android:layout_marginLeft="10dp"
android:alpha="0.64"
android:fontFamily="#font/montserrat_light"
android:hint="email#example.com"
android:inputType="textEmailAddress"
android:textColor="#color/pillbox_background_dark"
android:textColorHint="#color/pillbox_accent_green" />
<EditText
android:id="#+id/PasswordEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/EmailEditText"
android:layout_marginStart="10dp"
android:alpha="0.64"
android:fontFamily="#font/montserrat_light"
android:hint="password"
android:inputType="textPassword"
android:textColor="#color/pillbox_background_dark"
android:textColorHint="#color/pillbox_accent_green" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/FooterString"
android:textColor="#000000"
android:textSize="12sp"
android:text="2018."
android:layout_centerHorizontal="true"
android:textAlignment="center"
android:fontFamily="#font/montserrat_light"
android:layout_alignParentBottom="true"/>
<Button
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:id="#+id/SignInButton"
android:background="#drawable/round_button"
android:text="Sign In"
android:textSize="15sp"
android:textColor="#color/pillbox_green_primary_dark"
android:layout_below="#id/PasswordEditText"/>
<Button
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:id="#+id/SignUpButton"
android:background="#drawable/round_button"
android:text="Sign Up"
android:textSize="15sp"
android:textColor="#color/pillbox_green_primary_dark"
android:layout_below="#id/PasswordEditText"
android:layout_toRightOf="#id/SignInButton"/>
</RelativeLayout>
My MainActivity.java file is:
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText email = (EditText) findViewById(R.id.EmailEditText);
EditText password = (EditText) findViewById(R.id.PasswordEditText);
TextView close = (TextView) findViewById(R.id.CloseActivityCross);
Button sign_up = (Button) findViewById(R.id.SignUpButton);
Button sign_in = (Button) findViewById(R.id.SignInButton);
email.setOnClickListener(MainActivity.this);
password.setOnClickListener(MainActivity.this);
sign_in.setOnClickListener(MainActivity.this);
close.setOnClickListener(MainActivity.this);
}
#Override
public void onClick(View view) {
EditText email = (EditText) findViewById(R.id.EmailEditText);
EditText password = (EditText) findViewById(R.id.PasswordEditText);
TextView close = (TextView) findViewById(R.id.CloseActivityCross);
Button sign_up = (Button) findViewById(R.id.SignUpButton);
Button sign_in = (Button) findViewById(R.id.SignInButton);
switch (view.getId()) {
case (R.id.SignInButton):
Log.d("Event:", "Signed in with correct credentials.");
break;
case (R.id.CloseActivityCross):
Toast.makeText(MainActivity.this, "Closing.", Toast.LENGTH_SHORT).show();
MainActivity.this.finish();
Log.d("Cross:", "Activity closed");
break;
}
}
}
In my main activity, I created cases in a switch-statement to handle the OnClick Events, but only the first case defined works. The remaining cases never trigger for some reason or trigger after an extended delay. To diagnose where the problem occurs, I have:
1. Tried to change the order in which I add the listeners
2. Changed cases with the first being CloseActivityCross once and SignInButton the next. Each time, only the first case works properly. Why does this happen? I should mention that in one trial, things began working perfectly for a while, and now the same issue is cropping up.
Don't re-initialize your views in onClick method i.e., remove these lines from the OnClick method and it should be good.
EditText email = (EditText) findViewById(R.id.EmailEditText);
EditText password = (EditText) findViewById(R.id.PasswordEditText);
TextView close = (TextView) findViewById(CloseActivityCross);
Button sign_up = (Button) findViewById(R.id.SignUpButton);
Button sign_in = (Button) findViewById(R.id.SignInButton);
what's happening is, when you press any of these views, they lose their onClickListeners as you are initializing the above views again.
Edited as OP added additional code.
EDIT 2:
Remove OnClick for root element RelativeLayout
<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:layout_margin="10dp"
tools:context="com.radical.pillbox.MainActivity">
Listeners are OK in java code . The problem is in xml . Your parent layout is RelativeLayout and you have use rule android:layout_below .
In some places you have used "#id instead of "#+id . So this will make overlap the views . Make it write as "#+id in all android:layout_below tags and remove android:onClick="onClick" from root layout . see if it works .
Suggestion :- If all of your widgets aligned vertically then Use LinearLayout with vertical orientation .
For example. There is picture on the top of the screen below that there are some empty boxes and below the boxes there are some buttons. Every button has a character for text("a","c","t"). You click on a button and the button's text appear in the box. You can click them in the order you want to but the answer is "cat" so when you put the characters in the correct order then you got a toast.
I tried to do it with TextViews and Buttons. I can make the button disappear when i click on it and a textview appear in the same time. But every textview has a fix place on the screen, so i need to put every character in every box invisible and when i click on the "c" character it appear in the first box and the other "c" characters stay invisible. But if i click on the "a" first, then it appears in the second box because there is too much variation to do all. I'm not good at explaining but if anyone has an idea how to do that easier please response!
Here is my code:
public class MainActivity extends ActionBarActivity implements OnClickListener{
Button b1;
Button b2;
Button b3;
TextView tg1;
TextView tg2;
TextView tg3;
TextView to1;
TextView to2;
TextView to3;
TextView tl1;
TextView tl2;
TextView tl3;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = (Button)findViewById(R.id.bg);
b1.setOnClickListener(this);
b2 = (Button)findViewById(R.id.bo);
b2.setOnClickListener(this);
b3 = (Button)findViewById(R.id.bl);
b3.setOnClickListener(this);
tg1 = (TextView)findViewById(R.id.tg1);
tg2 = (TextView)findViewById(R.id.tg2);
tg3 = (TextView)findViewById(R.id.tg3);
to1 = (TextView)findViewById(R.id.to1);
to2 = (TextView)findViewById(R.id.to2);
to3 = (TextView)findViewById(R.id.to3);
tl1 = (TextView)findViewById(R.id.tl1);
tl2 = (TextView)findViewById(R.id.tl2);
tl3 = (TextView)findViewById(R.id.tl3);
}
#Override
public void onClick(View v) {
switch(v.getId()) {
case R.id.bg:
b1.setVisibility(View.INVISIBLE);
tg1.setVisibility(View.VISIBLE);
tg2.setVisibility(View.INVISIBLE);
tg3.setVisibility(View.INVISIBLE);
break;
case R.id.bo:
b2.setVisibility(View.INVISIBLE);
to2.setVisibility(View.VISIBLE);
to1.setVisibility(View.INVISIBLE);
to3.setVisibility(View.INVISIBLE);
break;
case R.id.bl:
b3.setVisibility(View.INVISIBLE);
tl3.setVisibility(View.VISIBLE);
tl2.setVisibility(View.INVISIBLE);
tl1.setVisibility(View.INVISIBLE);
}
}
}
<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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="hu.szada.gombokelso.MainActivity"
android:orientation="horizontal">
<TextView
android:id="#+id/tl1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:visibility="invisible"
android:text="l"/>
<Button
android:id="#+id/bo"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="86dp"
android:onClick="onClick"
android:text="o" />
<Button
android:id="#+id/bl"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignBaseline="#+id/bg"
android:layout_alignBottom="#+id/bg"
android:layout_alignParentLeft="true"
android:layout_marginLeft="36dp"
android:onClick="onClick"
android:text="l" />
<Button
android:id="#+id/bg"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:layout_marginRight="14dp"
android:layout_toLeftOf="#+id/bo"
android:onClick="onClick"
android:text="g" />
<TextView
android:id="#+id/tg1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/tl"
android:layout_alignBottom="#+id/tl"
android:layout_alignLeft="#+id/tl"
android:layout_weight="1"
android:visibility="invisible"
android:text="g" />
<TextView
android:id="#+id/to1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/tl"
android:layout_alignBottom="#+id/tl"
android:layout_alignLeft="#+id/tl"
android:layout_weight="1"
android:visibility="invisible"
android:text="o" />
/// Second
<TextView
android:id="#+id/to2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/tl1"
android:layout_alignBottom="#+id/tl1"
android:layout_marginLeft="19dp"
android:layout_toRightOf="#+id/tl1"
android:layout_weight="1"
android:visibility="invisible"
android:text="o" />
<TextView
android:id="#+id/tg2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/to2"
android:layout_alignBottom="#+id/to2"
android:layout_alignLeft="#+id/to2"
android:layout_weight="1"
android:visibility="invisible"
android:text="g" />
<TextView
android:id="#+id/tl2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/to2"
android:layout_alignBottom="#+id/to2"
android:layout_alignRight="#+id/to2"
android:layout_weight="1"
android:visibility="invisible"
android:text="l" />
/// Third
<TextView
android:id="#+id/tg3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/to2"
android:layout_alignBottom="#+id/to2"
android:layout_alignRight="#+id/bl"
android:layout_weight="1"
android:visibility="invisible"
android:text="g" />
<TextView
android:id="#+id/tl3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/tg3"
android:layout_alignBottom="#+id/tg3"
android:layout_alignLeft="#+id/tg3"
android:layout_weight="1"
android:visibility="invisible"
android:text="l" />
<TextView
android:id="#+id/to3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/tg3"
android:layout_alignBottom="#+id/tg3"
android:layout_toRightOf="#+id/tl3"
android:layout_weight="1"
android:visibility="invisible"
android:text="o" />
You might want to try a slightly different approach.
If I understand you correctly, you want to "type" a word out using given lettered buttons. Like one of those hangman style games.
Why not append the text views on the fly.
Something like
#Override
public void onClick(View v) {
//Grab the surrounding layout for the textviews
GridView answerGrid = (GridView)getViewById(R.id.answerGrid);
//Get the text that was on the button
Button b = (Button)v;
String btnText = b.getText().toString();
//Make a text view with text
TextView txt = new TextView();
text.setText(btnText);
//Append to text view container
answerGrid.addView(txt);
//Invisible button
b.setVisibility(View.INVISIBLE);
}
Haven't tested to see if this is perfect, but its a start.
=====
I've looked at your xml
Why not use GridViews?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
....>
<GridView android:id="#+id/answerGrid"
....>
<!-- Put nothing here. This is for answers -->
</GridView>
<GridView android:id="#+id/lettersGrid"
android:layout_below="answerGrid"
....>
<!-- Buttons in here -->
</GridView>
</RelativeLayout>
This way you can customise the number of rows/columns based on the length of the word you're playing with. And GridView will automatically give you a neat layout and spacing.
Have a look at the GridView doc and get it customised the way you want it.
See my edits above for the Java code.
I have a 5 linear layouts, each containing 10 buttons, which gives rise to a 5 by 10 array of buttons. I would like the user to select 5 buttons, and each button contains a certain point value. On the next page, I would like the sum of the point values of these 5 buttons to appear in a textview.
Here is what I have tried so far, using a small sample of my code.
On the xml file: (this is a 2 by 3 sample)
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/button11"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="50" />
<Button
android:id="#+id/button12"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="50" />
<Button
android:id="#+id/button13"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="75" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/button21"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="00" />
<Button
android:id="#+id/button22"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="25" />
<Button
android:id="#+id/button23"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="75" />
</LinearLayout>
I am not sure what to do on the java file, but I was considering giving each button id a value (which is currently represented by the name of the button) and adding up all the values, which will then be displayed on the next page.
You can just convert the text on the button to an integer:
int value = 0;
try {
value = Integer.parseInt(button.getText().toString());
}
catch(NumberFormatException nfe) {
}
Say that xml file is called activity_main.xml. You need to have an Activity class, let's call it MainActivity.java
MainActivity.java
public class MainActivity extends Activity implements OnClickListener{
private totalVal = 0;
#Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button12 = (Button) findViewById(R.id.button12);
button12.setOnClickListener(this);
// ... Do the same for the rest of the buttons
}
#Override
public void onClick(View v){
switch(v.getId(){
case R.id.button12:
int textVal = Integer.parseInt(v.getText().toString());
totalVal = totalVal + textVal;
// do whatever else you want to when the button is clicked
break;
// ... Do the same for the rest of the buttons
}
You would also need a button that says you are done, and implement it in a similar way
Hi I am getting this message android.widget.imagebutton cannot be cast to android.widget.button (See attachment pic for logcat error) which I don't understand why? because my code seems to be right.
Code:
ImageButton Calendar = (ImageButton) findViewById (R.id.Calendar);
Calendar.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent OpenCalendarbtn = new Intent (Menu.this, DisplayCalendar.class);
startActivity (OpenCalendarbtn);
}
});
Complete Layout xml file:
`
<ImageButton
android:id="#+id/Read"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/Write"
android:layout_marginRight="31dp"
android:src="#drawable/read" />
<ImageView
android:id="#+id/AppLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#drawable/logo" />
<ImageButton
android:id="#+id/Write"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/AppLogo"
android:layout_marginLeft="35dp"
android:layout_marginTop="14dp"
android:src="#drawable/write" />
<ImageButton
android:id="#+id/Calendar"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignLeft="#+id/Write"
android:layout_below="#+id/Write"
android:layout_marginTop="20dp"
android:src="#drawable/calendar/>
`
Make sure you have used the <ImageButton> tag instead of <Button> tag in your layout resource file.
That could be the cause of the error.
Change your
ImageButton Calendar = (ImageButton) findViewById (R.id.Calendar);
To:
Button Calendar = (Button) findViewById (R.id.Calendar);
Its an Eclipse problem not in your code.
Solution for this is just copy your code in xml by Ctrl+c and save the xml then again paste it again then save it and run.....this works with me.
Hi all i have updated my post to show the full xml file, which will show if i am doing something wrong.
i implemented a custom dialog with an edit text field and it keeps crashing. I will
also like to access the values filled in the text field. Any idea where i am going wrong? Thanks.
Below is the offending/troublesome??? code
First i show the xml file which contains my layout for the alert dialog.
<?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="wrap_content">
<ImageView android:id="#+id/ImageView01"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_centerHorizontal="true" />
<ScrollView android:id="#+id/ScrollView01"
android:layout_width="wrap_content" android:layout_below="#+id/ImageView01"
android:layout_height="200px">
<TextView android:text="#+id/TextView01" android:id="#+id/TextView01"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<EditText
android:id="#+id/lastname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="blah"
/>
</ScrollView>
<Button android:id="#+id/Button01"
android:layout_below="#id/ScrollView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Cancel" />
</RelativeLayout>
Then main activity file which implements
my button click events...etc.
.......
setContentView(R.layout.main);
//this button will show the dialog
Button button1main = (Button) findViewById(R.id.Button01main);
button1main.setOnClickListener(new View.OnClickListener() {
public void onClick(View OnClickListener) {
//set up dialog
final Dialog dialog = new Dialog(MoredialogActivity.this);
dialog.setContentView(R.layout.maindialog);
dialog.setTitle("This is my custom dialog box");
dialog.setCancelable(true);
TextView text = (TextView) dialog.findViewById(R.id.TextView01);
text.setText(R.string.lots_of_text);
//set up image view
ImageView img = (ImageView) dialog.findViewById(R.id.ImageView01);
img.setImageResource(R.drawable.icon);
//set up button
Button button = (Button) dialog.findViewById(R.id.Button01);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
//finish();
}
});
dialog.show();
}
});
}
}
You have two items in your ScrollView. According to the doc :
A ScrollView is a FrameLayout, meaning you should place one child in
it containing the entire contents to scroll; this child may itself be
a layout manager with a complex hierarchy of objects.
So you should had another layout, like a linear layout :
<ScrollView
android:id="#+id/ScrollView01"
android:layout_width="wrap_content"
android:layout_below="#+id/ImageView01"
android:layout_height="200px">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center">
<TextView
android:text="#+id/TextView01"
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/lastname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="blah" />
</LinearLayout>
</ScrollView>