Hey i have a simple question. i have a mobile_navigation that contain code to call a fragment class, and i have the fragment class but i want to call / pass to another java class. for example i have Inputdata.xml that when tap will go to fragment class nah i want when i tap the input xml it will instantly go to another java class not stuck in fragment class
here is the example code for mobile_navigation
<fragment
android:id="#+id/nav_pantuan"
android:name="com.joshua.r0th.crud2.ui.gallery.GalleryFragment"
android:label="#string/pantauan"
tools:layout="#layout/fragment_pantauan" />
and here is the GalleryFragment code
public class GalleryFragment extends Fragment {
private GalleryViewModel GalleryViewModel;
public View onCreateView(#NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
GalleryViewModel =
ViewModelProviders.of(this).get(GalleryViewModel.class);
View root = inflater.inflate(R.layout.fragment_pantauan, container, false);
final TextView textView = root.findViewById(R.id.text_gallery);
GalleryViewModel.getText().observe(this, new Observer<String>() {
#Override
public void onChanged(#Nullable String s) {
textView.setText(s);
}
});
return root;
}
}
and this is the another java class that i willing to reach
public class pantauan extends AppCompatActivity {
database1 myDb;
EditText editNomorRumah,editJentikDalam,editJentikLuar;
Button btnAddData;
Button btnViewAll;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_pantauan);
myDb = new database1(this);
editNomorRumah = (EditText)findViewById(R.id.nomorrmh);
editJentikDalam = (EditText)findViewById(R.id.jentikdirumah);
editJentikLuar = (EditText)findViewById(R.id.jentikdiluarrumah);
btnAddData = (Button)findViewById(R.id.tambahdata);
btnViewAll = (Button)findViewById(R.id.lihatdata);
AddData();
viewAll();
}
//fungsi tambah
public void AddData() {
btnAddData.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
boolean isInserted = myDb.insertData(editNomorRumah.getText().toString(),
editJentikDalam.getText().toString(),
editJentikLuar.getText().toString() );
if(isInserted == true)
Toast.makeText(pantauan.this,"Data Iserted",Toast.LENGTH_LONG).show();
else
Toast.makeText(pantauan.this,"Data Not Iserted",Toast.LENGTH_LONG).show();
}
}
);
}
//fungsi menampilkan data
public void viewAll() {
btnViewAll.setOnClickListener(
new View.OnClickListener(){
#Override
public void onClick(View v) {
Cursor res = myDb.getAllData();
if(res.getCount() == 0) {
// show message
showMessage("Error","Noting Found");
return;
}
StringBuffer buffer = new StringBuffer();
while (res.moveToNext() ) {
buffer.append("NomorRumah :"+ res.getString(0)+"\n");
buffer.append("JentikDalam :"+ res.getString(1)+"\n");
buffer.append("JentikLuar :"+ res.getString(2)+"\n");
}
// show all data
showMessage("Data",buffer.toString());
}
}
);
}
//membuat alert dialog
public void showMessage(String title, String Message){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCancelable(true);
builder.setTitle(title);
builder.setMessage(Message);
builder.show();
}
}
and here is the Input.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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#drawable/gradient"
android:orientation="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginTop="70dp"
android:background="#drawable/gradient"
android:elevation="4dp"
android:orientation="vertical"
android:padding="20dp">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="30dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Nomor Rumah" />
<EditText
android:id="#+id/nomorrmh"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/roundtext" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Jentik Di Dalam Rumah" />
<EditText
android:id="#+id/jentikdirumah"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/roundtext" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Jentik Di Luar Rumah" />
<EditText
android:id="#+id/jentikdiluarrumah"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/roundtext"
android:layout_marginBottom="10dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_height="match_parent"
android:layout_gravity="center">
<Button
android:id="#+id/tambahdata"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:background="#d67601"
android:text="Tambah Data"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp" />
<Button
android:id="#+id/lihatdata"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:background="#d67601"
android:text="contoh lihat data"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<TextView
android:id="#+id/textviewadd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="26dp"
android:gravity="center_horizontal"
android:text="Input Data"
android:textColor="#fff"
android:textSize="26sp"
android:textStyle="bold"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
<TextView
android:id="#+id/text_gallery"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:textAlignment="center"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</RelativeLayout>
My goal is to pass the fragment into the java class that i want, because i dont know how to put that input class to the fragment always get cannot be cast to androidx.fragment.app.Fragment when i replace the GalleryFragment with pantauan.java code. thank you
Related
Somehow the scroll view is not working . The message alert dialog box is showing is really big and so I need to implement vertical scrollbar. I tried to get data from previous asked question but it isn't solving my issue please help.
I need to show the alert dialog on button click event.
benefits.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
AlertDialog ad = new AlertDialog.Builder(Panchgavya.this).create();
ad.setCancelable(false); // This blocks the 'BACK' button
ad.setMessage(getString(R.string.benefits));
ad.setTitle("Benefits");
ad.setButton("OK", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
ad.show();
TextView textView = (TextView) ad.findViewById(android.R.id.message);
textView.setScroller(new Scroller(Panchgavya.this));
textView.setVerticalScrollBarEnabled(true);
textView.setMovementMethod(new ScrollingMovementMethod());
}
});
My XML File Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Design.Panchgavya"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#color/Green"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Panchgavya"
android:textColor="#color/white"/>
</android.support.v7.widget.Toolbar>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="6"
android:orientation="vertical">
<TextView
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:ellipsize="end"
android:text="#string/panchgavya"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:orientation="vertical">
<TextView
android:id="#+id/panchgavya_tv_cow_dung"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cow Dung"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Medium"
android:textStyle="bold"
android:textColor="#color/black"/>
<TextView
android:id="#+id/panchgavya_tv_cow_urine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Cow Urine"
android:textStyle="bold"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Medium"
android:textColor="#color/black"/>
<TextView
android:id="#+id/panchgavya_tv_cow_milk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Cow Milk"
android:textStyle="bold"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Medium"
android:textColor="#color/black"/>
<TextView
android:id="#+id/panchgavya_tv_ghee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Medium"
android:text="Ghee"
android:textStyle="bold"
android:textColor="#color/black"/>
<TextView
android:id="#+id/panchgavya_tv_dahi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Medium"
android:text="Dahi"
android:textStyle="bold"
android:textColor="#color/black"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true">
<Button
android:id="#+id/panchgavya_btn_benefits"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Benefits"
android:background="#color/Green"
android:textColor="#color/white"
/>
</LinearLayout>
</LinearLayout>
You can create custom layout for your dialog and set any property easily.
For your requirement, Crate a layout for your required Dialog. Put android:scrollbars = "vertical" in your textView inside your layout. And textview.setMovementMethod(new ScrollingMovementMethod());.
You can set custom layout on your by following method.
public void showDialog(Activity activity, String msg){
final Dialog dialog = new Dialog(activity);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(false);
dialog.setContentView(R.layout.dialog);
TextView text = (TextView) dialog.findViewById(R.id.text_dialog);
text.setText(msg);
Button dialogButton = (Button) dialog.findViewById(R.id.btn_dialog);
dialogButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Textview
android:id="#+id/txtDescription"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/margin_16dp"
android:paddingRight="#dimen/margin_16dp"
android:paddingBottom="#dimen/margin_16dp"
android:paddingTop="#dimen/margin_10dp"
android:text="#string/dummy_text_"
android:textSize="#dimen/font_14dp"
android:textColor="#color/colorPrimary"
android:layout_below="#+id/imgClose"/>
<ImageView
android:id="#+id/imgClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_close"
android:layout_alignParentRight="true"
android:layout_marginRight="#dimen/margin_10dp"
android:layout_marginTop="#dimen/margin_10dp" />
</RelativeLayout>
</ScrollView>
// in your java file put below code
private void showPopup() {
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
LayoutInflater inflater = this.getLayoutInflater();
final View dialogView = inflater.inflate(R.layout.dialog_terms_services,
null);
dialogBuilder.setView(dialogView);
TextView txtDescription = dialogView.findViewById(R.id.txtDescription);
ImageView imgClose = dialogView.findViewById(R.id.imgClose);
txtDescription.setText(message);
final AlertDialog b = dialogBuilder.create();
b.show();
imgClose.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
b.dismiss();
}
});
}
// after than call that showPopup() methos on button click.Hope it works for you
class extending DialogFragment can have UI elements as per your requirement.
public class OrderDetailFragment extends DialogFragment{
#Override
public void onStart() {
super.onStart();
Dialog d = getDialog();
if (d!=null){
int width = ViewGroup.LayoutParams.MATCH_PARENT;
int height = ViewGroup.LayoutParams.WRAP_CONTENT;
d.getWindow().setLayout(width, height);
}
}
public static OrderDetailFragment getInstance(GeneralListDataPojo dataList){
OrderDetailFragment orderDetailFragment=new OrderDetailFragment();
Bundle bundle = new Bundle();
bundle.putParcelable(DATA, dataList);
orderDetailFragment.setArguments(bundle);
return orderDetailFragment;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View root_view = inflater.inflate(R.layout.fragment_order_detail, container, false);
GeneralListDataPojo mDataList = getArguments().getParcelable(DATA);//My class which holds data implemented Parcelable
//population of data from mDataList
return root_view;
}
void closeDialog(){
this.dismiss();
}
}
fragment_order_detail is having my requirement specific element's (ScrollView/LinearLayouts/Buttons etc)
GeneralListDataPojo is the class which holds data implements Parcelable for transferring data between components
Now you can invoke this DialogFragment from your Fragment like this. (Im invoking from a Fragment. Change the FragmentManager retrieval accordingly if you are using from Activity)
OrderDetailFragment orderDetailFragment=OrderDetailFragment.getInstance((GeneralListDataPojo) responseObj);
FragmentManager fragmentManager=getFragmentManager();
orderDetailFragment.show(fragmentManager,"OrderDetailFragment");
Create The Custom Dialog layout Using Scroll View in your own custom Layout
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final Dialog dialog= new Dialog(getApplicationContext());
dialog.setContentView(R.layout.activity_dialog);
Button click= dialog.findViewById(R.id.click);
click.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
});
How can I delete the space when I hide a CardView? I doing an app with android and Firebase and I show the information from firebase in cardviews, but when the info isn't correct the cardview must disappear. The point is that the cardview disappear, but still uses a space in the layout, I've tried the answers in
setVisibility(GONE) view becomes invisible but still occupies space But it doesn't work for me.
#Override
protected void onStart() {
super.onStart();
firebaseAuth.addAuthStateListener(firebaseAuthListener);
final FirebaseRecyclerAdapter<CursosDB, MainActivity.CursosPViewHolder> firebaseRecyclerAdapter =
new FirebaseRecyclerAdapter<CursosDB, MainActivity.CursosPViewHolder>(
CursosDB.class,
R.layout.design_row_cursos,
MainActivity.CursosPViewHolder.class,
myRef)
{
#Override
protected void populateViewHolder(MainActivity.CursosPViewHolder viewHolder, final CursosDB Cmodel, int position)
{
String estado = Cmodel.getSTATUS().toString();
if (estado.equals("OK")){
viewHolder.setPhotoURL(getApplicationContext(), Cmodel.getURI());
viewHolder.setTitle(Cmodel.getTITLE());
viewHolder.setCiudad(Cmodel.getPLACE());
viewHolder.setLevel(Cmodel.getLEVEL());
viewHolder.setDur(Cmodel.getDURACION());
viewHolder.setPrice(Cmodel.getCOSTO());
}else{
RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) viewHolder.mView.getLayoutParams();
layoutParams.setMargins(0,0,0,0);
viewHolder.mView.setLayoutParams(layoutParams);
viewHolder.mView.setVisibility(View.INVISIBLE);
viewHolder.mView.setVisibility(View.GONE);
//viewHolder.mView.setVisibility(View.GONE);
//Toast.makeText(getApplicationContext(), "Ningún curso aprobado aún", Toast.LENGTH_SHORT).show();
}
viewHolder.mView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Toast.makeText(getApplicationContext(), Cmodel.getUSERID(), Toast.LENGTH_LONG).show();
//Toast.makeText(getApplicationContext(), Cmodel.getTITLE(), Toast.LENGTH_SHORT).show();
//Toast.makeText(UsersList.this, user_key, Toast.LENGTH_LONG).show();
}
});
}
};
mCourses.setAdapter(firebaseRecyclerAdapter);
}
This is my layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/cardview_cursos"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:onClick="positionAction"
android:padding="4dp"
android:paddingBottom="4dp"
android:paddingEnd="4dp"
android:paddingStart="4dp"
android:paddingTop="4dp"
app:cardElevation="4dp">
<LinearLayout android:id="#+id/layout_to_hide"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/Cimg"
android:layout_width="match_parent"
android:layout_height="165dp"
android:scaleType="center"
app:srcCompat="#drawable/knowit_logo" />
<TextView
android:id="#+id/Ctitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/Cimg"
android:layout_marginLeft="14dp"
android:layout_marginStart="14dp"
android:paddingTop="8dp"
android:text="Titulo"
android:textStyle="bold" />
<TextView
android:id="#+id/Clugar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/Ctitle"
android:layout_alignStart="#+id/Ctitle"
android:layout_below="#+id/Ctitle"
android:layout_marginTop="10dp"
android:text="Lugar" />
<TextView
android:id="#+id/textView29"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/Clugar"
android:layout_alignStart="#+id/Clugar"
android:layout_below="#+id/Clugar"
android:layout_marginTop="10dp"
android:text="$" />
<TextView
android:id="#+id/Cprice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/textView29"
android:layout_marginBottom="4dp"
android:layout_toEndOf="#+id/textView29"
android:layout_toRightOf="#+id/textView29"
android:paddingLeft="5dp"
android:text="0.0" />
<TextView
android:id="#+id/Cdur"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/Clugar"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="126dp"
android:layout_marginRight="126dp"
android:text="Duración" />
<TextView
android:id="#+id/Cnivel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/Cprice"
android:layout_alignLeft="#+id/Cdur"
android:layout_alignStart="#+id/Cdur"
android:layout_marginBottom="0dp"
android:text="Nivel" />
</RelativeLayout>
</LinearLayout> </android.support.v7.widget.CardView>
This is the mView:
public static class CursosPViewHolder extends RecyclerView.ViewHolder {
View mView;
public CursosPViewHolder(final View itemView) {
super(itemView);
mView = itemView;
}
public void setTitle(String title){
TextView post_title = (TextView)mView.findViewById(R.id.Ctitle);
post_title.setText(title);
}
public void setCiudad (String ciudad){
TextView post_city = (TextView)mView.findViewById(R.id.Clugar);
post_city.setText(ciudad);
}
public void setPhotoURL(Context ctx, String pgotouserurl) {
ImageView post_image =(ImageView)mView.findViewById(R.id.Cimg);
Picasso.with(ctx).load(pgotouserurl).into(post_image);
} }
I hope you can help me.
First the XML code you've posted ils wrong closed,(must finish with a CardView tag)
On addition be sure you're pointing the CardView layout with mView field ans Only use GONE or INVISIBLE,
INVISIBLE change your Panel ( Root view ) structure but GONE don't
I have 2 layout files. One is the default one, and the other is sw720dp. Obviously, they both share the same model:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fresco="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<import type="java.lang.String" />
<variable
name="product"
type="com.test.test.test.test.Product" />
</data>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:orientation="vertical"
tools:context="com.test.test.test.test.ProductDetailsFragment">
<RelativeLayout
android:id="#+id/ll_custome_action_bar"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="#color/light_blue_900"
android:orientation="horizontal">
<TextView
android:id="#+id/tv_back_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:gravity="center_vertical"
android:padding="16dp"
android:text="#string/fa_arrow_left"
android:textColor="#color/white"
android:textSize="22sp" />
<TextView
android:id="#+id/tv_product_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
android:paddingLeft="46dp"
android:paddingRight="46dp"
android:text="#{product.name}"
android:textColor="#color/white"
android:textSize="18sp" />
</RelativeLayout>
<com.facebook.drawee.view.SimpleDraweeView
android:id="#+id/vp_product_images"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_below="#+id/ll_custome_action_bar"
fresco:actualImageScaleType="centerCrop"
fresco:placeholderImage="#drawable/placeholder2" />
<Button
android:id="#+id/btn_add_to_card"
android:layout_width="232dp"
android:layout_height="wrap_content"
android:layout_below="#+id/btn_wishlist"
android:layout_centerHorizontal="true"
android:layout_marginBottom="16dp"
android:background="#drawable/selector_button_green"
android:text="#string/add_to_cart"
android:textColor="#color/white"
android:textSize="16sp" />
<Button
android:id="#+id/btn_wishlist"
android:layout_width="232dp"
android:layout_height="wrap_content"
android:layout_below="#+id/ll_price_holder"
android:layout_centerHorizontal="true"
android:layout_marginBottom="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:background="#drawable/selector_button_red"
android:text="#string/wishlist"
android:textColor="#color/white"
android:textSize="16sp" />
<LinearLayout
android:id="#+id/ll_product_info_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/ll_product_images"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="5dp"
android:background="#drawable/drawable_border"
android:orientation="vertical">
<TextView
android:id="#+id/tv_product_description_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/light_blue_900"
android:gravity="center"
android:padding="3dp"
android:text="#string/description"
android:textColor="#color/white"
android:textSize="16sp" />
<TextView
android:id="#+id/tv_product_description_value"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:text="#{product.description}"
android:textColor="#color/gray_800"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll_price_holder"
android:layout_width="264dp"
android:layout_height="wrap_content"
android:layout_below="#+id/ll_product_info_holder"
android:layout_centerHorizontal="true"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/ll_total_price_holder"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/screen_edge_margin"
android:background="#drawable/drawable_border"
android:orientation="vertical">
<TextView
android:id="#+id/tv_total_price_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/light_blue_900"
android:gravity="center"
android:padding="3dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="#string/basePrice"
android:textColor="#color/white"
android:textSize="16sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="16dp">
<TextView
android:id="#+id/tv_total_price_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#{product.normalPrice}"
android:textColor="#color/gray_800"
android:textSize="14sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/blank_space"
android:textColor="#color/white"
android:textSize="12sp" />
<TextView
android:id="#+id/tv_total_price_currency"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#{product.productionData}"
android:textColor="#color/gray_800"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/ll_your_price_holder"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/screen_edge_margin"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:background="#drawable/drawable_border"
android:orientation="vertical">
<TextView
android:id="#+id/tv_your_price_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/light_blue_900"
android:gravity="center"
android:padding="3dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="#string/yourPrice"
android:textColor="#color/white"
android:textSize="16sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="16dp">
<TextView
android:id="#+id/tv_your_price_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#{product.specialPrice}"
android:textColor="#color/gray_800"
android:textSize="14sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/blank_space"
android:textColor="#color/white"
android:textSize="12sp" />
<TextView
android:id="#+id/tv_your_price_currency"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#{product.productionData}"
android:textColor="#color/gray_800"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/ll_product_images"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/vp_product_images"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="20dp"
android:orientation="horizontal">
<com.facebook.drawee.view.SimpleDraweeView
android:id="#+id/vp_product_image_1"
android:layout_width="100dp"
android:layout_height="70dp"
android:layout_margin="5dp"
android:layout_weight="1"
fresco:actualImageScaleType="centerCrop"
fresco:placeholderImage="#drawable/placeholder2" />
<com.facebook.drawee.view.SimpleDraweeView
android:id="#+id/vp_product_image_2"
android:layout_width="100dp"
android:layout_height="70dp"
android:layout_margin="5dp"
android:layout_weight="1"
fresco:actualImageScaleType="centerCrop"
fresco:placeholderImage="#drawable/placeholder2" />
<com.facebook.drawee.view.SimpleDraweeView
android:id="#+id/vp_product_image_3"
android:layout_width="100dp"
android:layout_height="70dp"
android:layout_margin="5dp"
android:layout_weight="1"
fresco:actualImageScaleType="centerCrop"
fresco:placeholderImage="#drawable/placeholder2" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
Then, in my fragment I access the binder like this FragmentProductDetailsBinding mBinder and later on mBinder.setProduct(mProduct);.
public class ProductDetailsFragment extends BaseFragment implements ProductDetailsView {
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
public static final String ACTION_SHOW_ACTION_BAR = ProductDetailsFragment.class.getName() + ".show_action_bar";
public static final String ACTION_HIDE_ACTION_BAR = ProductDetailsFragment.class.getName() + ".hide_action_bar";
public static final String ACTION_BACK = ProductDetailsFragment.class.getName() + ".back";
public static final String ACTION_ADD_TO_CART = ProductDetailsFragment.class.getName() + ".add_to_cart";
public static final String ACTION_ADD_TO_WISHLIST = ProductDetailsFragment.class.getName() + ".add_to_wishlit";
FragmentProductDetailsBinding mBinder;
Shop mShop;
Product mProduct;
ProductDetailsPresenter mPresenter;
PreferenceAdapter mPreferenceAdapter;
public ProductDetailsFragment() {
// Required empty public constructor
}
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* #param product Parameter 1.
* #return A new instance of fragment ProductDetailsFragment.
*/
public static ProductDetailsFragment newInstance(Shop shop, Product product) {
ProductDetailsFragment fragment = new ProductDetailsFragment();
Bundle args = new Bundle();
args.putParcelable(ARG_PARAM1, Parcels.wrap(shop));
args.putParcelable(ARG_PARAM2, Parcels.wrap(product));
fragment.setArguments(args);
return fragment;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
Parcelable parcelable;
parcelable = getArguments().getParcelable(ARG_PARAM1);
mShop = Parcels.unwrap(parcelable);
parcelable = getArguments().getParcelable(ARG_PARAM2);
mProduct = Parcels.unwrap(parcelable);
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mBinder = DataBindingUtil.inflate(inflater, R.layout.fragment_product_details, container, false);
setUIListeners();
mPresenter = new ProductDetailsPresenterImpl(this);
mPreferenceAdapter = new PreferenceAdapter(getContext());
mBinder.setProduct(mProduct);
setImages();
setPriceVisibility();
sendActionToActivity(ACTION_HIDE_ACTION_BAR);
if (isUserLogged()) {
mBinder.btnWishlist.setVisibility(View.VISIBLE);
} else {
mBinder.btnWishlist.setVisibility(View.GONE);
}
return mBinder.getRoot();
}
#Override
public void onDestroyView() {
super.onDestroyView();
mPresenter.cleanup();
sendActionToActivity(ACTION_SHOW_ACTION_BAR);
}
#Override
protected void setTypeface() {
mBinder.tvBackButton.setTypeface(FontManager.getInstance().getFontAwesome());
}
private void setUIListeners() {
mBinder.btnAddToCard.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
sendActionToActivity(ACTION_ADD_TO_CART, mShop, mProduct);
}
});
mBinder.btnWishlist.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
sendActionToActivity(ACTION_ADD_TO_WISHLIST, mShop, mProduct);
}
});
mBinder.tvBackButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
sendActionToActivity(ACTION_BACK);
}
});
}
private void setImages() {
String imagePathMax = mPreferenceAdapter.readImagePathMax();
String imagePathNormal = mPreferenceAdapter.readImagePathNormal();
String imageExtension = mPreferenceAdapter.readImageExtension();
String input = mProduct.getId();
input = input.replace(" ", "");
String image = imagePathMax + input + imageExtension;
String image_01 = imagePathNormal + input + "_01" + imageExtension;
String image_02 = imagePathNormal + input + "_02" + imageExtension;
final Uri imageUri = Uri.parse(image);
final Uri image_01Uri = Uri.parse(image_01);
final Uri image_02Uri = Uri.parse(image_02);
mBinder.vpProductImages.setImageURI(imageUri);
mBinder.vpProductImage1.setImageURI(imageUri);
mBinder.vpProductImage2.setImageURI(image_01Uri);
mBinder.vpProductImage3.setImageURI(image_02Uri);
mBinder.vpProductImage1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mBinder.vpProductImages.setImageURI(imageUri);
}
});
mBinder.vpProductImage2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mBinder.vpProductImages.setImageURI(image_01Uri);
}
});
mBinder.vpProductImage3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mBinder.vpProductImages.setImageURI(image_02Uri);
}
});
}
private void setPriceVisibility() {
if (mBinder.getProduct().getNormalPrice().equals(mBinder.getProduct().getSpecialPrice())) {
mBinder.llTotalPriceHolder.setVisibility(View.VISIBLE);
mBinder.llYourPriceHolder.setVisibility(View.GONE);
} else {
mBinder.llTotalPriceHolder.setVisibility(View.VISIBLE);
mBinder.llYourPriceHolder.setVisibility(View.VISIBLE);
}
}
#Override
public void logoutShop(Shop shop) {
}
#Override
public void showError(Error error) {
}
#Override
public void showProgress(boolean show) {
}
private void sendActionToActivity(String action) {
if (mListener == null) {
return;
}
Bundle bundle = new Bundle();
bundle.putString(Constants.ACTION_KEY, action);
mListener.onFragmentInteraction(bundle);
}
private void sendActionToActivity(String action, Shop shop, Product product) {
if (mListener == null) {
return;
}
Bundle bundle = new Bundle();
bundle.putString(Constants.ACTION_KEY, action);
bundle.putParcelable(Constants.DATA_KEY_1, Parcels.wrap(shop));
bundle.putParcelable(Constants.DATA_KEY_2, Parcels.wrap(product));
mListener.onFragmentInteraction(bundle);
}
public void logoutShop() {
AsyncExecutor.create().execute(new AsyncExecutor.RunnableEx() {
#Override
public void run() throws Exception {
mPresenter.logoutShop(mShop);
ShopRepository shopRepository;
shopRepository = new ShopRepository();
mShop.setLoginId(-1);
mShop.setCustomerId(-1);
mShop.setCartNumber(0);
mShop.setLineNumber(0);
mShop.setCartItems(0);
shopRepository.updateLoginNumber(mShop);
shopRepository.updateCart(mShop);
notifyChanges();
}
});
}
private boolean isUserLogged() {
return mShop != null && mShop.getLoginId() != -1;
}
private void notifyChanges() {
AuthShopResult event;
event = new AuthShopResult();
event.setShop(mShop);
EventBus.getDefault().post(event);
}
}
But when I try to run my app on tablet, and expect that the other layout is used, but I get an error at the binder.
C:\ProductDetailsFragment.java
Error:(179, 65) error: cannot find symbol method getProduct()
Error:(179, 20) error: cannot find symbol method getProduct()
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
Information:BUILD FAILED
Information:Total time: 6.231 secs
Information:3 errors
Information:0 warnings
Information:See complete output in console
The getProduct() error can be found in setPriceVisibility() method.
According to me FragmentProductDetailsBinding mBinder refers only to the standard layout, but there's no binder for the sw720dp layout. How do I solve this?
EDIT: I've added the following:
FragmentProductDetailsBindingSw720dpImpl mBinder720;
mBinder720 = DataBindingUtil.inflate(inflater, R.layout.fragment_product_details, container, false);
mBinder720.setProduct(mProduct);
mBinder720.getProduct().getNormalPrice().equals(mBinder720.getProduct().getSpecialPrice())
This way I have two binders and it works, but there must be a better way.
EDIT 2: I've posted the question at the Android bug tracker, please feel free to correct me if you have any suggestion.
For some reason the getter is not defined on the binding class FragmentProductDetailsBinding like it's documented:
The generated binding class will have a setter and getter for each of the described variables. The variables will take the default Java values until the setter is called — null for reference types, 0 for int, false for boolean, etc.
The *Impl classes extend this class and define this getter method while the setter is overridden. So I'd consider this to be a bug on the data binding generation side.
In your case you could work around this by using mProduct from your Fragment directly.
When run my app and click on the edittext to write something, the keyboard pushes/overlaps the edittext, why?
This is before the overlap
This is after the overlap
Here is my XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:id="#+id/title"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:text="HJÆLP......"
android:textSize="30dp"
android:background="#00796b"
android:textStyle="bold"
android:textColor="#ffffff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/suggestion"
android:hint="Hvad er dit forslag?"
android:gravity="top"
android:layout_below="#+id/title"
android:layout_alignParentStart="true"
android:layout_marginTop="61dp"
android:layout_alignParentEnd="true"
android:editable="true"
android:textAlignment="textStart"
android:layout_above="#+id/suggestknap" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send forslag"
android:id="#+id/suggestknap"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="157dp"
android:textColor="#ffffff"
android:background="#00796b" />
This is the java class for the fragment:
public class SuggestFrag extends Fragment implements View.OnClickListener {
Button suggestButton;
TextView title;
EditText suggestion;
Annonce annonce;
#Override
public View onCreateView(LayoutInflater i, ViewGroup container, Bundle savedInstanceState) {
View rod = i.inflate(R.layout.frag_suggest, container, false);
suggestButton = (Button)rod.findViewById(R.id.suggestknap);
suggestButton.setOnClickListener(this);
title = (TextView)rod.findViewById(R.id.title);
suggestion = (EditText)rod.findViewById(R.id.suggestion);
annonce = ((AnnonceDisplay)this.getActivity()).getAnnonce();
title.setText(annonce.getItemname());
return rod;
}
#Override
public void onClick(View view) {
if(view == suggestButton) {
AlertDialog alert = new AlertDialog.Builder(getActivity())
.setMessage(suggestion.getText().toString())
.setNeutralButton("ok", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
}
}
).show();
}
}
}
You can set your activity's windowSoftInputMode flag to adjustPan in android manifest file to prevent this.
<activity
...
android:windowSoftInputMode="adjustPan">
</activity>
I got a problem with a custom dialog in an android application.
I got a Custom Dialog with a ListView inside it. The Dialog itself is 600dp width and the ListView is 600dp as well.
The problem is that the dialog is more than that width value:
This is the Dialog layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="600dp"
android:layout_height="wrap_content"
android:orientation="vertical">
<ListView
android:id="#+id/promotionListView"
android:layout_width="600dp"
android:layout_height="400dp"
android:scrollbarStyle="insideOverlay"
android:dividerHeight="1dp" />
<LinearLayout
android:layout_width="600dp"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/promotion_dialog_abort"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/annulla"/>
<Button
android:id="#+id/promotion_dialog_apply"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/applica"/>
</LinearLayout>
</LinearLayout>
This is the layout of the single row: (note that both the width of the layout and the sum of single views is 600dp)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="600dp" <-- I tried "wrap_content" and "match_parent" with the same result
android:layout_height="wrap_content">
<CheckBox
android:id="#+id/promotionCheck"
android:layout_width="50dp"
android:layout_height="50dp"
android:gravity="center"
android:layout_gravity="center" />
<TextView
android:id="#+id/promotionText"
android:layout_width="350dp"
android:layout_height="50dp"
android:gravity="center_vertical"
android:layout_gravity="center"
android:textColor="#android:color/white"
android:textSize="#dimen/customerdetail_headertextsize" />
<TextView
android:id="#+id/promotionFactor"
android:layout_width="100dp"
android:layout_height="50dp"
android:gravity="center_vertical|right"
android:layout_gravity="center"
android:textColor="#android:color/white"
android:textSize="#dimen/customerdetail_headertextsize" />
<TextView
android:id="#+id/promotionPrice"
android:layout_width="100dp"
android:layout_height="50dp"
android:gravity="center_vertical|right"
android:layout_gravity="center"
android:textColor="#android:color/white"
android:textSize="#dimen/customerdetail_headertextsize" />
</LinearLayout>
And finally the Custom Dialog Class
public class PromotionDialog extends Dialog {
private boolean authCode;
private Set<OrderDetailDiscount> promotions;
private List<OrderDetailDiscount> selectedPromotions;
private ListView mainListView;
public Response response = Response.CANCEL;
private Button buttonAbort;
private Button buttonAccept;
public PromotionDialog(Context context, boolean authCode, Set<OrderDetailDiscount> promotions) {
super(context);
this.authCode = authCode;
this.promotions = promotions;
selectedPromotions = new ArrayList<>();
setTitle("Promozioni");
setContentView(R.layout.isfa_promotiondialog);
buttonAbort = (Button) findViewById(R.id.promotion_dialog_abort);
buttonAccept = (Button) findViewById(R.id.promotion_dialog_apply);
}
}
I really can't understand what the problem is, I tried to manually resize the titlebar with no success... what could I possibbly try?
You should use wrap_content or match_parent instead of fixed width/height values in order to support different screen sizes and to simulate table rows you can apply layout_weight to each child (column) of a horizontal LinearLayout.
Moreover, I suggest you to use AlertDialog.Builder APIs.
Here's what I achieved trying to recreate your dialog using my suggestions:
And here's the code:
MainActivity.java
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AlertDialog.Builder mBuilder = new AlertDialog.Builder(this);
mBuilder.setTitle("Discounts");
mBuilder.setAdapter(new MyAdapter(), null);
mBuilder.setPositiveButton("OK",new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
}
});
mBuilder.setNegativeButton("Cancel",new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
}
});
mBuilder.create().show();
}
class RowItem{
public String field1;
public String field2;
public String field3;
public RowItem(String f1,String f2, String f3){
field1=f1;
field2=f2;
field3=f3;
}
}
private class MyAdapter extends BaseAdapter{
private final ArrayList<RowItem> rows = new ArrayList<RowItem>();
public MyAdapter(){
rows.add(new RowItem("Sales","1","5%"));
rows.add(new RowItem("Extra Sales","2","50%"));
rows.add(new RowItem("Super Sales","3","70%"));
rows.add(new RowItem("Completely Free","4","100%"));
}
#Override
public int getCount(){
return rows.size();
}
#Override
public Object getItem(int p){
return rows.get(p);
}
#Override
public long getItemId(int p){
return p;
}
#Override
public View getView(int position, View v, ViewGroup parent){
v=getLayoutInflater().inflate(R.layout.row_layout,parent,false);
LinearLayout row = (LinearLayout)v.findViewById(R.id.linearlayout);
CheckBox checkBox = (CheckBox)v.findViewById(R.id.checkbox);
TextView field1 = (TextView)v.findViewById(R.id.field1);
TextView field2 = (TextView)v.findViewById(R.id.field2);
TextView field3 = (TextView)v.findViewById(R.id.field3);
row.setBackgroundColor(Color.parseColor(position%2==0?"#212121":"#424242"));
RowItem item = rows.get(position);
field1.setText(item.field1);
field2.setText(item.field2);
field3.setText(item.field3);
return v;
}
}
}
row_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearlayout"
android:orientation="horizontal"
android:weightSum="1"
android:layout_width="match_parent" android:layout_height="wrap_content">
<CheckBox
android:layout_width="0dp"
android:layout_weight="0.1"
android:layout_height="wrap_content"
android:text=""
android:id="#+id/checkbox"
android:checked="false" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="myText"
android:id="#+id/field1"
android:layout_weight="0.6" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="myText"
android:id="#+id/field2"
android:layout_weight="0.15" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="myText"
android:id="#+id/field3"
android:layout_weight="0.15" />
</LinearLayout>