The product details text which is fetched from the mysqlite database is pushed off the screen. I have look at other post with similar questions but none using mysqlite (I do not think this is the problem).
The text is displayed in a fragment opened when an element is clicked in the MainActivity.
I feel I am right using LinearLayout as it is just details about a product with a hint.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ProductDescriptionFragment"
android:orientation="vertical">
<TextView
android:id="@ id/textview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Product Fragment"
android:textSize="50dp" />
<TextView
android:id="@ id/txtViewProductNameFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Product Name: "
android:inputType="text" />
<TextView
android:id="@ id/txtViewProductPriceFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Product Price: "
android:inputType="text" />
<TextView
android:id="@ id/txtViewProductQuantityFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Product Quantity: "
android:inputType="text" />
<!-- This is the textView which is being pushed off the scrren -->
<TextView
android:id="@ id/txtViewProductDescriptionDetailedFragment"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:hint="Product Description: "
android:inputType="text" />
</LinearLayout>
The values for each line is passed from MainActivity using a RecyclerView when an Item is clicked a fragment is opened and I pass the values with Bundle.
// function that will bind an item in our arraylist to a view holder so it can be displayed
// we pull the elements views from the recycler_product.xml by initializing a ProductHolder
override fun onBindViewHolder(holder: ProductHolder, position: Int) {
// get the item at the current position
val item: Product = product_array.get(position)
// Here is where we are calling for the ProductDescription fragment to be opened once
// a item is clicked on the recyclerView
holder.itemView.setOnClickListener(object : View.OnClickListener{
override fun onClick(p0: View?) {
//TODO: ???
// creating a reference to the fragment we are opening
val activity = p0?.context as AppCompatActivity
val productFragment = ProductDescriptionFragment()
// Opening the fragment
activity.supportFragmentManager.beginTransaction().apply {
// creating a bundle of arguments to pass into the fragment
val args = Bundle()
args.putString("name", item.name)
args.putDouble("price", item.price)
args.putInt("quantity", item.quantity)
args.putString("description_detailed", item.description_detailed)
productFragment.arguments = args
// replace the container view id (our FrameLayout)
replace(R.id.flFragment, productFragment)
commit()
}
}
})
Now in the Fragment I collect them and display on screen
// We access on screen elements here for the fragment as they are guaranteed to
// be created and collect data passed from the adaptor bundle
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// Collecting the arguments passed by the adapter Bundle for a product
val args = arguments
val name = args?.getString("name")
val price = args?.getDouble("price")
val quantity = args?.getInt("quantity")
val description_detailed = args?.getString("description_detailed")
// Displaying the received arguments
val txtViewName: TextView? = view.findViewById(R.id.txtViewProductNameFragment)
txtViewName?.text = "Product Name: " name
val txtViewPrice: TextView? = view.findViewById(R.id.txtViewProductPriceFragment)
txtViewPrice?.text = "Product Price: " price
val txtViewQuantity: TextView? = view.findViewById(R.id.txtViewProductQuantityFragment)
txtViewQuantity?.text = "Product Price: " quantity
val txtViewDetails: TextView? = view.findViewById(R.id.txtViewProductDescriptionDetailedFragment)
txtViewDetails?.text = "Product Details: " description_detailed
}
CodePudding user response:
your width should be match_parent
. wrap_content
makes your view as something which can take infinite length. change:
<!-- This is the textView which is being pushed off the scrren -->
<TextView
android:id="@ id/txtViewProductDescriptionDetailedFragment"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:hint="Product Description: "
android:inputType="text" />
to
<!-- This is the textView which is being pushed off the scrren -->
<TextView
android:id="@ id/txtViewProductDescriptionDetailedFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Product Description: "
/>