java.lang.NoSuchMethodError: android.app.Dialog.create - java

I have created custom Dialog layout. When user press on the button the dialog is shown. Android version lollipop shows me the dialog perfectly but in case of lower version than lollipop it throws me error.
Here is my code:
public class MainActivity extends AppCompatActivity {
private Button click;
private Dialog dialog;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
click=(Button)findViewById(R.id.click);
click.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(v.equals(click))
{
dialog=new Dialog(MainActivity.this);
dialog.setContentView(R.layout.check_in_weight_dialog);
dialog.create();
dialog.show();
}
}
});
}
And here is my custom dialog layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:padding="16dp"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="10">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Check In Weight"
android:textColor="#android:color/black"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Medium"
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="20dp"
android:layout_weight="20">
<EditText
android:layout_width="match_parent"
android:layout_height="40dp"
android:inputType="number"
android:hint="Current Weight"
android:background="#drawable/editext_border"
android:id="#+id/edtCheckInWhgt"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="center"
android:layout_marginTop="20dp"
android:layout_weight="10">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OK"
android:gravity="center"
android:id="#+id/btncheckin"
android:textColor="#android:color/holo_blue_light"
android:background="?android:attr/selectableItemBackground"/>
</LinearLayout>
</LinearLayout>

dialog.create();
this is for lolipop only. Remove this line

Try this way ,It works fine (Lolipop)
custom_dialog = new Dialog(this,android.R.style.Theme_Holo_Light_Dialog_MinWidth);
custom_dialog.getWindow().setBackgroundDrawable(new ColorDrawable((0xff000000)));
custom_dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
custom_dialog.setCancelable(false);
custom_dialog.setContentView(R.layout.check_in_weight_dialog);
custom_dialog.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, Color.parseColor("#FFFFFF"));
custom_dialog.show();
Or Remove dialog.create();
dialog=new Dialog(MainActivity.this);
dialog.setContentView(R.layout.check_in_weight_dialog);
dialog.show();

Related

Android bottom sheet does not collapse

I'm trying to create a simple Bottom Sheet layout, One button shows and other collapse, but its not working. I was following this tutorial but still nothing.So I'm trying to pass the state inside of buttons and then pass into the callback method to hide or expand, and the bottom sheet can't be scrolled down!
This is the layout.
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/activity_botton_test"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="24dp">
<Button
android:id="#+id/button_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button 1"
android:padding="16dp"
android:layout_margin="8dp"
android:textColor="#android:color/white"
android:background="#android:color/holo_green_dark"/>
<Button
android:id="#+id/button_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:layout_margin="8dp"
android:text="Button 2"
android:textColor="#android:color/white"
android:background="#android:color/holo_blue_light"/>
<Button
android:id="#+id/button_3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:layout_margin="8dp"
android:text="Button 3"
android:textColor="#android:color/white"
android:background="#android:color/holo_red_dark"/>
</LinearLayout>
</ScrollView>
<android.support.v4.widget.NestedScrollView
android:id="#+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="350dp"
android:clipToPadding="true"
android:background="#android:color/holo_orange_light"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="opaa"
android:padding="16dp"
android:textSize="16sp"/>
</android.support.v4.widget.NestedScrollView>
Activity :
private View bottomSheet;
private Button button1,button2,button3;
private BottomSheetBehavior mBottomSheetBehavior;
bottomSheet = findViewById( R.id.bottom_sheet );
button1 = (Button)findViewById(R.id.button_1);
button2 = (Button)findViewById(R.id.button_2);
button3 = (Button)findViewById(R.id.button_3);
mBottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
mBottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
#Override
public void onStateChanged(View bottomSheet, int newState) {
if (newState == BottomSheetBehavior.STATE_COLLAPSED) {
mBottomSheetBehavior.setPeekHeight(0);
}
if(newState == BottomSheetBehavior.STATE_EXPANDED){
mBottomSheetBehavior.setPeekHeight(500);
}
}
#Override
public void onSlide(View bottomSheet, float slideOffset) {
}
});
button1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}
});
button2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
});
I ran into the same issue when trying that tutorial myself.
You have to set the BottomSheetBehavior to be hideable. Moreover, the COLLAPSED state may not be what you are looking for. To make the BottomSheet disappear completely, you have to set the state to HIDDEN. Like this:
mBottomSheetBehavior.setHideable(true);
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
Put TextView into LinearLayout

How to wrap alertdialog in android?

I would like to ask on how to achieve to wrap a content in alertdialog?
Because the current output of my dialog has an excess white field.
Hope someone can help me to understand this problem thanks.
Here is my activity_dialog.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:minWidth="10dp"
android:minHeight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:context="com.bloxofcode.toggle.MainActivity">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="50sp"
android:background="#color/colorHeaderDialog"
android:textColor="#android:color/white"
android:text="#string/select_gender"
android:padding="15dp"
android:gravity="center_horizontal|left"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:padding="15dp"
android:text="Sample"
android:id="#+id/editText" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ToggleButton
android:text="ToggleButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/toggleButtonMale"
android:textOn=""
android:textOff=""
android:focusable="false"
android:background="#drawable/check_male"
android:layout_weight="1" />
<ToggleButton
android:text="ToggleButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/toggleButtonFemale"
android:textOn=""
android:textOff=""
android:focusable="false"
android:background="#drawable/check_male"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp">
<Button
android:id="#+id/btnCancel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Cancel"
android:textSize="20dp"
android:padding="30dp"
android:textColor="#android:color/white"
android:layout_weight="1"/>
<Button
android:id="#+id/btnAccept"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Accept"
android:textSize="20dp"
android:padding="30dp"
android:background="#color/colorDialogOK"
android:textColor="#android:color/white"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Here is some of my implementation in the MainActivity.java:
AlertDialog.Builder mBuilder = new AlertDialog.Builder(MainActivity.this);
View mView = getLayoutInflater().inflate(R.layout.activity_dialog, null);
.....
mBuilder.setView(mView);
final AlertDialog dialog = mBuilder.create();
dialog.show();
Try Creating a dialog like this. this works perfect and then right away your dialog logic is seperated from you activity logic
public class CustomDialog extends Dialog implements
android.view.View.OnClickListener {
public Activity c;
public CustomDialog d;
public Button yes, no;
public CustomDialog(Activity a) {
super(a);
// TODO Auto-generated constructor stub
this.c = a;
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.dialog_layout);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//dosomething
}
});
}
}
Hope it is not correct to wrap the content of dialog as it might disrupt the view in tablets and larger devices.
Anyhow, basing upon your requirement.. hope this link works
AlertDialog with custom view: Resize to wrap the view's content

How to make a pop up image like an advertisement? [Android]

I've encountered a lot of pop up images like the example below, i've made a pop up image but there is no close button at the top left corner, do u guys have any idea how to make a pop up image with close button at the top left cornel like the example below in Android?
You need to make your own Dialog with your custom layout
Dialog dialog;
private void showDialog() {
// custom dialog
dialog = new Dialog(this);
dialog.setContentView(R.layout.custom_dialog);
// set the custom dialog components - text, image and button
ImageButton close = (ImageButton) dialog.findViewById(R.id.btnClose);
Button buy = (Button) dialog.findViewById(R.id.btnBuy);
// Close Button
close.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
//TODO Close button action
}
});
// Buy Button
buy.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
//TODO Buy button action
}
});
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();
}
custom_dialog.xml
<?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">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:background="#android:color/white"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/images" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<Button
android:id="#+id/btnBuy"
android:layout_width="80dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#android:color/holo_green_light"
android:text="BUY"
android:textColor="#android:color/white" />
<TextView
android:id="#+id/txtTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/btnBuy"
android:text="Thank You (Domestic Album Version)"
android:textColor="#android:color/black"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/txtTitle"
android:text="Still Not Gettin' Any, 2004" />
</RelativeLayout>
</LinearLayout>
<ImageButton
android:id="#+id/btnClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#android:color/black"
android:src="#android:drawable/ic_menu_close_clear_cancel" />
</RelativeLayout>
Result is:
You can use this library. There is close button on top right corner. only need to set image only.
https://github.com/chathuralakmal/AndroidImagePopup

Android background color for accordion menu

I want the code in the Java file to set the background color of whatever button was clicked, and keep it, even after you let go of the button. Thanks in advance
I don't really get the formatting on here. I hope it's clear what belongs where.
Java:
package mika.actual;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class accordion extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.accordian);
Button btnProfile = (Button) findViewById(R.id.btnProfile);
Button btnSettings = (Button) findViewById(R.id.btnSettings);
Button btnPrivacy = (Button) findViewById(R.id.btnPrivacy);
View panelProfile = findViewById(R.id.panelProfile);
panelProfile.setVisibility(View.GONE);
View panelSettings = findViewById(R.id.panelSettings);
panelSettings.setVisibility(View.GONE);
View panelPrivacy = findViewById(R.id.panelPrivacy);
panelPrivacy.setVisibility(View.GONE);
btnProfile.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// DO STUFF
View panelProfile = findViewById(R.id.panelProfile);
panelProfile.setVisibility(View.VISIBLE);
View panelSettings = findViewById(R.id.panelSettings);
panelSettings.setVisibility(View.GONE);
View panelPrivacy = findViewById(R.id.panelPrivacy);
panelPrivacy.setVisibility(View.GONE);
}
});
btnSettings.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// DO STUFF
View panelProfile = findViewById(R.id.panelProfile);
panelProfile.setVisibility(View.GONE);
View panelSettings = findViewById(R.id.panelSettings);
panelSettings.setVisibility(View.VISIBLE);
View panelPrivacy = findViewById(R.id.panelPrivacy);
panelPrivacy.setVisibility(View.GONE);
}
});
btnPrivacy.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// DO STUFF
View panelProfile = findViewById(R.id.panelProfile);
panelProfile.setVisibility(View.GONE);
View panelSettings = findViewById(R.id.panelSettings);
panelSettings.setVisibility(View.GONE);
View panelPrivacy = findViewById(R.id.panelPrivacy);
panelPrivacy.setVisibility(View.VISIBLE);
}
});
}
}
XML:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/root_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFFFF"
android:orientation="vertical">
<Button
android:id="#+id/btnProfile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Profile"
android:textColor="#FFFFFFFF" />
<LinearLayout
android:id="#+id/panelProfile"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#FFFFFFFF">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFFFF">
<LinearLayout
android:id="#+id/panelProfile1"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFFFF">
<TextView
android:id="#+id/strName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name" />
<EditText
android:id="#+id/txtName"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="#+id/panelProfile2"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFFFF">
<TextView
android:id="#+id/strSurname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Surname" />
<EditText
android:id="#+id/txtSurname"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
<Button
android:id="#+id/btnSettings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Settings"
android:textColor="#FFFFFFFF" />
<LinearLayout
android:id="#+id/panelSettings"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#FFFFFFFF">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="#+id/panelSettings1"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFFFF">
<TextView
android:id="#+id/strMail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="e-mail" />
<EditText
android:id="#+id/txtMail"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="#+id/panelSettings2"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFFFF">
<TextView
android:id="#+id/strPhone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Phone" />
<EditText
android:id="#+id/txtPhone"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
<Button
android:id="#+id/btnPrivacy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Privacy"
android:textColor="#FFFFFFFF" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/panelPrivacy"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#FFFFFFFF">
<CheckBox
android:id="#+id/checkFacebook"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Facebook"
android:textColor="#ff355689">
</CheckBox>
<CheckBox
android:id="#+id/checkLinkedIn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="LinkedIn"
android:textColor="#ff355689">
</CheckBox>
<CheckBox
android:id="#+id/checkTwitter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Twitter"
android:textColor="#ff355689">
</CheckBox>
</LinearLayout>
</ScrollView>
</LinearLayout>
If I understood correctly, what you want to do is, when clicking a button and expanding its sub-menu, change the background of that button until it is clicked again. You can do this with a Tag on the Button:
btnSettings.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// DO STUFF
//if button is not selected, change background and tag the View as selected
if(v.getTag() == null || v.getTag().equals("not_selected")) {
v.setBackgroundColor(Color.RED);
v.setTag("selected");
//show sub-menu
}
//if button is already selected, reset background and tag the View as not selected
else{
v.setBackgroundResource(android.R.drawable.btn_default);
v.setTag("not_selected");
//hide sub menu
}
}
});
Notice that v.setBackgroundResource(android.R.drawable.btn_default); is resetting the Button background to an android drawable. You may want to change this to a custom drawable or color.
You could have used an ExpandableListView to implement this kind of menu.
button.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
view.setBackgroundColor(ContextCompat.getColor(context, R.color.presed_color));
} else if (event.getAction() == MotionEvent.ACTION_UP) {
view.setBackgroundColor(ContextCompat.getColor(context, R.color.unpresed_color));
}
return false;
}
});

Android addListenerOnButton issue

I'm trying to create an application with 5 buttons on the main page. For some reason the ListenerOnButton is not working and the app will close before showing xml buttons layout.
Here's my MainActivity:
public class MainListActivity extends Activity {
ImageButton news;
ImageButton weather;
ImageButton counter;
ImageButton fakoi;
ImageButton gyalia;
ImageButton uvindex;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
addListenerOnButton();
}
public void addListenerOnButton() {
news = (ImageButton) findViewById(R.id.news);
weather = (ImageButton) findViewById(R.id.weather);
fakoi = (ImageButton) findViewById(R.id.fakoi);
gyalia = (ImageButton) findViewById(R.id.gyalia);
uvindex = (ImageButton) findViewById(R.id.uvindex);
news.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent
(getApplicationContext(), MyOrasisNews.class);
startActivity(intent);
}
});
weather.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent
(getApplicationContext(), MainActivity.class);
startActivity(intent);
}
});
gyalia.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent
(getApplicationContext(), GyaliaActivity.class);
startActivity(intent);
}
});
fakoi.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent
(getApplicationContext(), FakoiActivity.class);
startActivity(intent);
}
});
uvindex.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent
(getApplicationContext(), UvMainActivity.class);
startActivity(intent);
}
});
}
}
And this is the xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/db1_root"
android:background="#drawable/bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:layout_width="fill_parent"
android:layout_height="0dp"
android:weightSum="1"
android:layout_weight="0.5">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5">
<Button
android:id="#+id/news"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/homebg"
android:gravity="center|bottom"
android:paddingBottom="10dp"
android:singleLine="false"
android:text="News"
android:textSize="18sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/news"
android:layout_centerInParent="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5">
<Button
android:id="#+id/weather"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/homebg"
android:gravity="center|bottom"
android:paddingBottom="10dp"
android:singleLine="false"
android:text="Weather"
android:textSize="18sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/weather"
android:layout_centerInParent="true"/>
</RelativeLayout>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="0dp"
android:weightSum="1"
android:layout_weight="0.5">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5">
<Button
android:id="#+id/uvindex"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/homebg"
android:gravity="center|bottom"
android:paddingBottom="10dp"
android:text="Uv Index"
android:textSize="18sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/uvindex"
android:layout_centerInParent="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5">
<Button
android:id="#+id/fakoi"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/homebg"
android:gravity="center|bottom"
android:paddingBottom="10dp"
android:text="S Fakwn"
android:textSize="18sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/sfakon"
android:layout_centerInParent="true"/>
</RelativeLayout>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="0dp"
android:weightSum="1"
android:layout_weight="0.5">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5">
<Button
android:id="#+id/gyalia"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/homebg"
android:gravity="center|bottom"
android:paddingBottom="10dp"
android:text="S gyalion"
android:textSize="18sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/sgyalion"
android:layout_centerInParent="true"/>
</RelativeLayout>
</TableRow>
</TableLayout>
</LinearLayout>
Any help will be appreciated.
you defined Buttons in your xml but you are trying to cast them to ImageButton. change type of your ImageButtons to Button.
You try to cast Button to ImageButton.
In your XML file change the Button to ImageButton or in your activity change the ImageButton to Button.

Categories