FloatingActionButton Click Event not working - java

I have a floating action button in the following layout file activity_register :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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=".MainActivity">
<FrameLayout
android:paddingTop="70dp"
android:layout_width="320dp"
android:layout_height="400dp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true">
<android.support.v7.widget.CardView
android:id="#+id/cv_RegisterAdd"
app:cardBackgroundColor="#009688"
android:layout_marginTop="10dp"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="320dp"
app:cardCornerRadius="6dp"
app:cardElevation="3dp"
app:cardUseCompatPadding="true"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_marginTop="50dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:text="REGISTER"
android:textColor="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold"
/>
<LinearLayout
android:layout_marginTop="10dp"
android:paddingStart="50dp"
android:paddingEnd="30dp"
android:layout_width="match_parent"
android:layout_height="40dp">
<android.support.design.widget.TextInputLayout
android:textColorHint="#f0f7f4"
android:layout_width="match_parent"
android:theme="#style/TextLabel"
android:layout_height="wrap_content">
<EditText
android:textAppearance="?android:attr/textAppearanceMedium"
android:hint="Username"
android:textColor="#f0f7f4"
android:id="#+id/txtCurUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:background="#drawable/selector_bg_edit_2"
android:textCursorDrawable="#drawable/bg_input_cursor_2"
android:paddingBottom="2dp"
/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:paddingStart="50dp"
android:paddingEnd="30dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="40dp">
<android.support.design.widget.TextInputLayout
android:textColorHint="#FFFFFF"
android:theme="#style/TextLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:textAppearance="?android:attr/textAppearanceMedium"
android:hint="Password"
android:textColor="#f0f7f4"
android:id="#+id/txtNewPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:background="#drawable/selector_bg_edit_2"
android:textCursorDrawable="#drawable/bg_input_cursor_2"
android:paddingBottom="2dp"
/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:paddingStart="50dp"
android:paddingEnd="30dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="40dp">
<android.support.design.widget.TextInputLayout
android:textColorHint="#f0f7f4"
android:theme="#style/TextLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#f0f7f4"
android:hint="Repeat Password"
android:id="#+id/txtRepeatPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:background="#drawable/selector_bg_edit_2"
android:textCursorDrawable="#drawable/bg_input_cursor_2"
android:paddingBottom="2dp"
/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<Button
android:layout_marginTop="20dp"
android:layout_gravity="center_horizontal"
android:stateListAnimator="#drawable/state_list_animator_z"
android:id="#+id/btn_Register"
android:text="REGISTER"
android:textColor="#009688"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="200dp"
android:layout_height="40dp"
android:background="#drawable/register_btnshape"
>
</Button>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fb_Cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fabSize="normal"
android:src="#drawable/plus_x"
android:transitionName="loginFab"
android:layout_gravity="center_horizontal|top" />
</FrameLayout>
</RelativeLayout>
In the activity I have set a Click event on the floating action button.
I have been debugging and checking to see if the event is ever fired and the click event is never fired. The RegisterActivity code is as follows:
public class RegisterActivity extends AppCompatActivity
{
#BindView(R.id.fb_Cancel)
FloatingActionButton mClose_fb;
#BindView(R.id.btn_Register)
Button mRegister_btn;
#BindView(R.id.cv_RegisterAdd)
CardView mRegister_cv;
#Override
public void onCreate(#Nullable Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
ButterKnife.bind(this);
getSupportActionBar().hide();
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
showEnterAnimation();
}
mClose_fb.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v)
{
animationRevealClose();
}
});
}
public void showEnterAnimation()
{
Transition transition = TransitionInflater.from(this).inflateTransition(R.transition.fabtransition);
getWindow().setSharedElementEnterTransition(transition);
transition.addListener(new Transition.TransitionListener() {
#Override
public void onTransitionStart(Transition transition) {
mRegister_cv.setVisibility(View.GONE);
}
#Override
public void onTransitionEnd(Transition transition) {
transition.removeListener(this);
animateRevealShow();
}
#Override
public void onTransitionCancel(Transition transition) {
}
#Override
public void onTransitionPause(Transition transition) {
}
#Override
public void onTransitionResume(Transition transition) {
}
});
}
public void animationRevealClose()
{
Animator mAnimator = ViewAnimationUtils.createCircularReveal(mRegister_cv,mRegister_cv.getWidth()/2,0, mRegister_cv.getHeight(), mClose_fb.getWidth() / 2);
mAnimator.setDuration(500);
mAnimator.setInterpolator(new AccelerateInterpolator());
mAnimator.addListener(new AnimatorListenerAdapter()
{
#Override
public void onAnimationEnd(Animator animation)
{
mRegister_cv.setVisibility(View.INVISIBLE);
super.onAnimationEnd(animation);
mClose_fb.setImageResource(R.drawable.plus);
RegisterActivity.super.onBackPressed();
}
#Override
public void onAnimationStart(Animator animation) {
super.onAnimationStart(animation);
}
});
}
public void animateRevealShow()
{
Animator mAnimator = ViewAnimationUtils.createCircularReveal(mRegister_cv, mRegister_cv.getWidth()/2,0, mClose_fb.getWidth() / 2, mRegister_cv.getHeight());
mAnimator.setDuration(500);
mAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
mAnimator.addListener(new AnimatorListenerAdapter()
{
#Override
public void onAnimationEnd(Animator animation)
{
super.onAnimationEnd(animation);
}
#Override
public void onAnimationStart(Animator animation)
{
mRegister_cv.setVisibility(View.VISIBLE);
super.onAnimationStart(animation);
}
});
mAnimator.start();
}
#Override
public void onBackPressed() {
animationRevealClose();
}

the method which annotated with #OnClick should be out of onCreate.
#Override
public void onCreate(#Nullable Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
ButterKnife.bind(this);
//--------------------------TODO---------------------//
//----------Set a click event for the floating action button
}
#OnClick({R.id.btn_Login, R.id.fb_Register})
public void onClick(View view)
{
}

#OnClick(R.id.take_photo) void openCameraIntent()
{
openCameraIntent1();
}
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera);
initialize();
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(getApplicationContext());
}
private void initialize()
{
btnSavePhoto = findViewById(R.id.btn_save);
photoView = findViewById(R.id.imageView);
photoViewUnuse = findViewById(R.id.imageViewUnuse);
previewPhotoText = findViewById(R.id.preview_text);
btnSavePhoto.setOnClickListener(view -> submitDataToServer());
ButterKnife.bind(this);
}

Related

inputData to send data to mainActivity error using Realm Database instant crash

I have a problem that when I press the Fab button the app instant close and I don't know how to fix it, my goal was when pressing the fab button and inserting the data it will send the data to the MainActivity.xml and make a list of item
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Income"
android:textSize="24dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="0"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Expenses"
android:textSize="24dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="0"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Balance"
android:textSize="24dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="0"
android:textSize="20dp" />
</LinearLayout>
</LinearLayout>
<ListView
android:id="#+id/listView"
app:layout_anchor="#id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="80dp">
</ListView>
<com.google.android.material.bottomappbar.BottomAppBar
android:id="#+id/bottomAppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:fabCradleMargin="10dp"
app:fabCradleVerticalOffset="10dp"
app:fabCradleRoundedCornerRadius="20dp"
android:layout_gravity="bottom">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/bottomNavigationView"
app:menu="#menu/bottom_nav_menu"
android:layout_marginEnd="10dp"/>
</com.google.android.material.bottomappbar.BottomAppBar>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/fab"
android:src="#drawable/add_button"
app:layout_anchor="#id/bottomAppBar"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
activity_input_data.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"
android:orientation="vertical"
tools:context=".InputDataActivity">
<LinearLayout
android:layout_marginTop="200dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginBottom="200dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:textAlignment="center"
android:textSize="50dp"
android:textStyle="bold"
android:text="Input Data"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/txtTitle"
android:hint="Title..."
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/txtAmount"
android:hint="Amount..."
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/txtDate"
android:hint="Date..."
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:id="#+id/addButton"
android:text="Add"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="20dp">
<ImageView
android:src="#drawable/profile_button"
android:layout_width="50dp"
android:layout_height="50dp"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/title"
android:layout_gravity="end"
android:textSize="16dp"
android:textStyle="bold"
android:text="Main Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/amount"
android:layout_gravity="end"
android:textSize="14dp"
android:textStyle="bold"
android:text="Rp. 20.000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/date"
android:layout_gravity="end"
android:textSize="12dp"
android:textStyle="bold"
android:text="23-06-2021"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/spinner"
android:layout_gravity="end"
android:textSize="14dp"
android:textStyle="bold"
android:text="Expense"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity {
ListView listView;
MyHelper myHelper;
BottomNavigationView bottomNavigationView;
FloatingActionButton floatingActionButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bottomNavigationView = findViewById(R.id.bottomNavigationView);
floatingActionButton = findViewById(R.id.fab);
//ListView Adapter
ListViewAdapter adapter = new ListViewAdapter(this, myHelper.justRefresh());
listView.setAdapter(adapter);
floatingActionButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, InputDataActivity.class);
startActivity(intent);
}
});
//Bottom Nav
bottomNavigationView.setBackground(null);
bottomNavigationView.getMenu().getItem(2).setEnabled(false);
}
}
InputDataActivity.java
public class InputDataActivity extends AppCompatActivity {
EditText txtTitle, txtAmount,txtDate;
Button button;
Realm realm;
ListView listView;
MyHelper myHelper;
RealmChangeListener realmChangeListener;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_input_data);
realm = Realm.getDefaultInstance();
txtTitle = findViewById(R.id.txtTitle);
txtAmount = findViewById(R.id.txtAmount);
txtDate = findViewById(R.id.txtDate);
button = findViewById(R.id.addButton);
listView = findViewById(R.id.listView);
//MyHelper
myHelper = new MyHelper(realm);
myHelper.selectFromDB();
//ListView Adapter
ListViewAdapter adapter = new ListViewAdapter(this, myHelper.justRefresh());
listView.setAdapter(adapter);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
saveData();
}
});
Refresh();
}
private void saveData(){
realm.executeTransactionAsync(new Realm.Transaction() {
#Override
public void execute(Realm realm) {
Number maxId = realm.where(User.class).max("title_id");
int newKey = (maxId == null) ? 1 : maxId.intValue()+1;
User user = realm.createObject(User.class, newKey);
user.setTitle_name(txtTitle.getText().toString());
user.setAmount(txtAmount.getText().toString());
user.setDate(txtDate.getText().toString());
}
}, new Realm.Transaction.OnSuccess() {
#Override
public void onSuccess() {
Toast.makeText(InputDataActivity.this, "Success", Toast.LENGTH_SHORT).show();
}
}, new Realm.Transaction.OnError() {
#Override
public void onError(Throwable error) {
Toast.makeText(InputDataActivity.this, "Fail", Toast.LENGTH_SHORT).show();
}
});
}
private void Refresh(){
realmChangeListener = new RealmChangeListener() {
#Override
public void onChange(Object o) {
ListViewAdapter adapter = new ListViewAdapter(InputDataActivity.this, myHelper.justRefresh());
listView.setAdapter(adapter);
}
};
realm.addChangeListener(realmChangeListener);
}
#Override
protected void onDestroy() {
super.onDestroy();
realm.removeChangeListener(realmChangeListener);
realm.close();
}
}
MyHelper.java
public class MyHelper {
Realm realm;
RealmResults<User> users;
public MyHelper(Realm realm) {
this.realm = realm;
}
public void selectFromDB(){
users = realm.where(User.class).findAll();
}
public ArrayList<User> justRefresh(){
ArrayList<User> listItem = new ArrayList<>();
for(User user: users){
listItem.add(user);
}
return listItem;
}
}
User.java
public class User extends RealmObject {
#PrimaryKey
private int title_id;
private String title_name;
private String amount;
private String date;
private String spinner;
public int getTitle_id() {
return title_id;
}
public void setTitle_id(int title_id) {
this.title_id = title_id;
}
public String getTitle_name() {
return title_name;
}
public void setTitle_name(String title_name) {
this.title_name = title_name;
}
public String getAmount() {
return amount;
}
public void setAmount(String amount) {
this.amount = amount;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getSpinner() {
return spinner;
}
public void setSpinner(String spinner) {
this.spinner = spinner;
}
}
ListViewAdapter.java
public class ListViewAdapter extends BaseAdapter {
Context context;
ArrayList<User> users;
public ListViewAdapter(Context context, ArrayList<User> users) {
this.context = context;
this.users = users;
}
#Override
public int getCount() {
return users.size();
}
#Override
public Object getItem(int position) {
return users.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater =(LayoutInflater)context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
view =inflater.inflate(R.layout.list_item, parent,false);
TextView title,amount,date,spinner;
title =view.findViewById(R.id.title);
amount = view.findViewById(R.id.amount);
date = view.findViewById(R.id.date);
spinner = view.findViewById(R.id.spinner);
User u = (User)this.getItem(position);
title.setText(u.getTitle_name());
amount.setText(u.getAmount());
date.setText(u.getDate());
spinner.setText(u.getSpinner());
int numPosition = u.getTitle_id();
view.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
// for update
}
});
return view;
}
}
if someone can help, Thank you because I'm stuck here. my goal is to make Money Management

How can I add buttons in the dialog of xml?

I tried to create a dialog using xml, but I tried it many times and it will crash. I don’t know where the problem is. I ’m sure startConnect() and sendBtn() can be used. How can I create one The dialog of xml? Because I will sort out the interface finally.
This is the error code
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.smart.v9, PID: 11678
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at com.smart.v9.TcpClientActivity.tv(TcpClientActivity.java:423)
at com.smart.v9.TcpClientActivity.onClick(TcpClientActivity.java:267)
at android.view.View.performClick(View.java:7125)
at android.view.View.performClickInternal(View.java:7102)
at android.view.View.access$3500(View.java:801)
at android.view.View$PerformClick.run(View.java:27336)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
TcpClientActivity.java tv():
private void tv(){
final AlertDialog.Builder tvalert = new AlertDialog.Builder(this);
LayoutInflater inflater = getLayoutInflater();
final View tvview = inflater.inflate(R.layout.dialog_tv, null);
mBtn15.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
//startConnect();
//sendBtn(15);
}
});
mBtn16.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
startConnect();
sendBtn(16);
}
});
mBtn17.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
startConnect();
sendBtn(17);
}
});
mBtn18.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
startConnect();
sendBtn(18);
}
});
mBtn19.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
startConnect();
sendBtn(19);
}
});
mBtn20.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
startConnect();
sendBtn(20);
}
});
mBtn21.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
startConnect();
sendBtn(21);
}
});
mBtn22.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
startConnect();
sendBtn(22);
}
});
mBtn23.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
startConnect();
sendBtn(23);
}
});
mBtn24.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
startConnect();
sendBtn(24);
}
});
mBtn25.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
startConnect();
sendBtn(25);
}
});
mBtn26.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
startConnect();
sendBtn(26);
}
});
mBtn27.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
startConnect();
sendBtn(27);
}
});
mBtn28.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
startConnect();
sendBtn(28);
}
});
mBtn29.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
startConnect();
sendBtn(29);
}
});
mBtn30.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
startConnect();
sendBtn(30);
}
});
mBtn31.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
startConnect();
sendBtn(31);
}
});
mBtn32.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
startConnect();
sendBtn(32);
}
});
mBtn33.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
startConnect();
sendBtn(33);
}
});
mBtn34.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
startConnect();
sendBtn(34);
}
});
tvalert.setNegativeButton("退出", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
}
});
tvalert.setView(tvview);
tvalert.show();
}
dialog_tv.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/tv_lin"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/button15"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="on/off" />
<Button
android:id="#+id/button16"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="靜音" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/button17"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="退出" />
<Button
android:id="#+id/button18"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="+" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/button19"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="-" />
<Button
android:id="#+id/button20"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="快進" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/button21"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="後退" />
<Button
android:id="#+id/button22"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="↑" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/button23"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="←" />
<Button
android:id="#+id/button24"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="↓" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/button25"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="→" />
<Button
android:id="#+id/button26"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="enter" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/button27"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="setting" />
<Button
android:id="#+id/button28"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="暫停" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/button29"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="下一項" />
<Button
android:id="#+id/button30"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="上一項" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/button31"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="電視" />
<Button
android:id="#+id/button32"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="花園" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/button33"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="大門" />
<Button
android:id="#+id/button34"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="室內" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Add a lookup for the View Id
eg:
mBtn15 = tvview.findViewById(R.id.button15);
etc..
hope that may help you

cant set onclick on recylerview(cardview)

MainActivity.java
public class MainActivity extends AppCompatActivity {
RecyclerView recyclerView;
DatabaseReference reference;
FirebaseRecyclerAdapter<Bookdeets,Bkhomeholder>adapter;
FirebaseRecyclerOptions<Bookdeets> options;
ProgressBar loading;
FloatingActionButton searchbtn;
TextView logout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
reference = FirebaseDatabase.getInstance().getReference().child("books");
reference.keepSynced(true);
recyclerView = (RecyclerView) findViewById(R.id.rv);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.addItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.VERTICAL));
loading=(ProgressBar)findViewById(R.id.loading);
searchbtn=(FloatingActionButton)findViewById(R.id.searchbtn);
logout = (TextView) findViewById(R.id.Logout);
logout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Logout();
}
});
searchbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Opensearchpage();
}
});
options = new FirebaseRecyclerOptions.Builder<Bookdeets>()
.setQuery(reference, Bookdeets.class).build();
adapter = new FirebaseRecyclerAdapter<Bookdeets, Bkhomeholder>(options) {
#Override
protected void onBindViewHolder(#NonNull Bkhomeholder holder, int position, #NonNull Bookdeets model) {
Picasso.get().load(model.getImage()).into(holder.bookimg, new Callback() {
#Override
public void onSuccess() {
loading.setVisibility(View.GONE);
}
#Override
public void onError(Exception e) {
Toast.makeText(getApplicationContext(), "could not get the image", Toast.LENGTH_LONG).show();
loading.setVisibility(View.GONE);
}
});
holder.title.setText(model.getBookname());
}
#NonNull
#Override
public Bkhomeholder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.cardviewlay, parent, false);
return new Bkhomeholder(view);
}
};
GridLayoutManager gridLayoutManager=new GridLayoutManager(getApplicationContext(),3);
recyclerView.setLayoutManager(gridLayoutManager);
adapter.startListening();
recyclerView.setAdapter(adapter);
}
#Override
protected void onStart() {
super.onStart();
if(adapter!=null)
adapter.startListening();
loading.setVisibility(View.VISIBLE);
}
#Override
protected void onStop() {
super.onStop();
if(adapter!=null)
adapter.stopListening();
}
#Override
protected void onResume() {
super.onResume();
if(adapter!=null)
adapter.startListening();
}
public void Opensearchpage(){
Intent intent=new Intent(this, SearchPage.class);
startActivity(intent);
}
public void Logout() {
FirebaseAuth.getInstance().signOut();
startActivity(new Intent(getApplicationContext(), Login.class));
finish();
}
Bkhomeholder.java
public class Bkhomeholder extends RecyclerView.ViewHolder {
public TextView title;
public ImageView bookimg;
public Bkhomeholder(#NonNull View itemView) {
super(itemView);
title = itemView.findViewById(R.id.bkdettitle);
bookimg = itemView.findViewById(R.id.bkdetimg);
}
activity_main.xml
<RelativeLayout 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=".homepage.MainActivity"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="4dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:text="Library App"
android:textAlignment="center"
android:textColor="#E21B1B"
android:textSize="32dp"
android:textStyle="bold" />
<androidx.recyclerview.widget.RecyclerView
android:clipChildren="true"
android:id="#+id/rv"
android:layout_width="match_parent"
android:layout_height="525dp"
android:layout_marginStart="8dp"
android:layout_marginTop="75dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/searchbtn"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginStart="345dp"
android:layout_marginTop="480dp"
android:layout_marginEnd="12dp"
android:background="#B3E5FC"
android:clickable="true"
app:srcCompat="#drawable/customicon" />
<ProgressBar
android:id="#+id/loading"
style="?android:attr/progressBarStyle"
android:layout_width="76dp"
android:layout_height="76dp"
android:layout_marginStart="163dp"
android:layout_marginTop="253dp"
android:layout_marginEnd="163dp"
android:layout_marginBottom="253dp"
android:visibility="invisible"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="25dp"
android:id="#+id/Logout"
android:layout_centerHorizontal="true"
android:text="Logout"
android:textAlignment="center"
android:textSize="14sp"
android:layout_marginBottom="8dp"
android:layout_marginTop="565dp"
cardview xml
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cardview="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
android:id="#+id/bookcardview"
android:layout_width="120dp"
android:layout_height="190dp"
android:layout_margin="5dp"
cardview:cardCornerRadius="4dp">
<LinearLayout
android:id="#+id/bkdetlinear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:ignore="ExtraText"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
android:layout_marginEnd="4dp"
>
<ImageView
android:id="#+id/bkdetimg"
android:layout_width="match_parent"
android:layout_height="160dp"
android:background="#2d2d2d"
android:clickable="true"
android:scaleType="fitXY" />
<TextView
android:id="#+id/bkdettitle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Book title"
android:textColor="#2d2d2d"
android:textSize="12sp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</RelativeLayout>
i tried setting on click on the cardviewholder that is separate xml file which is inflated in my mainactivity oncreate and set the onclick listener under
onBindViewHolder but i got a error regarding null object refference as if the activity could not detect the cardview
You can set OnClickListener on RecyclerView item inside onBindViewHolder like below:
#Override
protected void onBindViewHolder(#NonNull Bkhomeholder holder, int position, #NonNull Bookdeets model) {
....
holder.title.setText(model.getBookname());
holder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Do your operation here
}
});
}
Update: Remove android:clickable="true" from cardview layout like below:
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cardview="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:foreground="?android:attr/selectableItemBackground"
android:id="#+id/bookcardview"
android:layout_width="120dp"
android:layout_height="190dp"
android:layout_margin="5dp"
cardview:cardCornerRadius="4dp">
<LinearLayout
android:id="#+id/bkdetlinear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:ignore="ExtraText"
android:foreground="?android:attr/selectableItemBackground"
android:layout_marginEnd="4dp"
>
<ImageView
android:id="#+id/bkdetimg"
android:layout_width="match_parent"
android:layout_height="160dp"
android:background="#2d2d2d"
android:scaleType="fitXY" />
<TextView
android:id="#+id/bkdettitle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Book title"
android:textColor="#2d2d2d"
android:textSize="12sp" />
</LinearLayout>
</androidx.cardview.widget.CardView>

setOnClickListener not working in fragment Android

I am trying to apply a setOnClickListener on an EditText View in a Fragment and for some reason, It is not working, the code in the listener doesn't execute when I click on the EditText.
The fragment xml:
<?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="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp"
tools:context=".add_payment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/testpay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Time:"
android:textColor="#000000"
android:textSize="24sp" />
<EditText
android:id="#+id/add_pay_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:ems="10"
android:inputType="time" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Date:"
android:textColor="#000000"
android:textSize="24sp" />
<EditText
android:id="#+id/add_pay_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="date" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Name:"
android:textColor="#000000"
android:textSize="24sp" />
<EditText
android:id="#+id/add_pay_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Table:"
android:textColor="#000000"
android:textSize="24sp" />
<EditText
android:id="#+id/add_pay_table"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Amount:"
android:textColor="#000000"
android:textSize="24sp" />
<EditText
android:id="#+id/add_pay_amm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberDecimal" />
</LinearLayout>
</LinearLayout>
The fragment code:
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container,
#Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.add_payment_fragment, container, false);
view.findViewById(R.id.add_pay_time).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getContext(), "aaaa", Toast.LENGTH_LONG).show();
}
});
return view;
}
Edit text needs focus to call onClick().
Solution 1
request focus when you set listener:
EditText editText = view.findViewById(R.id.add_pay_time);
editText.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getContext(), "aaaa", Toast.LENGTH_LONG).show();
}
});
editText.requestFocus(); //request focus
Solution 2
set on touch listener:
EditText editText = view.findViewById(R.id.add_pay_time);
editText.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if (MotionEvent.ACTION_DOWN == event.getAction())
Toast.makeText(getContext(), "aaaa", Toast.LENGTH_LONG).show();
return false;
}
});
Solution 3
you can use onClickListener and onFocusChangeListener together:
EditText editText = view.findViewById(R.id.add_pay_time);
editText.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
showToast();//call your method
}
});
editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus)
showToast();//call your method
}
});
EditText edText = view.findViewById(R.id.add_pay_time);
edText.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getActivity(), "aaaa", Toast.LENGTH_LONG).show();
}
});
Use getActivity().getApplicationContext() instead

Imagebutton doesnt work in slidinguppanel

I'm using the umano SlidingUpPanel library and I used an imagebutton in the panel but nothing happens when I click the imagebutton, I tried the imagebutton in another activity which worked perfectly. "next" is supposed to be printed to the logs when the button is pressed. I've searched all over but can't find any solution
Here's my code:
#SuppressLint("Registered")
public class NowPlaying extends Activity {
ImageButton play, pause, play_main, pause_main, next, imgbtn;
private MusicService musicSrv;
#SuppressLint("WrongViewCast")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.now_playing);
play = findViewById(R.id.play_button);
imgbtn = findViewById(R.id.imgbtn);
imgbtn.setOnClickListener(new View.OnClickListener() {
#SuppressLint("ShowToast")
#Override
public void onClick(View v) {
Log.i("oladapos", "next");
}
});
SlidingUpPanelLayout now_playing =
findViewById(R.id.slideup_nowplaying);
next.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
playNext();
}
});
}
//play next
private void playNext(){
musicSrv.playNext();
}
//play previous
private void playPrev(){
musicSrv.playPrev();
}
#Override
public void start() {
}
#Override
public void pause() {
}
#Override
public int getDuration() {
return 0;
}
#Override
public int getCurrentPosition() {
return 0;
}
#Override
public void seekTo(int pos) {
}
#Override
public boolean isPlaying() {
return false;
}
#Override
public int getBufferPercentage() {
return 0;
}
#Override
public boolean canPause() {
return false;
}
#Override
public boolean canSeekBackward() {
return false;
}
#Override
public boolean canSeekForward() {
return false;
}
#Override
public int getAudioSessionId() {
return 0;
}
}
xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/slideup_nowplaying"
android:layout_height="match_parent"
android:layout_width="match_parent"
tools:context=".Fragments.songsFragment">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:layout_alignParentTop="true"
android:scaleType="centerCrop"
android:src="#drawable/songs_cover"
tools:ignore="ContentDescription" />
<LinearLayout
android:id="#+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:clickable="true"
android:orientation="horizontal"
android:focusable="true">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/songs_cover_one"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="10dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:src="#drawable/songs_cover"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription" />
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="202dp"
android:layout_height="match_parent"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/linearLayout3"
app:layout_constraintStart_toEndOf="#+id/songs_cover_one"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/songs_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-condensed"
android:lines="1"
android:text="#string/havana_camila_cabello_song"
android:textColor="#FFFFFF"
android:textSize="22sp" />
<TextView
android:id="#+id/songs_artist_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lines="1"
android:text="#string/camila_cabello" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.974"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:orientation="horizontal">
<Button
android:id="#+id/play_button"
android:layout_width="50dp"
android:layout_height="50dp"
android:clickable="true"
android:focusable="true"
android:scaleType="centerInside"
android:src="#drawable/round_play_arrow_black_48dp" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/forword_button"
android:id="#+id/imgbtn"/>
</RelativeLayout>
</RelativeLayout>

Categories