My DetailActivity.java file shows an error by not picking ActivityDetailBinding. Other Activity files are working fine and I put;
buildFeatures{
viewBinding true
}
in build.gradle file before start working on xml files. Only DetailActivity.java file is showing this error.
Error displaying is;
import com.example.juizeesapp.databinding.ActivityDetailBinding; ^ symbol: class ActivityDetailBinding location: package com.example.juizeesapp.databinding
Please look into this help me through this. TIA.
Here is my code.
activity_detail.xml
<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"
tools:context=".DetailActivity"
>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="#+id/detailImage"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="centerCrop"
app:srcCompat="#drawable/apple" />
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="5dp"
android:text="Juice Name"
android:textColor="#000000"
android:textSize="24sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="25dp"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="#+id/subtract"
android:layout_width="30dp"
android:layout_height="wrap_content"
app:srcCompat="#drawable/minus" />
<TextView
android:id="#+id/quantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="2dp"
android:layout_marginLeft="2dp"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:text="1"
android:textSize="18sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/add"
android:layout_width="30dp"
android:layout_height="wrap_content"
app:srcCompat="#drawable/plus" />
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:orientation="vertical">
<TextView
android:id="#+id/detailDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginBottom="10dp"
android:gravity="center"
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam iaculis." />
<EditText
android:id="#+id/nameBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:background="#drawable/edit_textbackground"
android:ems="10"
android:hint="Name"
android:inputType="textPersonName"
android:minHeight="48dp"
android:padding="10dp" />
<EditText
android:id="#+id/phoneBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:background="#drawable/edit_textbackground"
android:ems="10"
android:hint="Phone Number"
android:inputType="phone"
android:minHeight="48dp"
android:padding="10dp" />
<TextView
android:id="#+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:gravity="center"
android:text="Price"
android:textColor="#000000" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rs. "
android:textColor="#color/red"
android:textSize="18dp"
android:textStyle="bold" />
<TextView
android:id="#+id/priceLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="45"
android:textColor="#color/red"
android:textSize="18dp"
android:textStyle="bold" />
</LinearLayout>
<Button
android:id="#+id/insertBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="#drawable/btn_background"
android:text="Place Your Order" />
</LinearLayout>
</LinearLayout>
DetailActivity.java
package com.example.juizeesapp;
import android.os.Bundle;
import android.os.PersistableBundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.example.juizeesapp.databinding.ActivityDetailBinding;
public class DetailActivity extends AppCompatActivity {
ActivityDetailBinding binding;
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityDetailBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
int image = getIntent().getIntExtra("image" , 0);
int price = Integer.parseInt(getIntent().getStringExtra("price"));
String name = getIntent().getStringExtra("name");
String description = getIntent().getStringExtra("desc");
binding.detailImage.setImageResource(image);
binding.priceLbl.setText(String.format("%d", price));
binding.nameBox.setText(name);
binding.detailDescription.setText(description);
}
}
you have not declared binding
ActivityDetailBinding binding;
It was a typo error in the manifest file. I stated .DetailActivity at the manifest file is;
<activity
android:name=".DetailActivity"
android:exported="false" />
But when I changed it into;
<activity android:name=".DetailActivity"></activity>
Problem solved.
Related
My activity does not sync with its layout xml. I really don't know why the coding seems okay. I'm a beginner dev.
This is my activity using Kotlin in Android Studio:
Code:
package com.pkndegwa.mycarmaintenance
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.work.Data
import androidx.work.ExistingWorkPolicy.REPLACE
import androidx.work.OneTimeWorkRequest
import androidx.work.WorkManager
import kotlinx.android.synthetic.service_list_item.*
import com.google.android.material.snackbar.Snackbar.LENGTH_LONG
import com.google.android.material.snackbar.Snackbar.make
import com.pkndegwa.mycarmaintenance.NotifyWork.Companion.NOTIFICATION_ID
import com.pkndegwa.mycarmaintenance.NotifyWork.Companion.NOTIFICATION_WORK
import java.lang.System.currentTimeMillis
import java.text.SimpleDateFormat
import java.util.*
import java.util.Locale.getDefault
import java.util.concurrent.TimeUnit.MILLISECONDS
class AlarmActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.service_list_item)
userInterface()
}
private fun userInterface() {
setSupportActionBar(toolbar)
val titleNotification = getString(R.string.notification_title)
done_fab.setOnClickListener {
val customCalendar = Calendar.getInstance()
customCalendar.set(
date_p.year, date_p.month, date_p.dayOfMonth, time_p.hour, time_p.minute, 0
)
val customTime = customCalendar.timeInMillis
val currentTime = currentTimeMillis()
if (customTime > currentTime) {
val data = Data.Builder().putInt(NOTIFICATION_ID, 0).build()
val delay = customTime - currentTime
scheduleNotification(delay, data)
val titleNotificationSchedule = getString(R.string.notification_schedule_title)
val patternNotificationSchedule = getString(R.string.notification_schedule_pattern)
make(
service_card,
titleNotificationSchedule + SimpleDateFormat(
patternNotificationSchedule, getDefault()
).format(customCalendar.time).toString(),
LENGTH_LONG
).show()
} else {
val errorNotificationSchedule = getString(R.string.notification_schedule_error)
make(service_card, errorNotificationSchedule, LENGTH_LONG).show()
}
}
}
private fun scheduleNotification(delay: Long, data: Data) {
val notificationWork = OneTimeWorkRequest.Builder(NotifyWork::class.java)
.setInitialDelay(delay, MILLISECONDS).setInputData(data).build()
val instanceWorkManager = WorkManager.getInstance(this)
instanceWorkManager.beginUniqueWork(NOTIFICATION_WORK, REPLACE, notificationWork).enqueue()
}
}
This is my layout.xml. This layout been use by two activity which is "ServiceListAdapter" and "AlarmActivity"
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView 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:id="#+id/service_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="8dp"
android:layout_marginVertical="4dp"
android:backgroundTint="#E9E9ED"
android:clickable="true"
android:focusable="true"
android:minHeight="#dimen/button_min_height"
app:cardElevation="1dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/services_heading_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_margin="12dp"
android:layout_weight="0"
android:importantForAccessibility="no"
android:src="#drawable/ic_baseline_build_circle_24" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/services"
android:textAllCaps="false"
android:textAppearance="?attr/textAppearanceBody2"
android:textColor="#color/black"
android:textSize="16sp" />
<TextView
android:id="#+id/services_done_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="false"
android:textSize="14sp"
tools:text="Oil Filer, Spark Plugs, Battery" />
</LinearLayout>
<ImageView
android:id="#+id/services_expand_view"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_margin="12dp"
android:layout_weight="0"
android:contentDescription="#string/expand_more_button"
android:src="#drawable/ic_baseline_expand_more_24" />
</LinearLayout>
<com.google.android.material.divider.MaterialDivider
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/services_details_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="6dp"
android:paddingTop="0dp"
android:paddingBottom="8dp"
android:visibility="gone"
app:layout_constraintEnd_toStartOf="#+id/services_left_layout"
app:layout_constraintStart_toStartOf="#+id/services_left_layout">
<LinearLayout
android:id="#+id/services_left_layout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="8dp"
android:orientation="vertical"
app:layout_constraintEnd_toStartOf="#id/services_right_layout"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/service_date"
android:textAppearance="?attr/textAppearanceBody2"
android:textColor="#color/black"
android:textSize="16sp" />
<TextView
android:id="#+id/service_date_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="false"
android:textSize="14sp"
tools:text="01 Nov 2022" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="#string/current_mileage"
android:textAppearance="?attr/textAppearanceBody2"
android:textColor="#color/black"
android:textSize="16sp" />
<TextView
android:id="#+id/current_mileage_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="false"
android:textSize="14sp"
tools:text="2,000 km" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="#string/next_service_mileage"
android:textAppearance="?attr/textAppearanceBody2"
android:textColor="#color/black"
android:textSize="16sp" />
<TextView
android:id="#+id/next_service_mileage_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="false"
android:textSize="14sp"
tools:text="4,000 km" />
</LinearLayout>
<LinearLayout
android:id="#+id/services_right_layout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="8dp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#id/services_left_layout"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/next_service_date"
android:textAppearance="?attr/textAppearanceBody2"
android:textColor="#color/black"
android:textSize="16sp" />
<TextView
android:id="#+id/next_service_date_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="false"
android:textSize="14sp"
tools:text="01 Mar 2023" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="#string/total_cost"
android:textAppearance="?attr/textAppearanceBody2"
android:textColor="#color/black"
android:textSize="16sp" />
<TextView
android:id="#+id/total_cost_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="false"
android:textSize="14sp"
tools:text="1,500 KSH" />
</LinearLayout>
<TextView
android:id="#+id/service_notes_title_text_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="24dp"
android:text="#string/notes"
android:textAppearance="?attr/textAppearanceBody2"
android:textColor="#color/black"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/services_left_layout" />
<TextView
android:id="#+id/service_notes_text_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:textAllCaps="false"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/service_notes_title_text_view"
tools:text="Testing out the notes appearance" />
<!-- This section is to create our alarm from different page since Examiner-->
<!-- want the user to separate the alarm from the add service -->
<EditText
android:id="#+id/titleET"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/service_notes_text_view"
android:hint="Title for your notification"
tools:context=".ui.AlarmActivity"
android:autofillHints="Which Car" />
<EditText
android:id="#+id/messageET"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="You can set your own notification here"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/titleET"
tools:context=".ui.AlarmActivity"
android:autofillHints="what service" />
<DatePicker
android:id="#+id/date_p"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="-30dp"
android:layout_marginRight="-30dp"
android:layout_weight="1"
android:calendarViewShown="false"
android:datePickerMode="spinner"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/messageET"
tools:context=".ui.AlarmActivity"/>
<TimePicker
android:id="#+id/time_p"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="-30dp"
android:layout_marginRight="-30dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:timePickerMode="spinner"
app:layout_constraintTop_toBottomOf="#id/date_p"
tools:context=".ui.AlarmActivity"/>
<Button
android:id="#+id/done_fab"
android:layout_marginTop="20dp"
android:layout_gravity="center"
android:text="schedule_notification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/time_p"
tools:context=".ui.AlarmActivity"/>
<LinearLayout
android:id="#+id/services_actions_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end|center_vertical"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/done_fab">
<Button
android:id="#+id/edit_service_button"
style="#style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="4dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="4dp"
android:padding="2dp"
android:text="#string/edit"
android:textAppearance="?attr/textAppearanceBody2"
android:textColor="#color/black"
app:drawableTopCompat="#drawable/ic_baseline_edit_24" />
<Button
android:id="#+id/delete_service_button"
style="#style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="2dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="4dp"
android:padding="2dp"
android:text="#string/delete"
android:textAppearance="?attr/textAppearanceBody2"
android:textColor="#color/black"
app:drawableTopCompat="#drawable/ic_baseline_delete_24" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
Before onCreate you need to initialize all widget
like
Button done_fab;//in JAVA
private lateinit var done_fab: Button //in Kotlin
//Add other here
and after setContentView you need to initialize the same widget with name like
done_fab=findViewById(R.id.done_fab);//in java
done_fab= findViewById(R.id.done_fab)//in Kotlin
//Add other here
it will be ready to use in overall activity class.
when I press the save button does not work after pressing it several time button is working sometimes first-time press is working sometimes after pressing moreover 10 times button is not working.Also i have toast messege to determine it is working or not the toast messege appear after pressing several time to the button.
binding.savebtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(Settringsactivity.this,"ok",Toast.LENGTH_LONG).show();
String status=binding.etStatus.getText().toString();
String username=binding.etUsername.getText().toString();
HashMap<String, Object> obj=new HashMap<>();
Toast.makeText(Settringsactivity.this,username,Toast.LENGTH_LONG).show();
obj.put("username",username);
obj.put("about",status);
if(name!=null) {
Toast.makeText(Settringsactivity.this,"Updated",Toast.LENGTH_LONG).show();
database.getReference().child("Users").child(name).updateChildren(obj);
}
}
});
Here is the xml code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="#+id/savebtn"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:background="#color/white"
android:foregroundTint="#B11B1B"
tools:context=".Settringsactivity">
<ImageView
android:id="#+id/settingsbackarraow"
android:layout_width="30dp"
android:layout_height="30dp"
android:backgroundTint="#FFFFFF"
app:srcCompat="#android:drawable/checkbox_on_background" />
<LinearLayout
android:id="#+id/flinear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/settingsbackarraow"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:gravity="center"
android:orientation="vertical">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/profileimage"
android:layout_width="120dp"
android:layout_height="120dp"
android:backgroundTint="#FFFFFF"
app:civ_border_color="#FF000000"
app:civ_border_width="2dp"
android:src="#drawable/img" />
<ImageView
android:id="#+id/plus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="#android:drawable/btn_plus" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username"
android:textColor="#100606" />
<EditText
android:id="#+id/etUsername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:textColor="#color/black"
android:hint="Enter your name"
android:inputType="textPersonName" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username"
android:textColor="#100606" />
<EditText
android:id="#+id/etStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="About"
android:textColor="#color/black"
android:inputType="textPersonName" />
</LinearLayout>
<Button
android:layout_width="100dp"
android:layout_height="50dp"
android:elevation="15sp"
android:background="#1966FB"
android:layout_gravity="right"
android:text="Save" />
</LinearLayout>
</RelativeLayout>
Here I am trying to take user input and display output in a Text View, but checkgen and checkuser is returning -1 despite of selecting them and also both the radio buttons are getting selected not any one of them, I want to display all the details entered in the text view. I have pasted the activity_reg.xml code below too
reg.java
package com.example.bloodbank;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
public class reg extends AppCompatActivity {
//login button
Button btn_login;
//firstname
EditText fn;
//lastname
EditText ln;
//phone number
EditText pn;
//output
TextView op;
//registration button
Button btn_reg;
//radio group for gender
RadioGroup rggen;
//radio group for user(donor/in search of blood)
RadioGroup rguser;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_reg);
btn_login=findViewById(R.id.btn_login);
fn=findViewById(R.id.txtfirstname);
ln=findViewById(R.id.txtlastname);
pn=findViewById(R.id.txtmobile);
op=findViewById(R.id.outputreg);
rggen=findViewById(R.id.rggender);
rguser=findViewById(R.id.rgreg);
btn_reg=findViewById(R.id.main_btn_reg);
btn_reg.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String fname=fn.getText().toString();
String lname=ln.getText().toString();
int pno= new Integer(pn.getText().toString());
int checkgen=rggen.getCheckedRadioButtonId();
//Toast.makeText(reg.this, "checkgen= "+checkgen, Toast.LENGTH_SHORT).show();
int checkuser=rguser.getCheckedRadioButtonId();
//Toast.makeText(reg.this, "checkuser= "+checkuser, Toast.LENGTH_SHORT).show();
if(((checkgen == -1)||(checkuser == -1))||((checkgen == -1)&&(checkuser == -1)))
{
//no radio button selected
Toast.makeText(reg.this, "Please select an option", Toast.LENGTH_SHORT).show();
}
else {
//radio button is checked
findRadioButton1(checkgen);
findRadioButton2(checkuser);
op.setText("Welcome " + fname + " " + lname + "Phone Number: " +pno );
}
}
});
btn_login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent i = new Intent(reg.this,login.class);
startActivity(i);
}
});
}
private void findRadioButton2(int checkuser) {
switch(checkuser){
case R.id.rbdonor:
op.setText("\nUser: Donor\n");
break;
case R.id.rbneedy:
op.setText("\nUser: In search of blood\n");
break;
}
}
private void findRadioButton1(int checkgen) {
switch(checkgen){
case R.id.rbmale:
op.setText("\nGender: Male\n");
break;
case R.id.rbfemale:
op.setText("\nGender: Female\n");
break;
}
}
}
activity_reg.xml
<?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:id="#+id/rbmale"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".reg">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="23dp"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/txtregister"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Registration"
android:textColor="#color/colorPrimaryDark"
android:textSize="20dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="10"
>
<EditText
android:id="#+id/txtfirstname"
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="First Name*"
android:paddingLeft="8dp"
android:paddingTop="15dp"
android:singleLine="true"
android:textColor="#color/colorPrimaryDark"
android:textColorHint="#color/colorPrimaryDark"
android:textSize="13dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="10"
>
<EditText
android:id="#+id/txtlastname"
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="Last Name*"
android:paddingLeft="8dp"
android:paddingTop="15dp"
android:singleLine="true"
android:textColor="#color/colorPrimaryDark"
android:textColorHint="#color/colorPrimaryDark"
android:textSize="13dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3"
>
<TextView
android:id="#+id/textView"
android:layout_width="90dp"
android:layout_height="30dp"
android:layout_weight="1"
android:text=" Gender*:"
android:textColor="#A31D13" />
<RadioGroup
android:id="#+id/rggender"
android:layout_width="309dp"
android:layout_height="match_parent"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<RadioButton
android:id="#+id/rbmale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Male"
android:textColor="#BE202F" />
<RadioButton
android:id="#+id/rbfemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Female"
android:textColor="#BE202F" />
</LinearLayout>
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="10"
>
<EditText
android:id="#+id/txtmobile"
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="Mobile Number*"
android:inputType="number"
android:maxLength="10"
android:paddingLeft="8dp"
android:paddingTop="15dp"
android:singleLine="true"
android:textColor="#color/colorPrimaryDark"
android:textColorHint="#color/colorPrimaryDark"
android:textSize="13dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="10"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal">
<EditText
android:id="#+id/txtpassword"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="1"
android:hint="Password*"
android:inputType="textPassword"
android:maxLength="10"
android:paddingLeft="8dp"
android:paddingTop="15dp"
android:singleLine="true"
android:textColor="#color/colorPrimaryDark"
android:textColorHint="#color/colorPrimaryDark"
android:textSize="13dp" />
</LinearLayout>
<TextView
android:id="#+id/textView2"
android:layout_width="111dp"
android:layout_height="30dp"
android:layout_marginTop="10dp"
android:text=" Register as*:"
android:textColor="#BE202F" />
<RadioGroup
android:id="#+id/rgreg"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/rbdonor"
android:layout_width="171dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="I am a donor"
android:textColor="#BE202F" />
<RadioButton
android:id="#+id/rbneedy"
android:layout_width="183dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="I am in search of blood"
android:textColor="#BE202F" />
</LinearLayout>
</RadioGroup>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginBottom="1dp"
android:orientation="horizontal">
</LinearLayout>
<Button
android:id="#+id/main_btn_reg"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginTop="20dp"
android:background="#color/colorPrimaryDark"
android:text="REGISTER"
android:textColor="#color/white"
android:textSize="14dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="0.6dp"
android:layout_marginTop="16dp"
android:background="#color/colorPrimaryDark"></View>
<Button
android:id="#+id/btn_login"
android:layout_width="86dp"
android:layout_height="44dp"
android:layout_marginTop="7dp"
android:gravity="center"
android:text="LOGIN"
android:textColor="#color/colorPrimaryDark"
android:textSize="14dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="10dp"
android:orientation="vertical"></LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/outputreg"
android:layout_width="match_parent"
android:layout_height="60dp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout> ```
How can I scroll in my Android app?
I already tried Scrollview but it doesn`t work.
So this is my MainActivity:
package com.example.myapplication2;
import android.content.DialogInterface;
import android.content.Intent;
import android.icu.text.IDNA;
import android.nfc.Tag;
import android.os.PersistableBundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import static com.example.myapplication2.R.id.*;
public class MainActivity extends AppCompatActivity implements BottomNavigationView.OnNavigationItemSelectedListener {
private boolean loadFragment(Fragment fragment){
if(fragment!=null){
getSupportFragmentManager()
.beginTransaction()
.replace(fragment_container, fragment)
.commit();
return true;
}
return false;
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BottomNavigationView navigation = findViewById(R.id.bottomnav);
navigation.setOnNavigationItemSelectedListener(this);
getSupportFragmentManager().beginTransaction().replace(fragment_container, new Home_Screen()).commit();
}
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem menuItem) {
Fragment fragment = null;
switch(menuItem.getItemId()){
case kontakt:
break;
case Termine:
fragment = new TermineFragment();
break;
case wilkommen:
fragment = new Home_Screen();
break;
}
return loadFragment(fragment);
}
}
And this is my XML file:
<?xml version="1.0" encoding="utf-8"?>
<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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#color/darkgrey">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Termine"
android:textSize="30sp"
android:textColor="#color/colorAccent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
></TextView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="173dp"
app:cardCornerRadius="8dp"
android:layout_marginTop="80dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
>
<Button
android:text="Mehr infos"
android:layout_width="120dp"
android:layout_height="35dp"
android:id="#+id/button1"
android:layout_weight="1"
android:layout_marginTop="130dp"
android:layout_marginRight="170dp"
/>
<LinearLayout android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="#color/maincolor"
>
</LinearLayout>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#color/white"
android:text="HPI - 29.06.19"
android:textSize="24dp"
/>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#color/white"
android:text="Sitzung: H-E.51"
android:textSize="16dp"
android:layout_marginTop="40dp"
/>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#color/white"
android:text="Juni22, 2019"
android:textSize="16dp"
android:layout_marginTop="40dp"
android:layout_marginRight="20dp"
android:layout_marginLeft="270dp"
/>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="173dp"
app:cardCornerRadius="8dp"
android:layout_marginTop="270dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
>
<LinearLayout android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="#color/colorPrimaryDark"
/>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#color/white"
android:text="HPI - 13.07.19"
android:textSize="24dp"
/>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#color/white"
android:text="Sitzung: H-E.51"
android:textSize="16dp"
android:layout_marginTop="40dp"
/>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#color/white"
android:text="July13, 2019"
android:textSize="16dp"
android:layout_marginTop="40dp"
android:layout_marginRight="20dp"
android:layout_marginLeft="270dp"
/>
</android.support.v7.widget.CardView>
</RelativeLayout>
What should I do? I want these Cardviews in my Scrollview.
Replace your XML layout code with the below. Also, be notified, there seems to be an awkward amount of topMargin between your two cards, not sure if that's intended or not but as of now, there is huge gap between your two cards :
<?xml version="1.0" encoding="utf-8"?>
<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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#color/darkgrey">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Termine"
android:textSize="30sp"
android:textColor="#color/colorAccent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="173dp"
app:cardCornerRadius="8dp"
android:layout_marginTop="80dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
>
<Button
android:text="Mehr infos"
android:layout_width="120dp"
android:layout_height="35dp"
android:id="#+id/button1"
android:layout_weight="1"
android:layout_marginTop="130dp"
android:layout_marginRight="170dp" />
<LinearLayout android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="#color/maincolor">
</LinearLayout>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#color/white"
android:text="HPI - 29.06.19"
android:textSize="24dp" />
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#color/white"
android:text="Sitzung: H-E.51"
android:textSize="16dp"
android:layout_marginTop="40dp"/>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#color/white"
android:text="Juni22, 2019"
android:textSize="16dp"
android:layout_marginTop="40dp"
android:layout_marginRight="20dp"
android:layout_marginLeft="270dp" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="173dp"
app:cardCornerRadius="8dp"
android:layout_marginTop="270dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
>
<LinearLayout android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="#color/colorPrimaryDark"
/>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#color/white"
android:text="HPI - 13.07.19"
android:textSize="24dp"
/>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#color/white"
android:text="Sitzung: H-E.51"
android:textSize="16dp"
android:layout_marginTop="40dp"
/>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#color/white"
android:text="July13, 2019"
android:textSize="16dp"
android:layout_marginTop="40dp"
android:layout_marginRight="20dp"
android:layout_marginLeft="270dp"
/>
</android.support.v7.widget.CardView>
</LinearLayout>
</ScrollView>
</RelativeLayout>
Use ScrollView in place of RelativeLayout. Add a LinearLayout with vertical orientation before the first TextView and close the LinearLayout after the CardView.
This question already has answers here:
Add positive button to Dialog
(3 answers)
Closed 5 years ago.
I am new in android app development. I am making a project in android-studio.I want to show pop up dialog whatever I have declared in xml file but OK button is not showing. If anyone knows about it, please share your answer.xml and java codes are below
image_layout.xml
<?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="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<!--<ImageView android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content" android:src="YOUR IMAGE"/>-->
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cardViewbluetooth"
app:cardCornerRadius="5dp"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:paddingTop="180dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Bluetooth not enabled"
android:textSize="20dp"
android:textStyle="bold"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Please enable bluetooth in settings and restart this application"
android:textStyle="bold"/>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="OK" android:onClick="dismissListener"/>
</LinearLayout>
</android.support.v7.widget.CardView></LinearLayout>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
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:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context="litifer.awesome.game.litifer_carddemo.MainActivity"
>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cardView1"
app:cardCornerRadius="5dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
app:cardElevation="0dp"
android:clickable="true"
app:cardBackgroundColor="#android:color/transparent"
android:background="#33FF0000"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/imageBeacon"
android:src="#drawable/beacon"
android:adjustViewBounds="true"
android:layout_gravity="center"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cardView1text"
android:text="Beacon Demo"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:textSize="20dp"
android:textStyle="bold"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cardView2"
app:cardCornerRadius="5dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
app:cardElevation="0dp"
android:clickable="true"
app:cardBackgroundColor="#android:color/transparent"
android:background="#33FF0000"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/imageWifi"
android:src="#drawable/wifi"
android:adjustViewBounds="true"
android:layout_gravity="center"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cardView2text"
android:text="Wifi Demo"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:textSize="20dp"
android:textStyle="bold"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cardView3"
app:cardCornerRadius="5dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
app:cardElevation="0dp"
android:clickable="true"
app:cardBackgroundColor="#android:color/transparent"
android:background="#33FF0000"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/imageCustomerReview"
android:src="#drawable/customerreview"
android:adjustViewBounds="true"
android:layout_gravity="center"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cardView3text"
android:text="CustomerReview Demo"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:textSize="20dp"
android:textStyle="bold"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cardView4"
app:cardCornerRadius="5dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
app:cardElevation="0dp"
android:clickable="true"
app:cardBackgroundColor="#android:color/transparent"
android:background="#33FF0000"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/imagecardview"
android:src="#drawable/cardview"
android:adjustViewBounds="true"
android:layout_gravity="center"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cardView4text"
android:text="CardView Demo"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:textSize="20dp"
android:textStyle="bold"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cardView5"
app:cardCornerRadius="5dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
app:cardElevation="0dp"
android:clickable="true"
app:cardBackgroundColor="#android:color/transparent"
android:background="#33FF0000"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/imagedemo"
android:src="#drawable/demo"
android:adjustViewBounds="true"
android:layout_gravity="center"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cardView5text"
android:text="Test All Demo"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:textSize="20dp"
android:textStyle="bold"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout> </ScrollView>
MainActivity.java
public class MainActivity extends AppCompatActivity {
private ImageView beacon,cardview,customerreview,demo,wifi;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
beacon = (ImageView)findViewById(R.id.imageBeacon);
beacon.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
// Device does not support Bluetooth
} else {
if (!mBluetoothAdapter.isEnabled()) {
// Bluetooth is not enable :)
Dialog settingsDialog = new Dialog(MainActivity.this);
settingsDialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
settingsDialog.setContentView(getLayoutInflater().inflate(R.layout.image_layout
, null));
settingsDialog.show();
}
}
}
});
}
}
try this
Dialog settingsDialog = new Dialog(this);
settingsDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
settingsDialog.setContentView(R.layout.image_layout);
settingsDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
settingsDialog.setCancelable(true);
settingsDialog.setTitle("Title...");
settingsDialog.show();