Vitamio full screen videoview - fullscreen

I try to play live streaming with Vitamio. I fixed some problems however I can't fix this problem. Video doesn't play in fullscreen. These are my codes. I hope you can help me! Thank you and sorry for my bad English.
package com.uusoftware.tvizle;
import io.vov.vitamio.widget.MediaController;
import io.vov.vitamio.widget.VideoView;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.view.WindowManager;
public class Trt extends Activity{
VideoView videoView;
private void Trt1(){
String httpLiveUrl = "rtmp://trt-i.mncdn.com/trt1/trt15";
videoView = (VideoView) findViewById(R.id.VideoView);
videoView.setVideoURI(Uri.parse(httpLiveUrl));
MediaController mediaController = new MediaController(this);
videoView.setMediaController(mediaController);
videoView.requestFocus();
videoView.start();
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.videolayout);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Trt1();
}
}
<?xml version="1.0" encoding="utf-8"?>`
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<io.vov.vitamio.widget.CenterLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<io.vov.vitamio.widget.VideoView
android:id="#+id/VideoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</io.vov.vitamio.widget.CenterLayout>
</LinearLayout>

Put the VideoView in a RelativeLayout and set it as:
<io.vov.vitamio.widget.VideoView
android:id="#+id/vitamioView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true" />

Use this method to stretch your videoview in onCreate() method of your activity
mVideoView.setVideoLayout(VideoView.VIDEO_LAYOUT_STRETCH, 0);
To handle onConfigurationChange();
use below code
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
mVideoView.setVideoLayout(VideoView.VIDEO_LAYOUT_STRETCH, 0);
Log.e("On Config Change", "LANDSCAPE");
} else {
mVideoView.setVideoLayout(VideoView.VIDEO_LAYOUT_STRETCH, 0);
Log.e("On Config Change", "PORTRAIT");
}
}
also add this in your activity menifest file
android:configChanges="orientation|screenSize|smallestScreenSize|keyboard|keyboardHidden|navigation"

if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
mVideoView.setVideoLayout(io.vov.vitamio.widget.VideoView.VIDEO_LAYOUT_STRETCH, 0);
} else if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
mVideoView.setVideoLayout(io.vov.vitamio.widget.VideoView.VIDEO_LAYOUT_ORIGIN, 0);
}
thank #Qadir Hussain
.it work for me

If using live streaming, then
there is a layout file for live streaming with the name of "mediaplayer_2.xml"
change the layout with following.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<io.vov.vitamio.widget.CenterLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<SurfaceView
android:id="#+id/surface"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center" >
</SurfaceView>
</io.vov.vitamio.widget.CenterLayout>
</LinearLayout>
Through this way i resolve my issue.

`package com.uusoftware.tvizle;
import io.vov.vitamio.widget.MediaController;
import io.vov.vitamio.widget.VideoView;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.view.WindowManager;
public class Trt extends Activity{
private VideoView mVideoView;
private void Trt1(){
String httpLiveUrl = "rtmp://trt-i.mncdn.com/trt1/trt15";
mVideoView = (VideoView) findViewById(R.id.VideoView);
mVideoView.setVideoURI(Uri.parse(httpLiveUrl));
MediaController mediaController = new MediaController(this);
mVideoView.setMediaController(mediaController);
mVideoView.requestFocus();
mVideoView.setVideoLayout(VideoView.VIDEO_LAYOUT_STRETCH, 0);
mVideoView.start();
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.videolayout);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Trt1();
}
}`

Related

How can I pass the checked radio button value into text View in kotlin android studio?

I made a dialogue box and I put radio group in it and I add three radio button 1)male 2)female 3)others if user select male so the selected radio button male should be shown in text View
Here, I would like to share you here a simple app with both the activity and layout code. I hope this will help you.
First the layout
<?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="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="100dp"
tools:context=".TestActivity">
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="20dp"
android:text="What is your gender?"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/txtViewGender"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="20dp"
android:text="-- Selected Gender --"
android:textSize="16sp" />
<Button
android:id="#+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Select" />
</LinearLayout>
Second the Main Activity code
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.dialog.MaterialAlertDialogBuilder
class GenderActivity: AppCompatActivity() {
private lateinit var selectedGender: String
private var selectedGenderIndex: Int = 0
private val gender = arrayOf("Male", "Female", "Others")
private lateinit var txtViewGender: TextView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_test4)
txtViewGender = findViewById<TextView>(R.id.txtViewGender)
var androidButton: Button = findViewById<Button>(R.id.button)
androidButton.setOnClickListener {
showRadioDialog()
}
}
private fun showRadioDialog() {
selectedGender = gender[selectedGenderIndex]
MaterialAlertDialogBuilder(this)
.setTitle("Select your gender")
.setSingleChoiceItems(gender, selectedGenderIndex) { dialog, which ->
selectedGenderIndex = which
selectedGender = gender[which]
}
.setPositiveButton("Ok") { dialog, which ->
Toast.makeText(this, "Selected --> $selectedGender ", Toast.LENGTH_SHORT)
.show()
txtViewGender.text = selectedGender
}
.setNegativeButton("Cancel") { dialog, which ->
dialog.dismiss()
}
.show()
}
}
When you run the code, you will get the following two screens.
Screen 1
Screen 2

Kotlin "D/skia: --- Failed to create image decoder with message 'unimplemented'" Error preventing functionality of button at login/registration screen

Hello I am currently facing an issue with my Kotlin code in Android SDK. For the purposes of a small personal project I am trying to get a simple change password functionality working with a nodeJS file and mongoDB. However I've run into the issue while writting up some code to this end. It seems that my change_password function doesn't want to launch the sequence to input the new password due to the following error "D/skia: --- Failed to create image decoder with message 'unimplemented'" which is only visible in the debug mode. I am not even certain where to start debugging this issue, so I'm hoping someone here might be able to help. Bellow I have provided my MainActivity file where the change_password function is present. Additionally I have provided the xml layout files involved in these operations.
MainActivity File
import android.Manifest
import android.app.Activity
import android.bluetooth.BluetoothAdapter
import android.bluetooth.BluetoothDevice
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.widget.AdapterView
import android.widget.ArrayAdapter
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import com.afollestad.materialdialogs.MaterialDialog
import com.example.accentus_login.R.id.*
import com.example.accentus_login.Retrofit.INodeJS
import com.example.accentus_login.Retrofit.RetrofitClient
import com.github.javiersantos.materialstyleddialogs.MaterialStyledDialog
import com.rengwuxian.materialedittext.MaterialEditText
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.home_page.*
import org.jetbrains.anko.toast
class MainActivity : AppCompatActivity() {
lateinit var myAPI: INodeJS
var compositeDisposable = CompositeDisposable()
var m_bluetoothAdapter: BluetoothAdapter? = null
lateinit var m_pairedDevices: Set<BluetoothDevice>
val REQUEST_ENABLE_BLUETOOTH=1
internal lateinit var change_pass_confirm_button: Button
companion object{
val EXTRA_ADDRESS: String = "Device_address"
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//Init API
val retrofit = RetrofitClient.instance
myAPI = retrofit.create(INodeJS::class.java)
//m_bluetoothAdapter = BluetoothAdapter.getDefaultAdapter()
//if (m_bluetoothAdapter==null){
// toast("this device doesn't support bluetooth")
// return
//}
//if(!m_bluetoothAdapter!!.isEnabled) {
// val enableBluetoothIntent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
// if (ActivityCompat.checkSelfPermission(
// this,
// Manifest.permission.BLUETOOTH_CONNECT
// ) != PackageManager.PERMISSION_GRANTED
// ) {
// ActivityCompat.requestPermissions(
// this#MainActivity,
// arrayOf(Manifest.permission.BLUETOOTH, Manifest.permission.BLUETOOTH_ADMIN),REQUEST_ENABLE_BLUETOOTH)
// }
// startActivityForResult(enableBluetoothIntent, REQUEST_ENABLE_BLUETOOTH)
//}
//select_device_refresh.setOnClickListener{ pairedDeviceList() }
//change_pass_confirm_button = findViewById(R.id.change_pass_confirm_button);
login_button.setOnClickListener{
login(edt_email.text.toString(),edt_password.text.toString())
}
register_button.setOnClickListener{
register(edt_email.text.toString(),edt_password.text.toString())
}
change_pass_button.setOnClickListener{
change_password(edt_email.text.toString())
}
}
private fun login(email: String, password: String) {
compositeDisposable.add(myAPI.loginUser(email, password)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe{ message ->
if (message.contains("encrypted_password"))
Toast.makeText(this#MainActivity,"Login Successful",Toast.LENGTH_SHORT).show()
else
Toast.makeText(this#MainActivity,message,Toast.LENGTH_SHORT).show()
setContentView(R.layout.home_page);
})
}
private fun change_password(email: String) {
val change_pass_view = LayoutInflater.from(this#MainActivity)
.inflate(R.layout.change_pass, null)
MaterialStyledDialog.Builder(this#MainActivity)
.setTitle("Change Password")
.setDescription("Enter New Password")
.setCustomView(change_pass_view)
.setNegativeText("Cancel")
.onNegative { materialDialog: MaterialDialog -> materialDialog.dismiss() }
.setPositiveText("Confirm")
.onPositive { materialDialog: MaterialDialog ->
val password = change_pass_view.findViewById(R.id.new_pass) as MaterialEditText
//val con_password = change_pass_view.findViewById(R.id.con_new_pass) as MaterialEditText
if (password != password)
Toast.makeText(this#MainActivity, "Password Doesn't Match", Toast.LENGTH_SHORT)
.show()
else
compositeDisposable.add(myAPI.ChangePass(email, password)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe { message ->
Toast.makeText(this#MainActivity, message, Toast.LENGTH_SHORT).show()
})
}
}
private fun register(email: String, password: String) {
val enter_name_view = LayoutInflater.from(this#MainActivity)
.inflate(R.layout.enter_name_layout,null)
MaterialStyledDialog.Builder(this#MainActivity)
.setTitle("Register")
.setDescription("Last Step: Enter your Name")
.setCustomView(enter_name_view)
.setIcon(R.drawable.ic_user)
.setNegativeText("Cancel")
.onNegative{ materialDialog: MaterialDialog-> materialDialog.dismiss() }
.setPositiveText("Register")
.onPositive { materialDialog: MaterialDialog ->
val edt_name = enter_name_view.findViewById<View>(edt_name) as MaterialEditText
compositeDisposable.add(myAPI.registerUser(email,edt_name.text.toString(), password)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe{ message ->
Toast.makeText(this#MainActivity,message,Toast.LENGTH_SHORT).show()
})
}.show()
}
private fun pairedDeviceList(){
if (ActivityCompat.checkSelfPermission(
this,
Manifest.permission.BLUETOOTH_CONNECT
) != PackageManager.PERMISSION_GRANTED
) {
ActivityCompat.requestPermissions(
this#MainActivity,
arrayOf(Manifest.permission.BLUETOOTH, Manifest.permission.BLUETOOTH_ADMIN),REQUEST_ENABLE_BLUETOOTH)
}
m_pairedDevices = m_bluetoothAdapter!!.bondedDevices
val list : ArrayList<BluetoothDevice> = ArrayList()
if(m_pairedDevices.isNotEmpty()) {
for(device : BluetoothDevice in m_pairedDevices) {
list.add(device)
Log.i("device", ""+device) // device logged as string
}
} else {
toast("no paired bluetooth devices found")
}
val adapter = ArrayAdapter(this,android.R.layout.simple_list_item_1,list)
select_device_list.adapter=adapter
select_device_list.onItemClickListener= AdapterView.OnItemClickListener{ _, _, position, _ ->
val device: BluetoothDevice= list[position]
val address: String = device.address
val intent = Intent(this, ControlActivity::class.java)
intent.putExtra(EXTRA_ADDRESS,address)
startActivity(intent)
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode==REQUEST_ENABLE_BLUETOOTH){
if(resultCode== Activity.RESULT_OK) {
if (m_bluetoothAdapter!!.isEnabled) {
toast("Bluetooth has been enabled")
} else {
toast("Bluetooth has been disabled")
}
} else if (resultCode == Activity.RESULT_CANCELED)
toast("Bluetooth enabling has been canceled")
}
}
override fun onStop() {
compositeDisposable.clear()
super.onStop()
}
override fun onDestroy() {
compositeDisposable.clear()
super.onDestroy()
}
XML Login Page
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/gradient_bg"
tools:context=".MainActivity">
<LinearLayout
android:layout_margin="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" >
<TextView
android:text="#string/accentus"
android:textSize="30sp"
android:textColor="#android:color/white"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<com.rengwuxian.materialedittext.MaterialEditText
android:id="#+id/edt_email"
android:hint="#string/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
app:met_iconLeft="#drawable/ic_user"
app:met_baseColor="#android:color/white"
app:met_textColorHint="#android:color/white"
app:met_primaryColor="#android:color/white"
app:met_iconPadding="0dp"/>
<com.rengwuxian.materialedittext.MaterialEditText
android:id="#+id/edt_password"
android:hint="#string/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
app:met_iconLeft="#drawable/ic_lock"
app:met_baseColor="#android:color/white"
app:met_textColorHint="#android:color/white"
app:met_primaryColor="#android:color/white"
app:met_iconPadding="0dp"/>
<LinearLayout
android:orientation="horizontal"
android:weightSum="2"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.button.MaterialButton
android:id="#+id/register_button"
android:text="#string/register_account"
android:layout_marginEnd="8dp"
android:textSize="11sp"
style="#style/Widget.MaterialComponents.Button"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content">
</com.google.android.material.button.MaterialButton>
<com.google.android.material.button.MaterialButton
android:id="#+id/login_button"
android:text="#string/login"
android:layout_marginStart="8dp"
android:textSize="11sp"
style="#style/Widget.MaterialComponents.Button.UnelevatedButton"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content">
</com.google.android.material.button.MaterialButton>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:weightSum="2"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.button.MaterialButton
android:id="#+id/change_pass_button"
android:text="#string/forgot_password"
android:layout_marginStart="125dp"
android:textSize="11sp"
style="#style/Widget.MaterialComponents.Button.UnelevatedButton"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content">
</com.google.android.material.button.MaterialButton>
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
XML Change Password Page
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/gradient_bg"
tools:context=".MainActivity">
<LinearLayout
android:layout_margin="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" >
<TextView
android:text="#string/change_password"
android:textSize="30sp"
android:textColor="#android:color/white"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<com.rengwuxian.materialedittext.MaterialEditText
android:id="#+id/login_email"
android:hint="#string/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
app:met_baseColor="#android:color/white"
app:met_textColorHint="#android:color/white"
app:met_primaryColor="#android:color/white"
app:met_iconPadding="0dp"/>
<com.rengwuxian.materialedittext.MaterialEditText
android:id="#+id/new_pass"
android:hint="#string/new_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
app:met_baseColor="#android:color/white"
app:met_textColorHint="#android:color/white"
app:met_primaryColor="#android:color/white"
app:met_iconPadding="0dp"/>
<com.rengwuxian.materialedittext.MaterialEditText
android:id="#+id/con_new_pass"
android:hint="#string/confirm_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
app:met_iconLeft="#drawable/ic_lock"
app:met_baseColor="#android:color/white"
app:met_textColorHint="#android:color/white"
app:met_primaryColor="#android:color/white"
app:met_iconPadding="0dp"/>
<LinearLayout
android:orientation="horizontal"
android:weightSum="2"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Please let me know if you think there is any other information necessary to understand why this is going on.

Why does Unexpected implicit cast to `EditText`: layout tag was `TextView`

I have a problem, I'm trying to finish the lesson Android fundamentals 02.3: Implicit intents, but there are some errors
the first one is Unexpected implicit cast to EditText: layout tag was TextView
the second one is Consider adding a declaration to your manifest when calling this \ method; see https://g.co/dev/packagevisibility for details
when running the application, it automatically stops immediately, I have tried it on the emulator and on real devices
source codelab : https://developer.android.com/codelabs/android-training-activity-with-implicit-intent?index=..%2F..%2Fandroid-training#0
Code MainActivity.java
package com.example.implicitintents;
import android.content.Intent;
import android.net.Uri;
import android.support.v4.app.ShareCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
private EditText mWebsiteEditText;
private EditText mLocationEditText;
private EditText mShareTextEditText;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebsiteEditText = findViewById(R.id.website_edittext);
mLocationEditText = findViewById(R.id.location_edittext);
mShareTextEditText = findViewById(R.id.share_edittext);
}
public void openWebsite(View view) {
String url = mWebsiteEditText.getText().toString();
Uri webpage = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
} else {
Log.d("ImplicitIntents", "Can't handle this intent!");
}
}
public void openLocation(View view) {
String loc = mLocationEditText.getText().toString();
Uri addressUri = Uri.parse("geo:0,0?q=" + loc);
Intent intent = new Intent(Intent.ACTION_VIEW, addressUri);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
} else {
Log.d("ImplicitIntents", "Can't handle this intent!");
}
}
public void shareText(View view) {
String txt = mShareTextEditText.getText().toString();
String mimeType = "text/plain";
ShareCompat.IntentBuilder
.from(this)
.setType(mimeType)
.setChooserTitle("Share this text with: ")
.setText(txt)
.startChooser();
}
}
Code Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
tools:context="MainActivity">
<TextView
android:id="#+id/website_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/edittext_uri" />
<Button
android:id="#+id/open_website_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:onClick="openWebsite"
android:text="#string/button_uri" />
<TextView
android:id="#+id/location_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/edittext_loc" />
<Button
android:id="#+id/open_location_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:onClick="openLocation"
android:text="#string/button_loc" />
<TextView
android:id="#+id/share_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/edittext_share" />
<Button
android:id="#+id/share_text_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:onClick="shareText"
android:text="#string/button_share" />
</LinearLayout>
In your xml file you declare three elements as Textview
<TextView
android:id="#+id/website_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/edittext_uri" />
<TextView
android:id="#+id/location_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/edittext_loc" />
<TextView
android:id="#+id/share_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/edittext_share" />
And then in your activity you declare your variables as EditText
private EditText mWebsiteEditText;
private EditText mLocationEditText;
private EditText mShareTextEditText;
And that's why your seeing those errors of casting.
Change in your xml file to EditText if you want to input some data or leave it like TextView if you want display some text but change the type of your variables in the activity. Make sure both are the same type

No adapter attached; skipping layout error in logcat windowin android studio

i have been facing this issue from 3-4 days and i still can't resolve this error. i have also gone through this a solution of the same problem
but i didn't understand enough. i got that, that this error occurs when we didn't attach our adapter but i have attached.
below i have attached my fragment file, adapter file and RecyclerView file-
this is a code where i declared my adapter
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.chumonsuru.R
import com.example.chumonsuru.model.Resturant
import com.squareup.picasso.Picasso
class DashboardRecyclerAdapter(val context : Context , val resturantInfoList : ArrayList<Resturant>) : RecyclerView.Adapter<DashboardRecyclerAdapter.DashboardViewHolder>(){
class DashboardViewHolder(view:View): RecyclerView.ViewHolder(view){
val txtResturantid : TextView = view.findViewById(R.id.txtResturantid)
val txtResturantName : TextView = view.findViewById(R.id.txtResturantName)
val txtPerPrice : TextView = view.findViewById(R.id.txtPerPrice)
val txtResturantRating : TextView = view.findViewById(R.id.txtResturantRating)
val imgResturantImage : ImageView = view.findViewById(R.id.imgResturantImage)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DashboardViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.recycler_dashboard_row_one , parent , false)
return DashboardViewHolder(view)
}
override fun getItemCount(): Int {
return resturantInfoList.count()
}
override fun onBindViewHolder(holder: DashboardViewHolder, position: Int) {
val resturant = resturantInfoList[position]
holder.txtResturantid.text = resturant.id
holder.txtResturantName.text = resturant.name
holder.txtPerPrice.text = resturant.cost_for_one
holder.txtResturantRating.text = resturant.rating
Picasso.get().load(resturant.image_url).into(holder.imgResturantImage)
}
}
and here is my dashboard fragment file-
import android.content.Context
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.android.volley.Request
import com.android.volley.Response
import com.android.volley.toolbox.JsonObjectRequest
import com.android.volley.toolbox.Volley
import com.example.chumonsuru.R
import com.example.chumonsuru.adapter.DashboardRecyclerAdapter
import com.example.chumonsuru.model.Resturant
import kotlin.collections.HashMap
class DashFrag : Fragment() {
lateinit var recyclerView: RecyclerView
lateinit var linearLayoutManager: LinearLayoutManager
lateinit var recyclerAdapter: DashboardRecyclerAdapter
val resturantInfoList = arrayListOf<Resturant>()
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
val view = inflater.inflate(R.layout.dash_frag, container, false)
linearLayoutManager = LinearLayoutManager(activity)
recyclerView = view.findViewById(R.id.recyclerView)
val queue = Volley.newRequestQueue(activity as Context)
val url = "http://13.235.250.119/v1/book/fetch_books/"
val jsonObjectRequest = object : JsonObjectRequest(Request.Method.GET, url, null, Response.Listener {
val success = it.getBoolean("success")
if (success != null) {
val data = it.getJSONArray("data")
for (i in 0 until data.length()) {
val resturantJsonObject = data.getJSONObject(i)
val resturantObject = Resturant(
resturantJsonObject.getString("id"),
resturantJsonObject.getString("name"),
resturantJsonObject.getString("rating"),
resturantJsonObject.getString("cost_for_one"),
resturantJsonObject.getString("image_url")
)
resturantInfoList.add(resturantObject)
recyclerAdapter = DashboardRecyclerAdapter(activity as Context, resturantInfoList)
recyclerView.adapter = recyclerAdapter
recyclerView.layoutManager = linearLayoutManager
recyclerView.addItemDecoration(DividerItemDecoration(recyclerView.context,
(linearLayoutManager)
.orientation))
}
}
},
Response.ErrorListener {
/////ERROR/////
}) {
override fun getHeaders(): MutableMap<String, String> {
val headers = HashMap<String, String>()
headers["Content-type"] = "application/json"
headers["token"] = "xyz"
return headers
}
}
queue.add(jsonObjectRequest)
return view
}
}
and
my restaurant class-
data class Resturant(
val id: String,
val name: String,
val rating: String,
val cost_for_one : String,
val image_url: String
)
my dashboard fragment xml file-
<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"
tools:context=".fragments.DashFrag">
<!-- TODO: Update blank fragment layout -->
<TextView
android:id="#+id/txtHelloFrag"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/hello_blank_fragment"
android:textSize="50sp"
android:textColor="#color/colorAccent"
android:padding="20dp"
android:background="#drawable/gradient"/>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/txtHelloFrag"
android:layout_margin="10dp"
android:padding="5dp"
/>
</RelativeLayout>
and the layout of the row of the recycler view
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="140dp"
android:orientation="horizontal"
android:background="#ffffff"
android:weightSum="6">
<ImageView
android:layout_weight="1.5"
android:id="#+id/imgResturantImage"
android:layout_width="0dp"
android:layout_height="110dp"
android:src="#mipmap/ic_launcher1"
android:padding="5dp"/>
<RelativeLayout
android:layout_weight="3.3"
android:layout_width="0dp"
android:layout_height="match_parent">
<TextView
android:padding="8dp"
android:id="#+id/txtResturantid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="id"
android:layout_toLeftOf="#id/txtResturantName"
android:textSize = "18sp"
/>
<TextView
android:id="#+id/txtResturantName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Name of the Resturant"
android:paddingTop="8dp"
android:textSize="18sp"
android:textColor="#000000"/>
<TextView
android:id="#+id/txtBookAuthor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/txtResturantName"
android:text="Name of the Author"
android:padding="8dp"
android:textSize="15sp"/>
<TextView
android:id="#+id/txtPerPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Rs. 299"
android:paddingTop="8dp"
android:paddingLeft="8dp"
android:layout_below="#id/txtBookAuthor"
android:textSize="15sp"
android:textStyle="bold"
android:textColor="#357a38"/>
<TextView
android:id="#+id/txtPerPerson"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/person"
android:layout_toRightOf="#id/txtPerPrice"
android:textSize="15sp"
android:layout_below="#id/txtBookAuthor"
android:textColor="#357a38"
android:paddingTop="8dp"
android:textStyle="bold"/>
</RelativeLayout>
<TextView
android:id="#+id/txtResturantRating"
android:layout_weight="1.2"
android:layout_width="0dp"
android:padding="6dp"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/star_foreground"
android:textColor="#ffca28"
android:text="4.5"
android:textSize="15sp"
android:textStyle="bold">
</TextView>
</LinearLayout>
i think i have already attached the adapter to my recycler view. if i didn't please help me to do this.
Please help me to get rid of this problem
I think something that you need to check.
return view
Instead of this, you have to use
return view;
second,
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/txtHelloFrag"
android:layout_margin="10dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:padding="5dp"
/>
You try to put app:layoutManager into that.
or
val layoutManager = LinearLayoutManager(this)
recyclerView_main.setLayoutManager(layoutManager)
As above, LayoutManager is set in the setLayoutManager and it processes as code.
LinearLayoutManager manager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(manager);
this is related above, you have set the layout manager for RecyclerView
I hope that It will be work.

Android Studio: Click TextView to open an Specific Image on other Activity (Click Index Title to Open page on other Activity)

I m Developing Book Reading Project on Android studio, it has index activity with all titles and page numbers, when some one click on any title of index so on the an other activity the specific image should be open. all images are in Drawable folder.
here is XML Coding of First Activity coding Activity_main3.xml
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:stretchColumns="0,1,2"
android:gravity="center"
android:shrinkColumns="1">
<TableRow
android:background="#000000"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_margin="1dp"
android:layout_weight="1"
>
<TextView
android:id="#+id/textview1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_column="0"
android:layout_margin="1dp"
android:autoSizeTextType="uniform"
android:background="#FFFFFF"
android:gravity="center"
android:text="ناشر پاران...5"
android:textAppearance="?android:attr/textAppearanceLarge" />
/>
<TextView
android:id="#+id/textview2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_column="2"
android:layout_margin="1dp"
android:autoSizeTextType="uniform"
android:background="#FFFFFF"
android:gravity="center"
android:text="پنهنجي پاران...6"
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
The Second Activty coding is like this Activity_main.xml
<android.support.constraint.ConstraintLayout 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="org.sindhila.www.sindhi_school_linguistics.MainActivity"
tools:layout_editor_absoluteY="81dp">
<Button
android:id="#+id/SwitchImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:text="Next"
app:layout_constraintBaseline_toBaselineOf="#+id/SwitchImage2"
app:layout_constraintEnd_toStartOf="#+id/SwitchImage2"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent" />
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="#mipmap/pic3" />
<Button
android:id="#+id/SwitchImage2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:text="Previous"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/SwitchImage" />
and Here is Coding Of mainactivity.java
it has two buttons for next and previous page and an image view to open images from drawable folder
package org.sindhila.www.sindhi_school_linguistics;
import android.content.res.AssetManager;
import android.graphics.Typeface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import java.util.Locale;
import uk.co.senab.photoview.PhotoViewAttacher;
public class MainActivity extends AppCompatActivity {
private static ImageView imageView;
private static Button SwitchImage;
private static Button SwitchImage2;
//
PhotoViewAttacher photoViewAttacher;
////
private int current_image_index;
int images[] = {R.mipmap.pic1, R.mipmap.pic2, R.mipmap.pic3,
R.mipmap.pic4,
R.mipmap.pic5,
R.mipmap.pic6,
R.mipmap.pic7,
R.mipmap.pic8,
R.mipmap.pic9,
R.mipmap.pic10,
R.mipmap.pic11,
R.mipmap.pic12,
R.mipmap.pic13,
R.mipmap.pic14,
R.mipmap.pic15,
R.mipmap.pic16,
R.mipmap.pic17,
R.mipmap.pic18,
R.mipmap.pic19,
R.mipmap.pic20,
R.mipmap.pic21,
R.mipmap.pic22,
R.mipmap.pic23,
R.mipmap.pic24,
R.mipmap.pic25,
R.mipmap.pic26,
R.mipmap.pic27,
R.mipmap.pic28,
R.mipmap.pic29,
R.mipmap.pic30,
R.mipmap.pic31,
R.mipmap.pic32,
R.mipmap.pic33,
R.mipmap.pic34,
R.mipmap.pic35,
R.mipmap.pic36,
R.mipmap.pic37,
R.mipmap.pic38,
R.mipmap.pic39,
R.mipmap.pic40,
R.mipmap.pic41,
R.mipmap.pic42,
R.mipmap.pic43,
R.mipmap.pic44,
R.mipmap.pic45,
R.mipmap.pic46,
R.mipmap.pic47,
R.mipmap.pic48,
R.mipmap.pic49,
R.mipmap.pic50,
R.mipmap.pic51,
R.mipmap.pic52,
R.mipmap.pic53,
R.mipmap.pic54,
R.mipmap.pic55,
R.mipmap.pic56,
R.mipmap.pic57,
R.mipmap.pic58,
R.mipmap.pic59,
R.mipmap.pic60,
R.mipmap.pic61,
R.mipmap.pic62,
R.mipmap.pic63,
R.mipmap.pic64,
R.mipmap.pic65,
R.mipmap.pic66,
R.mipmap.pic67,
R.mipmap.pic68,
R.mipmap.pic69,
R.mipmap.pic70,
R.mipmap.pic71,
R.mipmap.pic72,
R.mipmap.pic73,
R.mipmap.pic74,
R.mipmap.pic75,
R.mipmap.pic76,
R.mipmap.pic77,
R.mipmap.pic78,
R.mipmap.pic79,
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonClick();
buttonClick2();
//////
imageView = (ImageView)findViewById(R.id.imageView);
Drawable drawable = getResources().getDrawable(R.mipmap.pic1);
imageView.setImageDrawable(drawable);
photoViewAttacher = new PhotoViewAttacher(imageView);
photoViewAttacher.update();
//////
}
public void buttonClick() {
imageView = (ImageView) findViewById(R.id.imageView);
SwitchImage = (Button) findViewById(R.id.SwitchImage);
SwitchImage.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View view) {
current_image_index++;
current_image_index = current_image_index % images.length;
imageView.setImageResource(images[current_image_index]);
}
}
);
}
public void buttonClick2() {
imageView = (ImageView) findViewById(R.id.imageView);
SwitchImage2 = (Button) findViewById(R.id.SwitchImage2);
SwitchImage2.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View view) {
if (current_image_index!=0) {
current_image_index--;
current_image_index = current_image_index % images.length;
imageView.setImageResource(images[current_image_index]);
}
}
}
);
}
}
Every thing is working Fine, i need to have hyperlink on Textview (on Activity_main3.xml and Main3Activity.java) to open specific image on Activity_main.xml/MainActivity.java
i have used following Coding but it produce error how to solve it please help. i want to click a textview on one activity and open specific image on other activity in imageview
in xml file of first activity in textview i added
android:onClick="onClick"
android:clickable="true"
.... added coding to first index activity named Main3activity.java where textviews are placed when I click textview it should open other activity and an image in it
public void onClick(View v) {
Intent intent = new Intent(Main3Activity.this,
MainActivity.class);
intent.putExtra("pic", pic4.png);
startActivity(intent);
} ...
and this coding to mainactivity.java where image should be opened in image view
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonClick();
buttonClick2();
setContentView(R.mipmap.pic1);
ImageView iv = (ImageView) findViewById(R.id.imageView);
iv.setImageResource(getIntent().getIntExtra("img", 0));

Resources