I have some issues using a BootStrapButton onclickListener. Here is my code. When I run the app it crashes.
BootstrapButton btn2=(BootstrapButton) findViewById(R.id.button2);
btn2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent nextscreen=new Intent(getActivity().getApplicationContext(),Mellipage.class);
startActivity(nextscreen);
}
});
If anyone knows how I can fix it, please share.
by adding this code my problem solved!
<com.beardedhen.androidbootstrap.BootstrapButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Success"
bootstrapbutton:bb_icon_right="fa-android"
bootstrapbutton:bb_type="success" />
From your log:
java.lang.ClassCastException: android.widget.Button cannot be cast to com.beardedhen.androidbootstrap.BootstrapButton
you have probably declared your button in your layout as a Button instead of BootstrapButton
Change this
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp" />
to
<com.beardedhen.androidbootstrap.BootstrapButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Success"
bootstrapbutton:bb_icon_right="fa-android"
bootstrapbutton:bb_type="success" />
Related
Hy.... I'm making a simple project on eclipse. I'm using relative layout as shown below :
<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:gravity="center"
tools:context=".ProfileActivity"
>
<Button
android:id="#+id/Prof_edit_btn"
android:layout_below="#+id/Prof_LL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Edit"
android:layout_marginTop="17dp"
android:layout_centerHorizontal="true"
/>
<LinearLayout
android:layout_below="#+id/Prof_LL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_centerHorizontal="true"
>
<Button
android:id="#+id/Prof_save_btn"
android:layout_below="#+id/Prof_LL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="save"
android:layout_marginTop="17dp"
android:layout_centerHorizontal="true"
android:visibility="invisible"
android:clickable="false"
/>
<Button
android:id="#+id/Prof_batal_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Batal"
android:layout_marginTop="17dp"
android:visibility="invisible"
android:clickable="false"
/>
</LinearLayout>
</RelativeLayout>
In the main activity, I've made a simple onClicklistener for Edit and Save button as shown below :
mEdit = (Button)findViewById(R.id.Prof_edit_btn);
mEdit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
mBatal.setVisibility(View.VISIBLE);
mBatal.setClickable(true);
mSave.setVisibility(View.VISIBLE);
mSave.setClickable(true);
mEdit.setVisibility(View.INVISIBLE);
}
});
mSave = (Button)findViewById(R.id.Prof_save_btn);
mSave.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
mEdit.setVisibility(View.VISIBLE);
mBatal.setVisibility(View.INVISIBLE);
mSave.setVisibility(View.INVISIBLE);
Toast.makeText(getApplicationContext(), "Data Anda berhasil disimpan", Toast.LENGTH_SHORT).show();
}
});
Well... As we can see from my layout xml, only EDIT button will be visible on the start, then SAVE and BATAL button will be visible when EDIT is clicked by user according to the code program within setonclick listener of EDIT button. And as soon as EDIT button is clicked it will be invisible.... The problems here are WHen I clicked EDIT button, only SAVE button will be visible and BATAL button will be visible when SAVE button is clicked, another problem that I'm facing now is EDIT button is not invisible at all when I click it.... So.. anyone can help me with this problem please...??? :'(
Thanks in advance....
Naaah... I found my own solution... Just set the visibility of SAVE btn and BATAL btn to GONE... And it's all done.... :-)
<Button
android:id="#+id/Prof_save_btn"
android:layout_below="#+id/Prof_LL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="save"
android:layout_marginTop="17dp"
android:layout_centerHorizontal="true"
android:visibility="gone"<-----------=
android:clickable="false"
/>
<Button
android:id="#+id/Prof_batal_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Batal"
android:layout_marginTop="17dp"
android:visibility="gone"<-----------=
android:clickable="false"
/>
I have Following layout Scenario
Want to implement the Click even of TextView ..but the TextView Click not working
Here is code Sample
<FrameLayout
android:id="#+id/frame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:clickable="false">
<customview
android:id="#+id/custom"
android:layout_width="200dp"
android:layout_height="200dp"
android:clickable="false"/>
<LinearLayout
android:id="#+id/abc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/zero_done"
android:padding="5dp"
android:clickable="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
</LinearLayout>
My TextView ClickEvent not working ...please help me
Class Code
TextView view= (TextView) findViewById(R.id.btn);
view.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Press",
Toast.LENGTH_SHORT).show();
}
});
You didn't call show method of Toast,so you have no idea whether TextView click event did happen or not.
Try this:
Toast.makeText(getApplicationContext(), "Press",
Toast.LENGTH_SHORT).show(); // don't miss show method.
In my android code, I have implemented onclick event on 3 textviews using following code. But nothing happens when they are clicked. What is wrong ?
<TextView
android:id="#+id/tv1"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#drawable/menucircle"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:onClick="selectit"
android:textColor="#ffffff"
/>
public void selectit(View v)
{
Log.d("tv0","ok");
if(v.getId()==tv1.getId())
{Log.d("tv1","ok");
selectoption(1);
Log.d("tv1","ok");
}
if(v.getId()==tv2.getId())
{Log.d("tv2","ok");
selectoption(2);
}
if(v.getId()==tv3.getId())
{Log.d("tv3","ok");
selectoption(3);
}
}
Add this into your xml
android:clickable="true"
You probably need to have this code in your xml
android:clickable="true"
Or Set the Clicklistenner to TextView via code by
TextView btn=(TextView) findViewById(R.id.tv1);
btn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
selectit(v);
}
});
It will automatically make it clickable so no need of android:clickable="true"
You can set the click handler in xml with these attribute:
android:clickable="true"
Don't forget the clickable attribute, without it, the click handler isn't called.
main.xml
<TextView
android:id="#+id/tv1"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#drawable/menucircle"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:onClick="selectit"
android:clickable="true"
android:textColor="#ffffff"
/>
i hope it will help u all the best
Try like below:
android:onClick="onClick"
android:clickable="true"
My textview:
<TextView
android:id="#+id/click"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me"
android:textSize="55sp"
android:onClick="onClick"
android:clickable="true"/>
Main Activity:
public class MyActivity extends Activity {
public void onClick(View v) {
...
}
}
Hi I am getting this message android.widget.imagebutton cannot be cast to android.widget.button (See attachment pic for logcat error) which I don't understand why? because my code seems to be right.
Code:
ImageButton Calendar = (ImageButton) findViewById (R.id.Calendar);
Calendar.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent OpenCalendarbtn = new Intent (Menu.this, DisplayCalendar.class);
startActivity (OpenCalendarbtn);
}
});
Complete Layout xml file:
`
<ImageButton
android:id="#+id/Read"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/Write"
android:layout_marginRight="31dp"
android:src="#drawable/read" />
<ImageView
android:id="#+id/AppLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#drawable/logo" />
<ImageButton
android:id="#+id/Write"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/AppLogo"
android:layout_marginLeft="35dp"
android:layout_marginTop="14dp"
android:src="#drawable/write" />
<ImageButton
android:id="#+id/Calendar"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignLeft="#+id/Write"
android:layout_below="#+id/Write"
android:layout_marginTop="20dp"
android:src="#drawable/calendar/>
`
Make sure you have used the <ImageButton> tag instead of <Button> tag in your layout resource file.
That could be the cause of the error.
Change your
ImageButton Calendar = (ImageButton) findViewById (R.id.Calendar);
To:
Button Calendar = (Button) findViewById (R.id.Calendar);
Its an Eclipse problem not in your code.
Solution for this is just copy your code in xml by Ctrl+c and save the xml then again paste it again then save it and run.....this works with me.
i have this layout, but the button is not clickable.
i tried solutions from previous posts, such as adding android:focusable="false" to the button or listview or the linear layout but it didnt work. i tried adding : button.setFocusable(false) after the button OnClickListener but also didnt work. i even tried adding: android:descendantFocusability="blocksDescendants" to the main linear layout but the problem still exists.
Thanks.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
<EditText
android:id="#+id/search_field"
android:layout_width="181dp"
android:layout_height="wrap_content"
android:layout_weight="1.25"
android:ems="10"
android:hint="Search"
android:textColor="#1F6260" />
<Button
android:id="#+id/refresh_button"
android:layout_width="34dp"
android:layout_height="32dp"
android:background="#drawable/refresh3" />
</LinearLayout>
<ListView
android:id="#+id/list2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#b5b5b5"
android:dividerHeight="1dp"
android:listSelector="#drawable/list_selector">
</ListView>
</LinearLayout>
Java code:
refresh= (Button)myFragmentView.findViewById(R.id.refresh_button);
refresh.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
((MainTabs)getActivity()).refresh();
((MainTabs)getActivity()).getUsersList();
}
});
Added the toast in the onclick method and it showed, so my code isn't working and nothing is wrong with the button. Sorry for this inconvenience.
Thanks.
Two ways to achieve this
1.
Change your button like this
<Button
android:id="#+id/refresh_button"
android:layout_width="34dp"
android:layout_height="32dp"
android:background="#drawable/refresh3"
android:clickable="true"
android:onClick="buttonClick" />
then create a method inside your activity which have to pass your View as parameter like this.
public void buttonClick(View v) {}
or you can follow the second way
2.
Button button;
button = (Button) findViewById(R.id.refresh_button);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
Hope this will help you.