FATAL Exception:java.lang.RuntimeException: Unable to start activity ComponentInfo - android

I try to solve this problem but i don't find any solution so please help me to solve it.
1)My Package.java file:
b_indian=(Button)findViewById(R.id.b_indian);
b_classic=(Button)findViewById(R.id.b_classic);
b_royal=(Button)findViewById(R.id.b_royal);
t_pkg=(TextView)findViewById(R.id.t_pkg);
t_indian=(TextView)findViewById(R.id.t_indian);
t_classic=(TextView)findViewById(R.id.t_classic);
t_royal=(TextView)findViewById(R.id.t_royal);
b_indian.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i=new Intent(Package.this,Indianpkg.class);
startActivity(i);
}
});
b_classic.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i=new Intent(Package.this,Classicpkg.class);
startActivity(i);
}
});
b_royal.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i=new Intent(Package.this,Royalpkg.class);
startActivity(i);
}
});
}
}
2)activity_package.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Package"
android:id="#+id/t_pkg"
android:layout_gravity="center_horizontal"
style="#style/Title"/>
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/b_indian"
android:textSize="18sp"
android:gravity="center"
android:singleLine="false"
android:paddingBottom="10dp"
android:layout_margin="25dp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="INDIAN"
android:id="#+id/t_indian"
android:layout_margin="55dp"
android:gravity="center_horizontal"
style="#style/SimpleText"/>
</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:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/b_classic"
android:textSize="18sp"
android:gravity="center"
android:singleLine="false"
android:paddingBottom="10dp"
android:layout_margin="25dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="CLASSIC"
android:layout_margin="50dp"
android:id="#+id/t_classic"
android:layout_gravity="center_horizontal"
style="#style/SimpleText"/>
</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:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/b_royal"
android:textSize="18sp"
android:gravity="center"
android:singleLine="false"
android:paddingBottom="10dp"
android:layout_margin="25dp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="ROYAL"
android:layout_margin="55dp"
android:id="#+id/t_royal"
android:layout_gravity="center_horizontal"
style="#style/SimpleText"/>
</RelativeLayout>
</TableRow>
</TableLayout>
This is my package file and i put same code to intent three different packages in that file but i intent only indian package and rest of two packages is not intent and i have error:FATAL Exception.
Following all files:
1)Indianpkg.java
b_i_venue=(Button)findViewById(R.id.b_i_venue);
b_i_decor=(Button)findViewById(R.id.b_i_decor);
b_i_caterer=(Button)findViewById(R.id.b_i_caterer);
b_i_photo=(Button)findViewById(R.id.b_i_photo);
b_i_mehandi=(Button)findViewById(R.id.b_i_mehandi);
b_i_dj=(Button)findViewById(R.id.b_i_dj);
t1=(TextView)findViewById(R.id.t1);
b_i_venue.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i=new Intent(Indianpkg.this,Indian_venue.class);
startActivity(i);
}
});
b_i_decor.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i=new Intent(Indianpkg.this,Indian_decoration.class);
startActivity(i);
}
});
b_i_caterer.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i=new Intent(Indianpkg.this,Indian_decoration.class);
startActivity(i);
}
});
b_i_photo.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i=new Intent(Indianpkg.this,Indian_caterer.class);
startActivity(i);
}
});
b_i_mehandi.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i=new Intent(Indianpkg.this,Indian_mehandi.class);
startActivity(i);
}
});
b_i_dj.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i=new Intent(Indianpkg.this,Indian_dj.class);
startActivity(i);
}
});
}
}
2)activity_indianpkg.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text=" Indian Wedding"
android:id="#+id/t1"
android:layout_gravity="center_horizontal"
style="#style/Title"/>
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/b_i_venue"
android:background="#drawable/i_venue"
android:text="Venue"
android:textSize="18sp"
android:gravity="center|bottom"
android:singleLine="false"
android:paddingBottom="10dp"
android:layout_margin="10dp"
style="#style/Title"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/b_i_decor"
android:background="#drawable/i_decoration"
android:text="Decoration"
android:textSize="18sp"
android:gravity="center|bottom"
android:singleLine="false"
android:paddingBottom="10dp"
android:layout_margin="10dp"
style="#style/Title"/>
</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:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/b_i_caterer"
android:text="Caterer"
android:background="#drawable/i_caterer"
android:textSize="18sp"
android:gravity="center|bottom"
android:layout_margin="10dp"
android:paddingBottom="10dp"
style="#style/Title"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/b_i_photo"
android:text="Photography"
android:background="#drawable/i_photography"
android:textSize="18sp"
android:gravity="center|bottom"
android:paddingBottom="10dp"
android:layout_margin="10dp"
style="#style/Title"/>
</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:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/b_i_mehandi"
android:text="Mehandi"
android:background="#drawable/i_mahendi"
android:textSize="18sp"
android:gravity="center|bottom"
android:layout_margin="10dp"
android:paddingBottom="10dp"
style="#style/Title"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/b_i_dj"
android:text="DJ"
android:background="#drawable/i_dj"
android:textSize="18sp"
android:gravity="center|bottom"
android:layout_margin="10dp"
style="#style/Title"
android:paddingBottom="10dp"/>
</RelativeLayout>
</TableRow>
</TableLayout>
Above code is run succesfully. But below code is also same but still not run and give FATAL Exception.
3)Classic.java
b_c_venue=(Button)findViewById(R.id.b_i_venue);
b_c_decor=(Button)findViewById(R.id.b_i_decor);
b_c_caterer=(Button)findViewById(R.id.b_i_caterer);
b_c_photo=(Button)findViewById(R.id.b_i_photo);
b_c_mehandi=(Button)findViewById(R.id.b_i_mehandi);
b_c_dj=(Button)findViewById(R.id.b_i_dj);
t2=(TextView)findViewById(R.id.t2);
b_c_venue.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i=new Intent(Classicpkg.this,Classic_venue.class);
startActivity(i);
}
});
b_c_decor.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i=new Intent(Classicpkg.this,Classic_decoration.class);
startActivity(i);
}
});
b_c_caterer.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i=new Intent(Classicpkg.this,Classic_caterer.class);
startActivity(i);
}
});
b_c_photo.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i=new Intent(Classicpkg.this,Classic_photography.class);
startActivity(i);
}
});
b_c_mehandi.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i=new Intent(Classicpkg.this,Classic_mehandi.class);
startActivity(i);
}
});
b_c_dj.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i=new Intent(Classicpkg.this,Classic_dj.class);
startActivity(i);
}
});
}
}
4)activity_classic.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text=" Classic Wedding"
android:id="#+id/t2"
android:layout_gravity="center_horizontal"
style="#style/Title"/>
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/b_c_venue"
android:background="#drawable/i_venue"
android:text="Venue"
android:textSize="18sp"
android:gravity="center|bottom"
android:singleLine="false"
android:paddingBottom="10dp"
android:layout_margin="10dp"
style="#style/Title"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/b_c_decor"
android:background="#drawable/i_decoration"
android:text="Decoration"
android:textSize="18sp"
android:gravity="center|bottom"
android:singleLine="false"
android:paddingBottom="10dp"
android:layout_margin="10dp"
style="#style/Title"/>
</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:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/b_c_caterer"
android:text="Caterer"
android:background="#drawable/i_caterer"
android:textSize="18sp"
android:gravity="center|bottom"
android:layout_margin="10dp"
android:paddingBottom="10dp"
style="#style/Title"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/b_c_photo"
android:text="Photography"
android:background="#drawable/i_photography"
android:textSize="18sp"
android:gravity="center|bottom"
android:paddingBottom="10dp"
android:layout_margin="10dp"
style="#style/Title"/>
</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:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/b_c_mehandi"
android:text="Mehandi"
android:background="#drawable/i_mahendi"
android:textSize="18sp"
android:gravity="center|bottom"
android:layout_margin="10dp"
android:paddingBottom="10dp"
style="#style/Title"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/b_c_dj"
android:text="DJ"
android:background="#drawable/i_dj"
android:textSize="18sp"
android:gravity="center|bottom"
android:layout_margin="10dp"
style="#style/Title"
android:paddingBottom="10dp"/>
</RelativeLayout>
</TableRow>
</TableLayout>
enter image description here

May be you haven't add activity class in AndroidMaifest.xml
if you don't!
Add Activity to your AndroidMaifest.xml
like this
<activity
android:name=".Classic"
android:label="your_activity_label">
</activity>
Then Edit Code in Classic.java
b_c_venue=(Button)findViewById(R.id.b_c_venue);
b_c_decor=(Button)findViewById(R.id.b_c_decor);
b_c_caterer=(Button)findViewById(R.id.b_c_caterer);
b_c_photo=(Button)findViewById(R.id.b_c_photo);
b_c_mehandi=(Button)findViewById(R.id.b_c_mehandi);
b_c_dj=(Button)findViewById(R.id.b_c_dj);
t2=(TextView)findViewById(R.id.t2);

Your ids are wrong for your classic view, change ...i... for ....c... in your Classic Activity, like this:
b_c_venue=(Button)findViewById(R.id.b_c_venue);

Related

How to set Text button

i have a custom_layout_dish
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_gravity="center"
android:weightSum="10">
<ImageView
android:id="#+id/img_Dish"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="6"
android:src="#drawable/dau_phu_luot_van"/>
<LinearLayout
android:padding="10dp"
android:layout_weight="3.5"
android:layout_gravity="center"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/tv_NameDish"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pepsi"/>
<TextView
android:id="#+id/tv_Price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="30.000"/>
</LinearLayout>
<Button
android:id="#+id/btn_Order"
android:layout_gravity="center"
android:layout_weight="0.5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_add"/>
</LinearLayout>
and activity_orderfood
<Button
android:id="#+id/btn_Cart"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Xem Hóa Đơn" />
<ListView
android:id="#+id/lv_dish"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#id/btn_Cart"
android:layout_alignParentTop="true" />
So, how to setText btn_Cart (activity) when I click btn_Order (custom_layout)
In OrderFoodActivity I create
public void ShowQuantityOrder(int quantity){
btnCart.setText("Xem Giỏ Hàng " + quantity);
}
and
holder.btnOrder.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
int tongsoluong = chiTietGoiMonDAO.getTongSoLuong(magoimon);
OrderFood orderFoodActivity = new OrderFoodActivity ();
orderFoodActivity .ShowQuantityOrder(tongsoluong);
}
});
but It's not working pls help me I want when click btn_Order change text btn_Cart like "Xem Giỏ Hàng " + quantity, please help me. I using adapter

Android custom dialog displays extra space

My custom dialog adds extra space after the Cancel and Save button. I have made a couple of custom dialogs in this app, but this problem appears only in this case. I've colored the view's background to blue, so I think it should be okay.
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:layout_height="wrap_content"
android:background="#android:color/holo_blue_dark">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:gravity="center_horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/black"
android:text="#string/mo"/>
<CheckBox
android:id="#+id/cbMo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_marginLeft="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/black"
android:text="#string/tu"/>
<CheckBox
android:id="#+id/cbTu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_marginLeft="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/black"
android:text="#string/we"/>
<CheckBox
android:id="#+id/cbWe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_marginLeft="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/black"
android:text="#string/th"/>
<CheckBox
android:id="#+id/cbTh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_marginLeft="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/black"
android:text="#string/fr"/>
<CheckBox
android:id="#+id/cbFr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:gravity="center_horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:layout_marginRight="10dp"
android:text="#string/repeat_every"
android:textColor="#android:color/black"
android:gravity="right"
android:layout_gravity="center_vertical"/>
<Spinner
android:id="#+id/spRecurrence"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:prompt="#string/repeat_every"
android:layout_gravity="center_vertical"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:layout_marginTop="#dimen/activity_vertical_margin">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:layout_marginRight="10dp"
android:text="#string/starts_on"
android:textColor="#android:color/black"
android:gravity="right"/>
<TextView
android:id="#+id/tvDate"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:text="#string/pick_a_date"
android:drawableRight="#drawable/ic_calendar"
android:gravity="center_vertical"/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0.2"
android:visibility="visible"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:layout_marginTop="#dimen/activity_vertical_margin">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:gravity="right"
android:layout_marginRight="10dp"
android:textColor="#android:color/black"
android:text="#string/recurrences_colon"/>
<EditText
android:id="#+id/etNumber"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:inputType="number"/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0.3"
android:visibility="invisible"/>
</LinearLayout>
<TextView
android:id="#+id/tvError"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#android:color/holo_red_dark"
android:visibility="visible"
android:text="Error text"/>
</LinearLayout>
Displaying the dialog:
Context context = getContext();
final NewRecurrencesDialogView recurrencesDialogView = new NewRecurrencesDialogView(context, subject);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setView(recurrencesDialogView)
.setTitle(R.string.set_recurrence)
.setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) { }
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
}
});
final Dialog dialog = builder.create();
dialog.setCancelable(false);
dialog.show();
((AlertDialog)dialog).getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
ArrayList<Teaching> newRecurrences = recurrencesDialogView.saveRecurrences();
if (newRecurrences != null) {
recurrences.addAll(newRecurrences);
Collections.sort(recurrences, new Comparator<Teaching>() {
#Override
public int compare(Teaching lhs, Teaching rhs) {
if (lhs.getBegin() < rhs.getBegin())
return -1;
else
return 1;
}
});
updateListViewAdapter();
dataChangedListener.setChanged(true);
dialog.dismiss();
}
}
});
((AlertDialog)dialog).getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
I've compared the layout file with the other dialog's files, but can't figure out where the problem is.
I think the problem is with the android:layout_weight you set for your view.
Try change your:
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0.2"
android:visibility="visible"/>
To this:
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:visibility="visible"/>
I am not really sure what you trying to achieve, but think this will show you the direction (hopefully the right one).

couldnt save which view has focus?

my app contains "Settings" activity which contains 2 imagebuttons "back" and "about", whenever i press any of these buttons i get:
"couldnt save which view has focus because the focused view android.widget.LinearLayout#4055a9e0 has no id"
the xml code for my_settings:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/ll2"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="15" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_margin="8dp"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/settings" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|end"
android:orientation="horizontal" >
<ToggleButton
android:id="#+id/tb1"
android:layout_margin="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="#string/sett1" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/border2"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/ll_set_back"
android:layout_margin="3dp"
android:gravity="center"
android:layout_weight="1"
android:orientation="vertical" >
**<ImageButton
android:id="#+id/st_ibt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/action_btn"
android:src="#drawable/back_ic" />**
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/back"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/ll_set_about"
android:layout_margin="3dp"
android:gravity="center"
android:layout_weight="1"
android:orientation="vertical" >
**<ImageButton
android:id="#+id/st_ibt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/action_btn"
android:src="#drawable/about_ic" />**
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/about"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
dont pay attention to the "scrollview" (i dont think the problem is there), just look at the end of the code for the 2 imagebuttons..
and this the java code for Settings:
public class Settings extends Activity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.my_settings);
//code...
ImageButton goBack=(ImageButton)findViewById(R.id.st_ibt1);
ImageButton about=(ImageButton)findViewById(R.id.st_ibt2);
goBack.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Intent intent=new Intent(Settings.this, MainActivity.class);
startActivity(intent);
//finish();
}
});
about.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Intent intent=new Intent(Settings.this, About.class);
startActivity(intent);
//finish();
}
});
}
so, how to fix this? i dont understand what this error means.. any suggestions
I think the problem is :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:orientation="vertical" >
You enable focus to this LinearLayout, but you didn't provide any id for it.

Button inside cardview does not work

<LinearLayout 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="horizontal"
android:padding="10dp"
android:paddingTop="8dp"
android:descendantFocusability="blocksDescendants">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="2dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="#+id/view"
android:layout_width="5dp"
android:layout_height="match_parent"
android:background="#color/accent"/>
<TextView
android:id="#+id/m_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FF6600"
android:textSize="30dp"
android:layout_toRightOf="#id/view"
android:text="hey th"
android:textStyle="bold" />
<Button
android:id="#+id/m_delete"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_toRightOf="#id/m_name"
android:layout_weight="0"
android:text="Delete" />
</RelativeLayout>
</android.support.v7.widget.CardView>
I have put a button inside like this and this is shown in recycler view.
The problem I am facing is that the button click only works if I long press on the button else if i click normally then intent is called.
holder.delete.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
MetricsDAO dao = new MetricsDAO(context);
dao.deleteMetrics(metrices.get(position).getEventName());
dao.close();
Intent i = new Intent(context, HealthGraph.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
// ((Activity) context).finish();
}
});
I am doing this inside on onBindViewHolder()..
What is it that i am doing wrong or missing?

Custom Alignment of RadioButtons in Android

I have 4 RadioButtons (part of same RadioGroup) and I want to align them like this :
Code I am using is :
<RadioGroup
android:id="#+id/add_reminder_type"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="#dimen/zero"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical" >
<RadioButton
android:id="#+id/add_reminder_daily"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/add_reminder_daily" />
<RadioButton
android:id="#+id/add_reminder_weekly"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/add_reminder_weekly" />
</LinearLayout>
<LinearLayout
android:layout_width="#dimen/zero"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical" >
<RadioButton
android:id="#+id/add_reminder_monthly"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/add_reminder_monthly" />
<RadioButton
android:id="#+id/add_reminder_yearly"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/add_reminder_yearly" />
</LinearLayout>
</RadioGroup>
But by using this code, RadioGroup loses its property and all the RadioButtons can be checked at same time.
Any idea how RadioGroup can retain its property using this type of alignment ?
You can Try This....
first declare all radio button
r1=(RadioButton) findViewById(R.id.add_reminder_daily);
r2=(RadioButton) findViewById(R.id.add_reminder_weekly);
r3=(RadioButton) findViewById(R.id.add_reminder_monthly);
r4=(RadioButton) findViewById(R.id.add_reminder_yearly);
now on - onclick listner do
r1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
r2.setChecked(false);
r3.setChecked(false);
r4.setChecked(false);
}
});
r2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
r1.setChecked(false);
r3.setChecked(false);
r4.setChecked(false);
}
});
r3.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
r2.setChecked(false);
r1.setChecked(false);
r4.setChecked(false);
}
});
r4.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
r2.setChecked(false);
r3.setChecked(false);
r1.setChecked(false);
}
});
try below code works fine at my end:-
<RadioGroup
android:id="#+id/add_reminder_type"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:gravity="center_horizontal"
android:orientation="vertical" >
<RadioButton
android:id="#+id/add_reminder_daily"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Daily" />
<RadioButton
android:id="#+id/add_reminder_weekly"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Monthly" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical" >
<RadioButton
android:id="#+id/add_reminder_monthly"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Weekly" />
<RadioButton
android:id="#+id/add_reminder_yearly"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Yearly" />
</LinearLayout>
</RadioGroup>
use this code :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<RadioGroup
android:id="#+id/add_reminder_type"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="#dimen/zero"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical" >
<RadioButton
android:id="#+id/add_reminder_daily"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="daily" />
<RadioButton
android:id="#+id/add_reminder_weekly"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="weekly" />
</LinearLayout>
<LinearLayout
android:layout_width="#dimen/zero"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical" >
<RadioButton
android:id="#+id/add_reminder_monthly"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="monthly" />
<RadioButton
android:id="#+id/add_reminder_yearly"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="yearly" />
</LinearLayout>
</RadioGroup>
</LinearLayout>

Categories

Resources