Adding a button - android

I want to create a new button. This code is in my MainActivity.
public void method1 (View view)
{
Button myButton = new Button(this);
myButton.setText("Press Me");
LinearLayout layout = (LinearLayout) findViewById(R.id.layout1);
layout.addView(myButton);
}
I get an error on R.id.layout, saying layoutcan´t be resolved or is not a field. How can I fix it? I am a newbie on Android.
//Edit
my acitvity_main.xml looks like this
<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=".MainActivity" >
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp"
android:onClick="neuerTrainingsplan"
android:text="#string/neuerPlan" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button2"
android:layout_alignBottom="#+id/button2"
android:layout_toLeftOf="#+id/button2"
android:onClick="TrainingsplanAbrufen"
android:text="#string/TrainingsplanAbrufen" />

The error means that you haven't declared a layout with id layout1. If you have check the import from your class in order to import the correct R class. Should be yourpackage.R not android.R

Make sure you made the linear layout in your xml file. And its android:id is layout1.
<LinearLayout android:id="#+id/layout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Add this is in your layout file.

Related

How to call a layout inside the linear layout after clicking the buttons?

I'm learning android and And I'm facing some troubles. I kindly request you to solve these problems.
I have 2 linear layouts inside a linear layout, both are placed horizontally. The left side section contains some buttons and if we click the button the respective layout must come on the right-side section. As of now, if I click the button the specific layout is appearing but not inside the second linear layout. And also, I want to set a default layout to appear on the right side layout. For ex, here I've added the "breakfastdishes.xml", which I want as a default right-side layout, and when I click on the buttons from the left-side layout, according to id the right-side layout must change. Can you please help me to achieve it?
Here is my code:
MenuSection.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MenuSection"
android:background="#drawable/gradient"
android:padding="10dp">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="#+id/breakfast"
android:layout_width="220dp"
android:layout_height="65dp"
android:text="#string/breakfast"
android:textSize="20dp"
android:background="#drawable/menu_category"
android:fontFamily="sans-serif"
android:textStyle="bold"
app:backgroundTint="#AC8E0D"/>
<Button
android:id="#+id/lunch"
android:layout_width="220dp"
android:layout_height="65dp"
android:layout_marginTop="60dp"
android:text="#string/lunch"
android:textSize="20dp"
android:background="#drawable/menu_category"
android:fontFamily="sans-serif"
android:textStyle="bold"
app:backgroundTint="#0A5FAA"/>
<Button
android:id="#+id/eveningSnacks"
android:layout_width="220dp"
android:layout_height="65dp"
android:layout_marginTop="60dp"
android:background="#drawable/menu_category"
android:fontFamily="sans-serif"
android:text="#string/snacks"
android:textSize="20dp"
android:textStyle="bold"
app:backgroundTint="#DF5124" />
<Button
android:id="#+id/dinner"
android:layout_width="220dp"
android:layout_height="65dp"
android:layout_marginTop="60dp"
android:text="#string/dinner"
android:textSize="20dp"
android:background="#drawable/menu_category"
android:fontFamily="sans-serif"
android:textStyle="bold"
app:backgroundTint="#14A61A"/>
</LinearLayout>
</ScrollView>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:id="#+id/itemsDisplay">
<LinearLayout
android:id="#+id/menuDispArea"
android:layout_width="508dp"
android:layout_height="412dp">
<!-- <include-->
<!-- layout="#layout/breakfastdishes"-->
<!-- android:layout_width="508dp"-->
<!-- android:layout_height="412dp" />-->
</LinearLayout>
</ScrollView>
</LinearLayout>
BreakfastDishes.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/gradient"
android:paddingStart="12dp"
android:paddingLeft="10dp"
android:paddingTop="20dp"
android:paddingEnd="12dp"
android:paddingRight="10dp"
android:paddingBottom="20dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:orientation="vertical">
<ImageView
android:id="#+id/burger"
android:layout_width="155dp"
android:layout_height="102dp"
android:layout_x="10dp"
android:layout_y="10dp"
app:srcCompat="#mipmap/burger_breakfast" />
<TextView
android:id="#+id/burgerTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/burger"
android:layout_alignTop="#+id/burger"
android:layout_alignRight="#+id/burger"
android:layout_alignBottom="#+id/burger"
android:layout_gravity="center_horizontal"
android:layout_margin="1dp"
android:gravity="center"
android:text="#string/burger"
android:textColor="#FFF"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:orientation="vertical">
<ImageView
android:id="#+id/eggOmlet"
android:layout_width="160dp"
android:layout_height="104dp"
android:layout_x="233dp"
android:layout_y="7dp"
app:srcCompat="#mipmap/egg_omlet" />
<TextView
android:id="#+id/eggOmletTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/eggOmlet"
android:layout_alignTop="#+id/eggOmlet"
android:layout_alignRight="#+id/eggOmlet"
android:layout_alignBottom="#+id/eggOmlet"
android:layout_gravity="center_horizontal"
android:layout_margin="1dp"
android:gravity="center"
android:text="#string/eggOmlet"
android:textColor="#FFF"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
MenuSection.java
package com.example.restaurant;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MenuSection extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu_section);
Button breakfast = (Button) findViewById(R.id.breakfast);
Button lunch = (Button) findViewById(R.id.lunch);
breakfast.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(MenuSection.this, BreakfastDishes.class);
startActivity(intent);
}
});
lunch.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(MenuSection.this, LunchDishes.class);
startActivity(intent);
}
});
}
#Override
public void onBackPressed(){
//super.onBackPressed();
}
}
Akshay, here are a few things you have to keep in mind ;
In the button click listener you are launching new activity instead of updating
the existing layout. When you use Intent it will launch new activity and
close the current activity. So in your case do not use startActivity
Use findViewById for the menuDispArea layout and add update
the content when user clicks on the button.
never use dp for text size, use sp
you can divide the layout using LinearLayout weights to split your layouts on
all the devices instead of hardcoding the height and width
https://developer.android.com/guide/topics/ui/layout/linear#Weight
edit: Added sample
LayoutInflater inflater = LayoutInflater.from(MenuSection.this);
LinearLayout parentLayout = findViewById(R.id.menuDispArea);
View menuLayout= inflater.inflate(R.layout.BreakfastDishes, parentLayout, false);
parentLayout.addView(menuLayout);
You can use this to inflate any XML in your layout dynamically. Make sure you are doing this inside button onClick for your use case.

Android - Custom Keyboard on manually inflated listview row not showing

Good day.
I have an android application. In my application, I have a custom listView with 5 columns that are textViews. The user can click the rows, once he does, the row layout will change, changing the last 2 textViews to EditTexts. I then register the new EditTexts onto my custom keyboard taken from this example - kindly note that I did a functional copy-paste of his example with regards to the custom keyboard class and how to make it work in the main layout. However, when I click the EditText in the row, my custom keyboard does not show up at all.
I have a global variable as such:
CustomKeyboard mCustomKeyboard;
And in my onCreate() method in the activity, I do:
mCustomKeyboard= new CustomKeyboard(this, R.id.keyboardview, R.xml.custom_keyboard);
This is my layout, I have the KeyboardView at the bottom of the 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:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".SearchResult" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- A lot of views go here, enclosed in my linear layout -->
</LinearLayout>
<android.inputmethodservice.KeyboardView
android:id="#+id/keyboardview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:visibility="gone" />
</RelativeLayout>
Here is the code that changes the layout. What I do is that I take the row values from the old layout, get the new layout search_result_inflate, then set the texts of the new layout using the values I got. Kindly note the mCustomKeyboard.registerEditText(R.id.qtyInputSearchResult); line after inflating the layout:
private void changeLayout(final View view){
//get views from old layout
TextView textViewQuantity = (TextView)view.findViewById(R.id.qtyInput);
TextView textViewDiscountReq = (TextView)view.findViewById(R.id.discInput);
TextView textViewName = (TextView)view.findViewById(R.id.dialogItemName);
TextView textViewPrice = (TextView)view.findViewById(R.id.price);
TextView textViewDiscount = (TextView)view.findViewById(R.id.discount);
//store values in strings
String itemName = textViewName.getText().toString();
String itemPrice = textViewPrice.getText().toString();
String itemDiscount = textViewDiscount.getText().toString();
String itemQty = textViewQuantity.getText().toString();
String itemDisc = textViewDiscountReq.getText().toString();
//set the view to gone
textViewQuantity.setVisibility(View.GONE);
textViewDiscountReq.setVisibility(View.GONE);
textViewName.setVisibility(View.GONE);
textViewPrice.setVisibility(View.GONE);
textViewDiscount.setVisibility(View.GONE);
//get the old layout
LinearLayout ll_inflate = (LinearLayout)view.findViewById(R.id.search_result_layout);
//get the inflate/new view
View child = getLayoutInflater().inflate(R.layout.search_result_inflate, null);
//get the views in the new view, populate them
TextView newName = (TextView)child.findViewById(R.id.dialogItemName);
newName.setText(itemName);
TextView newDiscount = (TextView)child.findViewById(R.id.discount);
newDiscount.setText(itemDiscount);
TextView newPrice = (TextView)child.findViewById(R.id.price);
newPrice.setText(itemPrice);
EditText qtyInput = (EditText)child.findViewById(R.id.qtyInputSearchResult);
qtyInput.setText(itemQty);
EditText discInput = (EditText)child.findViewById(R.id.discInputSearchResult);
discInput.setText(itemDisc);
//show new layout
ll_inflate.removeAllViews();
ll_inflate.removeAllViewsInLayout();
ll_inflate.addView(child);
mCustomKeyboard.registerEditText(R.id.qtyInputSearchResult);
}
Here is my search_result_inflate.xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/search_result_inflate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:minHeight="50dp"
android:orientation="horizontal"
android:padding="1dip"
android:weightSum="1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="horizontal"
android:padding="1dip" >
<TextView
android:id="#+id/dialogItemName"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="2dp"
android:layout_weight="0.54"
android:gravity="center"
android:text="Item Name"
android:textSize="23sp" />
<TextView
android:id="#+id/price"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="2dp"
android:layout_weight="0.14"
android:gravity="center"
android:text="Price"
android:textSize="23sp" />
<TextView
android:id="#+id/discount"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="2dp"
android:layout_weight="0.10"
android:gravity="center"
android:text="Discount"
android:textSize="23sp" />
<EditText
android:id="#+id/qtyInputSearchResult"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="2dp"
android:layout_weight="0.14"
android:background="#layout/edittext_selector"
android:gravity="center"
android:hint="qtyInput"
android:textColorHighlight="#color/white_opaque"
android:textSize="23sp" >
</EditText>
<EditText
android:id="#+id/discInputSearchResult"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.11"
android:background="#layout/edittext_selector"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center"
android:hint="discInput"
android:textColorHighlight="#color/white_opaque"
android:textSize="23sp" />
</LinearLayout>
</LinearLayout>
As you can see, I have 2 editTexts and I registered qtyInputSearchResult to the custom keyboard class. However, the custom keyboard does not show up.
I also tried to use the custom keyboard class on an editText in another activity and it works just fine. Am I missing something here? I'm confused as to why the custom keyboard does not show up properly.
Any help is very much appreciated, thank you.
Got it, I placed the keyboard layout in the search_result_inflate.xml like so:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/search_result_inflate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:minHeight="50dp"
android:orientation="horizontal"
android:padding="1dip"
android:weightSum="1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="horizontal"
android:padding="1dip" >
<!-- a lot of components here -->
</LinearLayout>
<android.inputmethodservice.KeyboardView
android:id="#+id/keyboardview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:visibility="gone" />
</RelativeLayout>

Horizontal Scroll View One Child(Eclipse IDE, Android)

I realize there many related problems, but I'm looking for this specific answer. The below code is my XML for my mainactivity in an app. Now my question. I would like to be able to alter the contents of the horizontal view, dynamically. This will involve clearing it of Views as well as adding new ones. How exactly do I go about doing this, as well as accessing the Linear Layout within it, when I tried to assign an ID to the Linear Layout I was given an error saying it could not accept a id of type string.
<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=".MainActivity" >
<TextView
android:id="#+id/txtClassification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Classification:<>"
android:textAppearance="?android:attr/textAppearanceLarge"
tools:ignore="HardcodedText" />
<Spinner
android:id="#+id/spinGoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="56dp" />
<Button
android:id="#+id/btnBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="Go Back"
tools:ignore="HardcodedText" />
<Button
android:id="#+id/btnSelect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Select"
tools:ignore="HardcodedText" />
<HorizontalScrollView
android:id="#+id/gallery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/txtClassification"
android:layout_alignRight="#+id/spinGoto"
android:layout_below="#+id/txtClassification" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
</LinearLayout>
</HorizontalScrollView>
<ImageView
android:id="#+id/myImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</RelativeLayout>
All help is greatly appreciated!
You will have to work with the LinearLayout because a HorizontalScrollView can only have one direct child.
<HorizontalScrollView
android:id="#+id/gallery"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/txtClassification" >
<LinearLayout
android:id="#+id/yourLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
</HorizontalScrollView>
Then you access it programmatically to add or remove views
public void addView(View v) {
LinearLayout yourLayout = (LinearLayout) findViewById(R.id.yourLayout);
yourLayout.addView(v);
}
public void clearLayout() {
LinearLayout yourLayout = (LinearLayout) findViewById(R.id.yourLayout);
yourLayout.removeAllViews();
}
public void removeView(View v) {
LinearLayout yourLayout = (LinearLayout) findViewById(R.id.yourLayout);
yourLayout.removeView(v);
}
hope this helps
The id has a predifined format. Enter the name you want after the "#+id/" syntax. Example android:id="#+id/layout".
Then in code get the LinearLayoutinside of the HorizontalScrollView:
LinearLayout layout = findViewById(R.id.layout);
To add a View to layout call the adView() of your layout. Example:
//add 5 buttons
for (int i = 1; i <= 5 ; i++){
Button btn = new Button(this);
btn.setId(i);
btn.setText(i+"");
layout.addView(btn);
}
To remove a View from the layout call removeView()
//remove button nr. 3
Button btn3 = layout.findViewById(3);
layout.removeView(btn3);
The HorizontalScrollView takes care of everything, you just have to populate and organize the elements inside the nested LinearLayout.
Good luck!

applying setLayoutParams on a button programmatically causes the whole layout to get mixed and abnormal

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" >
<Button
android:id="#+id/insertButtonVIEW"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="insert" />
<Button
android:id="#+id/removeButtonVIEW"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="remove" />
</LinearLayout>
</RelativeLayout>
Sometimes, depending on a situaiton, I am hiding removeButtonVIEW using the method setVisibility(View.INVISIBLE);
When that happens, I want to my insertButtonVIEW to take the whole width of the screen (when the two are present, each one takes 50% of the screen).
Since this might or might not happen, I am doing these changes programmatically.
I tried the following methd which worked, however, it is causing for all the interface to go jumbo mumbo, as everything's location on the screen is getting mixed.
modifyButton.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
Any hints ?
UPDATE 1 after applying the answer :
I am using the following code to set the button to invisible.
Bundle extras;
extras = getIntent().getExtras();
String answer = extras.getString("answer");
if(answer.equalsIgnoreCase("yes")
{
insertButton.setEnabled(true);
insertButton.setText("INSERT");
removeButton.setVisibility(View.INVISIBLE);
}
else
{
//whatever
}
// I Have modify your code now try this one and you don't required set LayoutParams ().
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" >
<Button
android:id="#+id/insertButtonVIEW"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="insert" />
<Button
android:id="#+id/removeButtonVIEW"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="remove" />
</LinearLayout>
</RelativeLayout>
if(answer.equalsIgnoreCase("yes")
{
insertButton.setEnabled(true);
insertButton.setText("INSERT");
removeButton.setVisibility(View.GONE);
}
else
{
//whatever
}
Use
setVisibility(View.GONE);
*Remove this *
modifyButton.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
And set
android:layout_width="0dp"
in both button

Why doesn't Eclipse detect new onClick method I've added in my layout file

Here is my full layout file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:onClick="showButtons"
android:text="#string/buttons_label" />
</RelativeLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/relativeLayout1"
android:layout_centerHorizontal="true"
android:onClick="showSpinners"
android:text="#string/spinners_label" />
</RelativeLayout>
And here is where I call showSpinners:
private void showSpinners(View clickedButton){
goToActivity(SpinnerActivity.class);
}
Eclipse underlines in yellow showSpinners by saying it's never used locally, my guess is it is not detecting my onClick attribute in the layout file.
I'm wondering why it just wont work and what I should do to make it work...
Change the your method to :
public void showSpinners(View clickedButton) {
// do the work
}
The method needs to be visible outside the class (source).

Categories

Resources