I am making an Facts based application. I want it to show new fact every time the user presses the button and i also want that when the user exits the app and restart it, it would resume from the same fact that user was reading.
Help me guys... I have included the java and xml code that i am using
Thanks in advance
My Java Layout
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void Next(View view) {
TextView textView = (TextView) findViewById(R.id.textView);
textView.setText("Hi");
textView.setText("No One is here to sleep");
textView.setText("This sounds like fun");
textView.setText("Men will be men");
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is
// present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
// noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Xml:
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity"
android:background="#ff7922ff">
<TextView android:text="#string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView"
android:textSize="35dp"
android:layout_above="#+id/button"
android:layout_centerHorizontal="true"
android:layout_marginBottom="106dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"
android:id="#+id/button"
android:layout_marginBottom="158dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:onClick="Next" />
</RelativeLayout>
TextView tv = (TextView)findViewById(R.id.tv);
Button bt = (Button)findViewById(R.id.bt);
bt.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
tv.setText("TEXT");
}
});
Use SharedPreferences for that
SharedPreferences prefs = getSharedPreferences("mySHaredpref", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
boolean isFirst = prefs.getInt("lastFact", 0);
You could use Shared Preferences to keep a track of which was the last fact that the user had seen. Please check this link for the same How to use SharedPreferences in Android to store, fetch and edit values
What you will need to do is that on every next or previous button click you will have to store the fact number in your shared preferences. Every time the app is opened, load fact corresponding to the factnumber in the sharedpreferences.
I would advice you to do like this:
int count=0;
ArrayList<String> msgList = new ArrayList<>();
msgList.add("Hi");
msgList.add("No One is here to sleep");
msgList.add("This sounds like fun");
msgList.add("Men will be men");
Now
public void Next(View view) {
if(count==msgList.size()){
count=0;
textView.setText(msgList.get(count%msgList.size()));
}else{
textView.setText(msgList.get(count%msgList.size()));
count++;
}
}
As per your requirement, you need to save the facts in shared preferences and show the facts in TextView as user tap the button.
You also need to fetch the facts from shared preferences and show on the TextView in OnResume() of activity.
Button btn = (Button)findViewById(R.id.button);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
// save the facts in shared preferences
// and show the facts on the text view
}
});
and onResume()
#Override
protected void onResume() {
super.onResume();
// check the shared preferences for the facts
// If facts is available in shared preferences then show on the
// textview
}
If you want to define the onClick method on XML, then work on onClickListener to be done on the onClick method(defined in XML).
Related
I have a main_activity with 3 different Fragment and a SlideActivity. I could make transactions among 3 fragments successfully in my MainActivity.
Now I add 1 button in the MainActivity and it will open the SlideActivity. On the SlideActivity, there are 3 buttons in the navigation bar to switch to each different fragments which I already created.
The problem is when I click the list button in the navigation, an error comes out shows that
No view found for id 0x7f080052 (com.example.learnfragment:id/fragment_container) for fragment fragment_main{e1acaf7 #0 id=0x7f080052}
It seems that it cannot find the FrameLayout ID by R.id. and I believe because the navigation buttons are in the SlideActivity and it cannot find the ID which is in the MainActivity.
But how should I do for switching back to the MainActivity as well as changing different fragment?
Here's the navigation_slide_activity.xml
<include
layout="#layout/app_bar_slide"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_slide"
app:menu="#menu/activity_slide_drawer" />
The Navigation_Slide_Activity.java:
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_home) {
// Navigate back to the Main Fragment
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.fragment_container, new fragment_main());
ft.commit();
}
}
And the main_activity.xml:
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="392dp"
android:layout_height="496dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp" />
Finally, the MainActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create Fragment
if(savedInstanceState == null){
getSupportFragmentManager().beginTransaction().add(
R.id.fragment_container,
new fragment_main()).commit();
}
}
Get a public static variable in your MainActivity.
public static int FRAGMENT_TO_BE_LOADED = 0;
Now from the SlideActivity, set the variable to a number (e.g. 3, that is you want to move to the third fragment when you are returning to your MainActivity.
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_home) {
MainActivity.FRAGMENT_TO_BE_LOADED = 3;
finish();
}
}
Now in your MainActivity, you need to have an onResume function which will check the variable and load the fragment accordingly.
#Override
protected void onResume() {
super.onResume();
if(FRAGMENT_TO_BE_LOADED == 1) loadFragment1();
else if(FRAGMENT_TO_BE_LOADED == 2) loadFragment2();
else if(FRAGMENT_TO_BE_LOADED == 3) loadFragment3();
}
Hope that solves your problem.
I am working on a Project and testing the XML, however, whenever I try switching to my next activity, the app gets stuck on a black screen and does nothing, and I am forced to quit.
I tried switching the layouts for setContentView and that didn't work, I checked to make sure the code in the activity files was working, and now I am looking at other's questions and I am just confused.
Here is my MainActivity:
public class MainActivity extends android.app.Activity {
ImageButton startButton;
TextView textView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_main);
startButton = (ImageButton)findViewById(R.id.startButton);
textView = (TextView)findViewById(R.id.textView);
textView.setTextColor(Color.WHITE);
View backgroundView = findViewById(R.id.spoopySkellington);
View root = backgroundView.getRootView();
root.setBackgroundColor(getResources().getColor(android.R.color.black));
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
public void startClick(View view)
{
final Intent intent = new Intent(MainActivity.this, AdventureActivity.class);
startActivity(intent);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Here is the activity I am trying to switch to.
public class AdventureActivity extends android.app.Activity {
Character mainCharacter;
Character skeleton;
TextView dialogueView;
EditText textField;
Button confirmButton;
String field;
ImageView enemy;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_adventure);
confirmButton = (Button)findViewById(R.id.confirmButton);
dialogueView = (TextView)findViewById(R.id.dialogueView);
textField = (EditText)findViewById(R.id.inputText);
field = "";
skeleton = new Character("Skeleton", 10, 1);
String name = "";
while (field.equals("")) {
dialogueView.setText("What is your name?");
name = field;
}
mainCharacter = new Character(name);
}
public void onClick(View view)
{
field = textField.getText().toString();
textField.setText("");
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Lastly, here is the activity xml for the one I want to switch to:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.jason.textadventure.AdventureActivity"
tools:showIn="#layout/activity_adventure">
<TextView
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:id="#+id/dialogueView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="..."
android:textSize="30dp"
tools:layout_editor_absoluteY="126dp"
tools:layout_editor_absoluteX="180dp"
/>
<EditText
app:layout_constraintBottom_toBottomOf="#id/dialogueView"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:id="#+id/inputText"
android:layout_width="261dp"
android:layout_height="40dp"
tools:layout_editor_absoluteY="196dp"
tools:layout_editor_absoluteX="62dp"
android:inputType="textNoSuggestions"
/>
<Button
app:layout_constraintBottom_toBottomOf="#id/inputText"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="#id/dialogueView"
android:id="#+id/confirmButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CONFIRM"
android:onClick="onClick"
tools:layout_editor_absoluteY="184dp"
tools:layout_editor_absoluteX="148dp" />
When onCreate() is called, your code is stuck around this loop
while (field.equals("")) {
dialogueView.setText("What is your name?");
name = field;
}
I am having trouble with using OnClickListener. I am trying to start a new activity when the user presses one of the buttons in my floating action button. My app just crashes right when I run it.
In my LaunchActivity.java:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launch);
final Button buttonNote = (Button) findViewById(R.id.note);
buttonNote.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
startActivity(new Intent(LaunchActivity.this, CreateNote.class));
}
});
}
In my activity_launch.xml:
<com.getbase.floatingactionbutton.FloatingActionsMenu
android:id="#+id/create"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
fab:fab_addButtonColorNormal="#color/accent"
fab:fab_addButtonColorPressed="#color/accent_dark"
fab:fab_addButtonPlusIconColor="#color/window_background"
fab:fab_labelStyle="#style/menu_labels_style"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp">
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="#+id/note"
android:src="#drawable/ic_note"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingBottom="16dp"
fab:fab_title="#string/note"
fab:fab_colorNormal="#color/accent"
fab:fab_colorPressed="#color/accent_dark"/>
</com.getbase.floatingactionbutton.FloatingActionsMenu>
CreateNote.java:
public class CreateNote extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_note);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_create_note, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Thank you for any help, this is my first app.
try this
findViewById(R.id.note).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(LaunchActivity.this, CreateNote.class));
}
});
instead
final Button buttonNote = (Button) findViewById(R.id.note);
buttonNote.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
startActivity(new Intent(LaunchActivity.this, CreateNote.class));
}
});
hope it help
Please share your logcat errors here..
And try to change the object from Button to com.getbase.floatingactionbutton.FloatingActionButton.
Declare your activity in manifest file as follows
<activity
android:name=".CreateNote"
android:label="#string/app_name">
</activity>
Ok, you got it working, but for your information,
the reason why you were facing this problem was, the FAB is NOT one of those simple buttons that you create.
You have to create an object of floatingActionButton instead of creating the object of button (which you did in your case).
I made an android app in which the user click the favorite menu item button and the page name saves in the favorite.class activity. But when I click on any item in the favorite list it opens only one specific class and not others which I want. Here is my code please look at the code and tell me what should I do to make it first in ListView form and then to click the item which opens the correct activity from it.
favorite.xml layout:
<?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="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_marginLeft="17dp">
<TextView
android:id="#+id/empty_textview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/no_bookmark"
android:textSize="16sp"
android:textColor="#000000"
android:
android:textStyle="bold"/>
<TextView
android:id="#+id/bookmark_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:textSize="16sp"
android:textColor="#000000"
android:textStyle="bold"/>
<!-- ScrollView is needed when adding views, or only the last view will show up -->
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/bookmark_insert_point"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</LinearLayout>
Favorite.Class activity:
public class Favorite extends Activity {
private TextView mEmptyText;
private LinearLayout mBookmarkLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.favorite);
// this code is used for the action bar color change//
ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#6B8E23")));
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
mEmptyText = (TextView) findViewById(R.id.empty_textview);
mBookmarkLayout = (LinearLayout) findViewById(R.id.bookmark_insert_point);
getAllKeys();
}
private void getAllKeys()
{
SharedPreferences sp = this.getSharedPreferences("bookmarks", MODE_PRIVATE);
Map<String,?> keys = sp.getAll();
int count = 0;
for(Map.Entry<String,?> entry : keys.entrySet())
{
String value = entry.getValue().toString();
System.out.println("!!!!!!!!!!!!!!!!!value = "+value);
String delimiter = ",";
String[] values_array = value.split(delimiter);
addBookmark(values_array);
count++; //keep track of the number of bookmarks
}
//if there are no bookmarks, display a text view saying so. Otherwise, make the text view go away
if (count == 0)
{
mEmptyText.setVisibility(View.VISIBLE);
mEmptyText.setText(getString(R.string.no_bookmark));
}
else
mEmptyText.setVisibility(View.GONE);
}
#SuppressWarnings("deprecation")
private void addBookmark(final String[] values_array)
{
LayoutInflater vi = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = vi.inflate(R.layout.favorite, null);
final TextView text = (TextView) v.findViewById(R.id.bookmark_text);
text.setText(values_array[1]);
// insert into main view
mBookmarkLayout.addView(v, 0, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT));
System.out.println("!!!!!!!!!!!!!!!!!!!!Just added a view");
text.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(text.equals("Atherosclerosis"));
Intent i=new Intent(Favorite.this,Atherosclerosis.class);
startActivity(i);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.favorite, menu);
return true;
}
}
and finally the activity from where user click for add to favorite:
public boolean onOptionsItemSelected(MenuItem item) {
// Take appropriate action for each action item click
switch (item.getItemId()) {
case R.id.id_search:
Intent newActivity0 = new Intent(this,Search.class);
startActivity(newActivity0);
return true;
case R.id.id_favorit:
SharedPreferences sp = this.getSharedPreferences("bookmarks", MODE_PRIVATE);
Editor editor = sp.edit();
editor.putString("atherosclerosis", "com.kmcpesh.shortreviewofcardiology.Favorite,Atherosclerosis");
editor.commit();
Toast.makeText(getApplicationContext(), "Item Added to Favorite List!", Toast.LENGTH_SHORT).show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
well i guess what you have to do is setOnItemClickListener in everyone of the list items...
an example is
private void registerCallClickBack() {
// TODO Auto-generated method stub
ListView list = (ListView)findViewById(R.id.listView1);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View viewClicked, int position,
long id) {
// TODO Auto-generated method stub
//String message = "You have chosen the " + id + "item";
//Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show();
Intent intent = new Intent("package.Activity name");
startActivity(intent);
}
});
}
this will either display a toast message of every listview item clicked or start a new intent..
I'm going through the tutorial HelloFormStuff. I started having problems adding the RadioGroup widget. After moving some brackets around I finally got it to work.
When I tried to add the final (2) widgets, I found if I tried to add them in main.xml below the RadioGroup they wouldn't appear in the app. I guess I could just call it finished and move on, but I took the time to enter all the code (not ctrl C, ctrl P) and damn it, the widgets should show up where I tell them to! Why can't I add widgets below the RadioGroup?
public class HelloFormStuff extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final EditText edittext = (EditText) findViewById(R.id.edittext);
edittext.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// If the event is a key-down event on the "enter" button
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER)) {
// Perform action on key press
Toast.makeText(HelloFormStuff.this, edittext.getText(), Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
});
final CheckBox checkbox = (CheckBox) findViewById(R.id.checkbox);
checkbox.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Perform action on clicks, depending on whether it's now checked
if (((CheckBox) v).isChecked()) {
Toast.makeText(HelloFormStuff.this, "Selected", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(HelloFormStuff.this, "Not selected", Toast.LENGTH_SHORT).show();
}
}
});
final RadioButton radio_red = (RadioButton) findViewById(R.id.radio_red);
final RadioButton radio_blue = (RadioButton) findViewById(R.id.radio_blue);
radio_red.setOnClickListener(radio_listener);
radio_blue.setOnClickListener(radio_listener);
final Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Perform action on clicks
Toast.makeText(HelloFormStuff.this, "Beep Bop", Toast.LENGTH_SHORT).show();
}
});
final ToggleButton togglebutton = (ToggleButton) findViewById(R.id.togglebutton);
togglebutton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Perform action on clicks
if (togglebutton.isChecked()) {
Toast.makeText(HelloFormStuff.this, "Checked", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(HelloFormStuff.this, "Not checked", Toast.LENGTH_SHORT).show();
}
}
});
final RatingBar ratingbar = (RatingBar) findViewById(R.id.ratingbar);
ratingbar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
Toast.makeText(HelloFormStuff.this, "New Rating: " + rating, Toast.LENGTH_SHORT).show();
}
});
}
private OnClickListener radio_listener = new OnClickListener() {
public void onClick(View v) {
// Perform action on clicks
RadioButton rb = (RadioButton) v;
Toast.makeText(HelloFormStuff.this, rb.getText(), Toast.LENGTH_SHORT).show();
}
};
}
You can try:
Toast.makeText(HelloFormStuff.this,
((RadioButton) v).getText(),
Toast.LENGTH_SHORT).show();
if it crashes, but I don't see any problem with your code.
Here is the main.xml, everything should show up:
<CheckBox android:id="#+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="check it out" />
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton android:id="#+id/radio_red"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Red" />
<RadioButton android:id="#+id/radio_blue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Blue" />
</RadioGroup>
<ToggleButton android:id="#+id/togglebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn="Vibrate on"
android:textOff="Vibrate off"/>
<RatingBar android:id="#+id/ratingbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:stepSize="1.0"/>
I know this is REALLY old, but I just started learning Android and I ran into the same thing. Maybe this will help new-comers I found out that the reason you do not see them is because the value of layout_height for the RadioGroup should be wrap_content. The example says to make it fill_parent. But as you may know by now, the object's height will go to the bottom of the screen.
#Duy's main.xml is correct, but I just wanted to point out the exact reason.