Android Studio Code in Java to take user input and display output - java

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> ```

Related

Why do I get a null object reference on my RealtiveLayout.setBackgroundColor although I have initialized it

Here is my java code:
package com.example.project_final;
import static android.content.ContentValues.TAG;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.firestore.DocumentReference;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.EventListener;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.FirebaseFirestoreException;
import java.util.ArrayList;
public class history extends AppCompatActivity {
FirebaseFirestore Fstore;
String userID;
FirebaseAuth fAuth ;
int times;
int heart;
int avg_heart;
String date;
int count = 0;
TextView Data;
RelativeLayout [] L = new RelativeLayout[7];
TextView [] hr = new TextView[7];
TextView [] dates = new TextView[7];
ImageView [] img = new ImageView[7];
TextView last;
ArrayList<Integer> intheart = new ArrayList<>();
ArrayList<String> intdates = new ArrayList<>();
TextView average;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
Fstore = FirebaseFirestore.getInstance();
fAuth = FirebaseAuth.getInstance();
userID= fAuth.getUid();
DocumentReference documentReference = Fstore.collection("users").document(userID);
Data = findViewById(R.id.txtNodata);
Intent intent1 = getIntent();
String signup = intent1.getStringExtra("signup");
last = findViewById(R.id.txtlast);
average = findViewById(R.id.txtaverage);
for(int i = 0; i<=6 ;i++) {
int resourceId = this.getResources().getIdentifier("layout"+ i+1, "id", this.getPackageName());
L[i] = findViewById(resourceId);
}
for(int i = 0; i<=6 ;i++) {
int resourceId = this.getResources().getIdentifier("heartrate"+ i+1, "id", this.getPackageName());
hr[i] = findViewById(resourceId);
}
for(int i = 0; i<=6 ;i++) {
int resourceId = this.getResources().getIdentifier("txtdate"+ i+1, "id", this.getPackageName());
dates[i] = findViewById(resourceId);
}
for(int i = 0; i<=6 ;i++) {
int resourceId = this.getResources().getIdentifier("img"+ i+1, "id", this.getPackageName());
img[i] = findViewById(resourceId);
}
documentReference.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
#Override
public void onComplete(#NonNull Task<DocumentSnapshot> task) {
times = Math.toIntExact(task.getResult().getLong("times"));
avg_heart = Math.toIntExact(task.getResult().getLong("average_heart_rate"));
for (int i = 0 ; i <times ;i++){
intdates.add(task.getResult().getString("date" + i));
intheart.add(Math.toIntExact(task.getResult().getLong("heart"+i)));
}
}
});
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
if(!(intheart.isEmpty()||intdates.isEmpty())){
int count =0;
if(times>7){
times=7;
}
last.setText("Last "+ times +" Days history");
for(int i =0 ; i<intdates.size();i++){
if(1.2*avg_heart<intheart.get(i)||0.8*avg_heart<intheart.get(i)){
L[i].setBackgroundColor(R.drawable.color_gradient1);
img[i].setImageResource(R.drawable.sad);
}
else{
L[i].setBackgroundColor(R.drawable.gradient_color);
img[i].setImageResource(R.drawable.happy);
}
dates[i].setText(intdates.get(i));
hr[i].setText(intheart.get(i)+" Bpm");
L[i].setVisibility(View.VISIBLE);
}
}
else{
handler.postDelayed(this, 100);
}
}
}, 100);
}
}
Here is my XML code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<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:padding="20dp"
android:orientation="vertical"
tools:context=".history">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/txtlast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text=""
android:textSize="30sp"
android:layout_gravity="center"
android:textColor="#000"
android:textStyle="bold"
/>
<TextView
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text=""
android:id="#+id/txtaverage"
android:textColor="#000"
android:layout_gravity="center"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="120dp"
app:cardCornerRadius="20dp"
android:layout_marginTop="20dp">
<RelativeLayout
android:id="#+id/layout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/gradient_color"
android:padding="10dp"
android:visibility="invisible"
>
<TextView
android:id="#+id/txtday1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Day 1"
android:textColor="#ffff"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/txtdate1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txtday1"
android:layout_marginTop="10dp"
android:textColor="#ffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txtdate1"
android:id="#+id/heartrate1"
android:layout_marginTop="10dp"
android:textColor="#ffff"
/>
<ImageView
android:id="#+id/img1"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_marginLeft="220dp"
/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="120dp"
app:cardCornerRadius="20dp"
android:layout_marginTop="20dp">
<RelativeLayout
android:id="#+id/layout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible"
android:background="#drawable/color_gradient1"
android:padding="10dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Day 2"
android:textColor="#ffff"
android:textSize="20sp"
android:textStyle="bold"
android:id="#+id/txtday2"
/>
<TextView
android:id="#+id/txtdate2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txtday2"
android:layout_marginTop="10dp"
android:textColor="#ffff" />
<TextView
android:id="#+id/heartrate2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txtdate2"
android:layout_marginTop="10dp"
android:textColor="#ffff" />
<ImageView
android:id="#+id/img2"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_marginLeft="220dp"
/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="120dp"
app:cardCornerRadius="20dp"
android:layout_marginTop="20dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/gradient_color"
android:id="#+id/layout3"
android:visibility="invisible"
android:padding="10dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Day 3"
android:textColor="#ffff"
android:textSize="20sp"
android:textStyle="bold"
android:id="#+id/txtday3"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txtday3"
android:textColor="#ffff"
android:layout_marginTop="10dp"
android:id="#+id/txtdate3"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txtdate3"
android:layout_marginTop="10dp"
android:textColor="#ffff"
android:id="#+id/heartrate3"
/>
<ImageView
android:id="#+id/img3"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_marginLeft="220dp"
/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="120dp"
app:cardCornerRadius="20dp"
android:layout_marginTop="20dp">
<RelativeLayout
android:id="#+id/layout4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/color_gradient1"
android:visibility="invisible"
android:padding="10dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Day 4"
android:textColor="#ffff"
android:textSize="20sp"
android:textStyle="bold"
android:id="#+id/txtday4"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txtday4"
android:textColor="#ffff"
android:layout_marginTop="10dp"
android:id="#+id/txtdate4"
/>
<TextView
android:id="#+id/heartrate4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txtdate4"
android:layout_marginTop="10dp"
android:textColor="#ffff" />
<ImageView
android:id="#+id/img4"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_marginLeft="220dp"
/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="120dp"
app:cardCornerRadius="20dp"
android:layout_marginTop="20dp">
<RelativeLayout
android:id="#+id/layout5"
android:visibility="invisible"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/gradient_color"
android:padding="10dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Day 1"
android:textColor="#ffff"
android:textSize="20sp"
android:textStyle="bold"
android:id="#+id/txtday5"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txtday5"
android:textColor="#ffff"
android:layout_marginTop="10dp"
android:id="#+id/txtdate5"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txtdate5"
android:layout_marginTop="10dp"
android:textColor="#ffff"
android:id="#+id/heartrate5"
/>
<ImageView
android:id="#+id/img5"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_marginLeft="220dp"
/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="120dp"
app:cardCornerRadius="20dp"
android:layout_marginTop="20dp">
<RelativeLayout
android:visibility="invisible"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/gradient_color"
android:id="#+id/layout6"
android:padding="10dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Day 6"
android:textColor="#ffff"
android:textSize="20sp"
android:textStyle="bold"
android:id="#+id/txtday6"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txtday6"
android:textColor="#ffff"
android:layout_marginTop="10dp"
android:id="#+id/txtdate6"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txtdate6"
android:id="#+id/heartrate6"
android:layout_marginTop="10dp"
android:textColor="#ffff"
/>
<ImageView
android:id="#+id/img6"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_marginLeft="220dp"
/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="120dp"
app:cardCornerRadius="20dp"
android:layout_marginTop="20dp">
<RelativeLayout
android:visibility="invisible"
android:id="#+id/layout7"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/gradient_color"
android:padding="10dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Day 7"
android:textColor="#ffff"
android:textSize="20sp"
android:textStyle="bold"
android:id="#+id/txtday7"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txtday7"
android:textColor="#ffff"
android:layout_marginTop="10dp"
android:id="#+id/txtdate7"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txtdate7"
android:layout_marginTop="10dp"
android:textColor="#ffff"
android:id="#+id/heartrate7"
/>
<ImageView
android:id="#+id/img7"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_marginLeft="220dp"
/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
<TextView
android:id="#+id/txtNodata"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_gravity="center"
android:fontFamily="#font/lovelo"
android:gravity="center"
android:text="No data Available"
android:textColor="#color/colorRed"
android:textSize="20sp"
android:visibility="invisible" />
</LinearLayout>
</ScrollView>
When I run the code I get this error on a null object reference when I try to setbackground color inside the handler:
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.RelativeLayout.setBackgroundColor(int)'
The code should run fine since I initialized all the views. I've been stuck for a while I don't know where is the problem help.
I think you are not getting the name correct, so it's not initializing it, name must be a string as a whole :
for(int i = 0; i<=6 ;i++) {
int resourceId = this.getResources().getIdentifier("layout" + (i+1).toString(), "id", this.getPackageName());
L[i] = findViewById(resourceId);
}

Cardview Click is not opening Activty

My problems :
no error in this project, i can run successful.
my button can click at a certain time.
when i click it back, it doesn't work at all.
i think my problem is near the parent.
What's my mistake in my project's parent?
Help me please.
Below is my Java file : Dashboard.java
package com.example.whatisthat;
import androidx.cardview.widget.CardView;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class Dashboard extends Activity implements View.OnClickListener
{
private CardView LoginBtn, CaptureBtn, AboutBtn, FeedbackBtn, IgBtn, HelpBtn;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashboard);
//DEFINE CARDS
//ADD CLICK LISTENER TO THE CARDS
LoginBtn = findViewById(R.id.Login);
LoginBtn.setOnClickListener(this);
CaptureBtn = findViewById(R.id.Capture);
CaptureBtn.setOnClickListener(this);
AboutBtn = findViewById(R.id.About);
AboutBtn.setOnClickListener(this);
FeedbackBtn = findViewById(R.id.Feedback);
FeedbackBtn.setOnClickListener(this);
IgBtn = findViewById(R.id.Ig);
IgBtn.setOnClickListener(this);
HelpBtn = findViewById(R.id.Help);
HelpBtn.setOnClickListener(this);
}
#Override
public void onClick(View view)
{
Intent i;
switch (view.getId())
{
case R.id.Login : i = new Intent(this,Login1.class);
startActivity(i);
break;
case R.id.Capture : i = new Intent(this, Capture.class);
startActivity(i);
break;
case R.id.About : i = new Intent(this, About.class);
startActivity(i);
break;
case R.id.Feedback : i = new Intent(this, Feedback.class);
startActivity(i);
break;
case R.id.Ig : i = new Intent(this, Instagram.class);
startActivity(i);
break;
case R.id.Help : i = new Intent(this, Help.class);
startActivity(i);
break;
default:break;
}
}
}
Below is my .xml file : activity_dashboard.xml
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Dashboard">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="230dp"
android:orientation="vertical"
android:gravity="center"
android:background="#6A287E">
<ImageView
android:layout_width="90dp"
android:layout_height="90dp"
android:src="#drawable/iconfyp"
android:layout_gravity="center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DASHBOARD"
android:textColor="#color/colorAccent"
android:layout_gravity="center"
android:textStyle="bold"
android:textSize="18sp"
android:layout_marginTop="10dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="215dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="135dp"
android:orientation="horizontal"
android:layout_marginBottom="10dp">
<androidx.cardview.widget.CardView
android:foreground="? android:attr/selectableItemBackground"
android:focusable="true"
android:clickable="true"
android:id="#+id/Login"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_marginRight="5dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="50dp"
android:id="#+id/imageView1"
android:layout_height="50dp"
android:src="#drawable/people"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LOGIN"
android:textSize="16sp"
android:layout_below="#+id/imageView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/buttonLogin"
android:background="#android:color/transparent"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:foreground="? android:attr/selectableItemBackground"
android:focusable="true"
android:clickable="true"
android:id="#+id/Capture"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_marginLeft="5dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="50dp"
android:id="#+id/imageView2"
android:layout_height="50dp"
android:src="#drawable/cameraa"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CAPTURE"
android:textSize="16sp"
android:layout_below="#+id/imageView2"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/buttonCapture"
android:background="#android:color/transparent"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="135dp"
android:orientation="horizontal"
android:layout_marginBottom="10dp">
<androidx.cardview.widget.CardView
android:foreground="? android:attr/selectableItemBackground"
android:focusable="true"
android:clickable="true"
android:id="#+id/About"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_marginRight="5dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="50dp"
android:id="#+id/imageView3"
android:layout_height="50dp"
android:src="#drawable/aboutt"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ABOUT"
android:textSize="16sp"
android:layout_below="#+id/imageView3"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/buttonAbout"
android:background="#android:color/transparent"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:foreground="? android:attr/selectableItemBackground"
android:focusable="true"
android:clickable="true"
android:id="#+id/Feedback"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_marginLeft="5dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="50dp"
android:id="#+id/imageView4"
android:layout_height="50dp"
android:src="#drawable/feedback"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FEEDBACK "
android:textSize="16sp"
android:layout_below="#+id/imageView4"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/buttonFeedback"
android:background="#android:color/transparent"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="135dp"
android:orientation="horizontal"
android:layout_marginBottom="10dp">
<androidx.cardview.widget.CardView
android:foreground="? android:attr/selectableItemBackground"
android:focusable="true"
android:clickable="true"
android:id="#+id/Ig"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_marginRight="5dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="50dp"
android:id="#+id/imageView5"
android:layout_height="50dp"
android:src="#drawable/instagram"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="INSTAGRAM"
android:textSize="16sp"
android:layout_below="#+id/imageView5"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/buttonIg"
android:background="#android:color/transparent"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:foreground="? android:attr/selectableItemBackground"
android:focusable="true"
android:clickable="true"
android:id="#+id/Help"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_marginLeft="5dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="50dp"
android:id="#+id/imageView6"
android:layout_height="50dp"
android:src="#drawable/help"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="HELP"
android:textSize="16sp"
android:layout_below="#+id/imageView6"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/buttonHelp"
android:background="#android:color/transparent"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
Well You have to First Remove space from this android:foreground="?android:attr/selectableItemBackground" and add this to all the button
android:clickable="false"
If you want to Open Activity With Button Then you have to put setOnClickListener to Button .Else if you want to open Activity with Cardview you have to put setOnClickListener to cardview.
Use this for OnClick Method:
#Override
public void onClick(View view) {
if (view==LoginBtn){
startActivity(new Intent(this,Login1.class));
}else if(view==Capture){
startActivity(new Intent(this,Capture.class));
}
//Do rest by yourself.
}

ScrollView isn`t working. What should I do?

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.

Showing null pointer exception even though no error is showing up [duplicate]

This question already has answers here:
What is a stack trace, and how can I use it to debug my application errors?
(7 answers)
Closed 4 years ago.
This is the code MainActivity.java file. I think there should be no mistake in this code. But it shows the message
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference.
I don't know why it is showing up there? Please help me to figure out.
package com.example.android.practiceset2;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.*;
import android.view.*;`
public class MainActivity extends AppCompatActivity {
int score=0,wickets=0;
String value=null,number=null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
Button b1=(Button)findViewById(R.id.b_i1);//b_i1 stands for increase in 1 run taken by team B and similarly other names are to the ids of different button.
Button b2=(Button)findViewById(R.id.b_i2);
Button b3=(Button)findViewById(R.id.b_i3);
Button b4=(Button)findViewById(R.id.b_i4);
Button b6=(Button)findViewById(R.id.b_i6);
Button bw=(Button)findViewById(R.id.b_w);
Button bwide=(Button)findViewById(R.id.b_wide);
Button a1=(Button)findViewById(R.id.a_i1);
Button a2=(Button)findViewById(R.id.a_i2);
Button a3=(Button)findViewById(R.id.a_i3);
Button a4=(Button)findViewById(R.id.a_i4);
Button a6=(Button)findViewById(R.id.a_i6);
Button aw=(Button)findViewById(R.id.a_w);
Button awide=(Button)findViewById(R.id.a_wide);
TextView ta= (TextView)findViewById(R.id.a);
TextView tb= (TextView)findViewById(R.id.b);
public void aorb(View view{
if(getResources().getResourceEntryName((view.getId())).startsWith("a"))
{ value="a";}
else{value="b";}
number=getResources().getResourceEntryName((view.getId())).substring(2);
score();}
public void a_enabled(Boolean b)
{
a1.setEnabled(b);
a2.setEnabled(b);
a3.setEnabled(b);
a4.setEnabled(b);
a6.setEnabled(b);
aw.setEnabled(b);
awide.setEnabled(b);
}
public void b_enabled(Boolean b)
{
b1.setEnabled(b);
b2.setEnabled(b);
b3.setEnabled(b);
b4.setEnabled(b);
b6.setEnabled(b);
bw.setEnabled(b);
bwide.setEnabled(b);
}
public void display(String s){
if(value.equals("a"))
{
ta.setText(s);
b_enabled(false);
a_enabled(true);
}
else {
tb.setText(s);
a_enabled(false);
b_enabled(true);
}
}
public void score(){
int i=0;
if(number.equals("i1"))
i=1;
if(number.equals("i2"))
i=2;
if(number.equals("i3"))
i=3;
if(number.equals("i4"))
i=4;
if(number.equals("i6"))
i=6;
if(number.equals("wide"))
i=1;
score+=i;
if(number.equals("w"))
wickets+=1;
if(wickets==10)//if a team loses all its 10 wickets , the score is finalised and next team is invited for play
{
display(score+"/"+wickets);
if(value.equals("a"))
{
value="b";
}
else{value="a";}
score=0;
wickets=0;
display(score+"/"+wickets);
}
display(score+"/"+wickets);
}
public void reset(View view){
ta.setText("0/0");
tb.setText("0/0");
a_enabled(true);
b_enabled(true);
}}
This is the code for my content_main.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"
android:orientation="horizontal"
android:background="#FFFFFF">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Team A"
android:textAlignment="center"
android:fontFamily="sans-serif-medium"
android:textSize="20sp"
android:textColor="#616161"
android:layout_margin="16dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:text="0/0"
android:textAlignment="center"
android:fontFamily="sans-serif-light"
android:textSize="56dp"
android:textColor="#000000"
android:id="#+id/a"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:onClick="aorb"
android:id="#+id/a_i1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:onClick="aorb"
android:id="#+id/a_i3"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6"
android:onClick="aorb"
android:id="#+id/a_i6"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:onClick="aorb"
android:id="#+id/a_i2"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"
android:onClick="aorb"
android:id="#+id/a_i4"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Out"
android:onClick="aorb"
android:id="#+id/a_w"
/>
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:layout_centerHorizontal="true"
android:text="Wide"
android:onClick="aorb"
android:id="#+id/a_wide"/>
</RelativeLayout>
</LinearLayout>
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#android:color/darker_gray"></View>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Team B"
android:textAlignment="center"
android:fontFamily="sans-serif-medium"
android:textSize="20sp"
android:textColor="#616161"
android:layout_margin="16dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:text="0/0"
android:textAlignment="center"
android:fontFamily="sans-serif-light"
android:textSize="56dp"
android:textColor="#000000"
android:id="#+id/b"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:onClick="aorb"
android:id="#+id/b_i1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:onClick="aorb"
android:id="#+id/b_i3"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6"
android:onClick="aorb"
android:id="#+id/b_i6"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:onClick="aorb"
android:id="#+id/b_i2"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"
android:onClick="aorb"
android:id="#+id/b_i4"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Out"
android:onClick="aorb"
android:id="#+id/b_w"
/>
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:layout_centerHorizontal="true"
android:text="Wide"
android:onClick="aorb"
android:id="#+id/b_wide"
/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reset"
android:textAlignment="center"
android:layout_centerHorizontal="true"
android:onClick="reset"
android:layout_marginBottom="32dp"
/>
</RelativeLayout>
Here is the image of it should look like it is the screenshot the preview
All these findViewById must be included in your onCreate() method. You can keep the declarations out of onCreate(). Your views do not exist before setContentView(R.layout.activity_main);
I mean before onCreate() you can have Button b1;
and after setContentView(R.layout.activity_main); in onCreate() you must have b1=(Button)findViewById(R.id.b_i1);
for every view.
I have made the corrections in your and now the app is not crashing. Try using the below code snippet
MainActivity
public class MainActivity extends AppCompatActivity {
int score = 0, wickets = 0;
String value = null, number = null;
Button b1;
Button b2;
Button b3;
Button b4;
Button b6;
Button bw;
Button bwide;
Button a1;
Button a2;
Button a3;
Button a4;
Button a6;
Button aw;
Button awide;
TextView ta;
TextView tb;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_main);
b1 = (Button) findViewById(R.id.b_i1);//b_i1 stands for increase in 1 run taken by team B and similarly other names are to the ids of different button.
b2 = (Button) findViewById(R.id.b_i2);
b3 = (Button) findViewById(R.id.b_i3);
b4 = (Button) findViewById(R.id.b_i4);
b6 = (Button) findViewById(R.id.b_i6);
bw = (Button) findViewById(R.id.b_w);
bwide = (Button) findViewById(R.id.b_wide);
a1 = (Button) findViewById(R.id.a_i1);
a2 = (Button) findViewById(R.id.a_i2);
a3 = (Button) findViewById(R.id.a_i3);
a4 = (Button) findViewById(R.id.a_i4);
a6 = (Button) findViewById(R.id.a_i6);
aw = (Button) findViewById(R.id.a_w);
awide = (Button) findViewById(R.id.a_wide);
ta = (TextView) findViewById(R.id.a);
tb = (TextView) findViewById(R.id.b);
}
public void aorb(View view) {
if (getResources().getResourceEntryName((view.getId())).startsWith("a")) {
value = "a";
} else {
value = "b";
}
number = getResources().getResourceEntryName((view.getId())).substring(2);
score();
}
public void a_enabled(Boolean b) {
a1.setEnabled(b);
a2.setEnabled(b);
a3.setEnabled(b);
a4.setEnabled(b);
a6.setEnabled(b);
aw.setEnabled(b);
awide.setEnabled(b);
}
public void b_enabled(Boolean b) {
b1.setEnabled(b);
b2.setEnabled(b);
b3.setEnabled(b);
b4.setEnabled(b);
b6.setEnabled(b);
bw.setEnabled(b);
bwide.setEnabled(b);
}
public void display(String s) {
if (value.equals("a")) {
ta.setText(s);
b_enabled(false);
a_enabled(true);
} else {
tb.setText(s);
a_enabled(false);
b_enabled(true);
}
}
public void score() {
int i = 0;
if (number.equals("i1"))
i = 1;
if (number.equals("i2"))
i = 2;
if (number.equals("i3"))
i = 3;
if (number.equals("i4"))
i = 4;
if (number.equals("i6"))
i = 6;
if (number.equals("wide"))
i = 1;
score += i;
if (number.equals("w"))
wickets += 1;
if (wickets == 10)//if a team loses all its 10 wickets , the score is finalised and next team is invited for play
{
display(score + "/" + wickets);
if (value.equals("a")) {
value = "b";
} else {
value = "a";
}
score = 0;
wickets = 0;
display(score + "/" + wickets);
}
display(score + "/" + wickets);
}
public void reset(View view) {
ta.setText("0/0");
tb.setText("0/0");
a_enabled(true);
b_enabled(true);
}
}
content_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:fontFamily="sans-serif-medium"
android:text="Team A"
android:textAlignment="center"
android:textColor="#616161"
android:textSize="20sp" />
<TextView
android:id="#+id/a"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:fontFamily="sans-serif-light"
android:text="0/0"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="56dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
android:layout_weight="1"
android:orientation="vertical">
<Button
android:id="#+id/a_i1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="aorb"
android:text="1" />
<Button
android:id="#+id/a_i3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="aorb"
android:text="3" />
<Button
android:id="#+id/a_i6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="aorb"
android:text="6" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
android:layout_weight="1"
android:orientation="vertical">
<Button
android:id="#+id/a_i2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="aorb"
android:text="2" />
<Button
android:id="#+id/a_i4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="aorb"
android:text="4" />
<Button
android:id="#+id/a_w"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="aorb"
android:text="Out" />
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/a_wide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:onClick="aorb"
android:text="Wide"
android:textAlignment="center" />
</RelativeLayout>
</LinearLayout>
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#android:color/darker_gray"></View>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:fontFamily="sans-serif-medium"
android:text="Team B"
android:textAlignment="center"
android:textColor="#616161"
android:textSize="20sp" />
<TextView
android:id="#+id/b"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:fontFamily="sans-serif-light"
android:text="0/0"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="56dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
android:layout_weight="1"
android:orientation="vertical">
<Button
android:id="#+id/b_i1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="aorb"
android:text="1" />
<Button
android:id="#+id/b_i3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="aorb"
android:text="3" />
<Button
android:id="#+id/b_i6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="aorb"
android:text="6" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
android:layout_weight="1"
android:orientation="vertical">
<Button
android:id="#+id/b_i2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="aorb"
android:text="2" />
<Button
android:id="#+id/b_i4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="aorb"
android:text="4" />
<Button
android:id="#+id/b_w"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="aorb"
android:text="Out" />
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/b_wide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:onClick="aorb"
android:text="Wide"
android:textAlignment="center" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="32dp"
android:onClick="reset"
android:text="Reset"
android:textAlignment="center" />
</RelativeLayout>
</RelativeLayout>
Hope this helps.

Not displaying OK button in cardview in pop up dialog [duplicate]

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();

Categories

Resources