I am very new to coding so there could be all sorts of issues with this but after doing a fair bit of searching, I can't find whats wrong with it, I don't get any errors or crashes, the buttons just do nothing?
The aim is to have the orange arrows increase and decrease the number in the middle by 1.
App Screenshot:
I don't know what code to show you so here is most of it:
T3_TrampetFragment.java
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class T3_TrampetFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.t3_trampetlayout, container, false);
}
}
t3_trampetlayout.xml
<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="wrap_content"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".T3_TrampetFragment">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:id="#+id/tblrow_title"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/txt_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="Tariff Calculator"
android:textAlignment="center"
android:textColor="#color/colorPrimaryDark"
android:textSize="36sp"
android:textStyle="bold" />
</TableRow>
<TableRow
android:id="#+id/tblrow_rotations"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="10dp"
android:paddingTop="10dp">
<TextView
android:id="#+id/txt_rotations"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="Rotations"
android:textAlignment="center"
android:textColor="#color/colorPrimary"
android:textSize="24sp" />
<ImageButton
android:id="#+id/btn_r_minus"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:backgroundTint="?android:attr/colorBackground"
android:clickable="true"
android:foreground="#android:drawable/ic_media_play"
android:foregroundTint="#color/colorSecondary"
android:hapticFeedbackEnabled="true"
android:rotation="180" />
<Space
android:layout_width="10dp"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/Rnum"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:background="?android:attr/colorBackground"
android:focusable="false"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="#string/sRnum"
android:textAlignment="center"
android:textColor="?attr/colorControlNormal"
android:textSize="24sp"
android:textStyle="bold" />
<Space
android:layout_width="10dp"
android:layout_height="wrap_content" />
<ImageButton
android:id="#+id/btn_r_plus"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:backgroundTint="?android:attr/colorBackground"
android:clickable="true"
android:foreground="#android:drawable/ic_media_play"
android:foregroundTint="#color/colorSecondary"
android:hapticFeedbackEnabled="true" />
<Space
android:layout_width="20dp"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:id="#+id/tblrow_pike"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="10dp"
android:paddingTop="10dp">
<TextView
android:id="#+id/txt_pike"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="Pike Bonus"
android:textAlignment="center"
android:textColor="#color/colorPrimary"
android:textSize="24sp" />
<ImageButton
android:id="#+id/btn_p_minus"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:backgroundTint="?android:attr/colorBackground"
android:clickable="true"
android:foreground="#android:drawable/ic_media_play"
android:foregroundTint="#color/colorSecondary"
android:hapticFeedbackEnabled="true"
android:rotation="180" />
<Space
android:layout_width="10dp"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/Pnum"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:background="?android:attr/colorBackground"
android:focusable="false"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="#string/sPnum"
android:textAlignment="center"
android:textColor="?attr/colorControlNormal"
android:textSize="24sp"
android:textStyle="bold" />
<Space
android:layout_width="10dp"
android:layout_height="wrap_content" />
<ImageButton
android:id="#+id/btn_p_plus"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:backgroundTint="?android:attr/colorBackground"
android:clickable="true"
android:foreground="#android:drawable/ic_media_play"
android:foregroundTint="#color/colorSecondary"
android:hapticFeedbackEnabled="true" />
<Space
android:layout_width="20dp"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:id="#+id/tblrow_straight"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="10dp"
android:paddingTop="10dp">
<TextView
android:id="#+id/txt_straight"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="Straight Bonus"
android:textAlignment="center"
android:textColor="#color/colorPrimary"
android:textSize="24sp" />
<ImageButton
android:id="#+id/btn_s_minus"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:backgroundTint="?android:attr/colorBackground"
android:clickable="true"
android:foreground="#android:drawable/ic_media_play"
android:foregroundTint="#color/colorSecondary"
android:hapticFeedbackEnabled="true"
android:rotation="180" />
<Space
android:layout_width="10dp"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/Snum"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:background="?android:attr/colorBackground"
android:focusable="false"
android:inputType="number"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="#string/sSnum"
android:textAlignment="center"
android:textColor="?attr/colorControlNormal"
android:textSize="24sp"
android:textStyle="bold" />
<Space
android:layout_width="10dp"
android:layout_height="wrap_content" />
<ImageButton
android:id="#+id/btn_s_plus"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:backgroundTint="?android:attr/colorBackground"
android:clickable="true"
android:foreground="#android:drawable/ic_media_play"
android:foregroundTint="#color/colorSecondary"
android:hapticFeedbackEnabled="true" />
<Space
android:layout_width="20dp"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:id="#+id/tblrow_twist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="10dp"
android:paddingTop="10dp">
<TextView
android:id="#+id/txt_twist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="Twists"
android:textAlignment="center"
android:textColor="#color/colorPrimary"
android:textSize="24sp" />
<ImageButton
android:id="#+id/btn_t_minus"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:backgroundTint="?android:attr/colorBackground"
android:clickable="true"
android:foreground="#android:drawable/ic_media_play"
android:foregroundTint="#color/colorSecondary"
android:hapticFeedbackEnabled="true"
android:rotation="180" />
<Space
android:layout_width="10dp"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/Tnum"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:background="?android:attr/colorBackground"
android:focusable="false"
android:inputType="numberDecimal"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="#string/sTnum"
android:textAlignment="center"
android:textColor="?attr/colorControlNormal"
android:textSize="24sp"
android:textStyle="bold" />
<Space
android:layout_width="10dp"
android:layout_height="wrap_content" />
<ImageButton
android:id="#+id/btn_t_plus"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:backgroundTint="?android:attr/colorBackground"
android:clickable="true"
android:foreground="#android:drawable/ic_media_play"
android:foregroundTint="#color/colorSecondary"
android:hapticFeedbackEnabled="true" />
<Space
android:layout_width="20dp"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:id="#+id/tblrow_result"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="20dp"
android:paddingTop="20dp">
<TextView
android:id="#+id/txt_result"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="Difficulty"
android:textAlignment="center"
android:textColor="#color/colorPrimary"
android:textSize="24sp"
android:textStyle="bold" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/_space"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:rotation="180"
android:visibility="invisible"
app:backgroundTint="#color/colorSecondary"
app:fabSize="mini"
app:srcCompat="#android:drawable/ic_media_play" />
<Space
android:layout_width="0dp"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/Resultnum"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:background="?android:attr/colorBackground"
android:focusable="false"
android:inputType="numberDecimal"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="#string/sResultnum"
android:textAlignment="center"
android:textColor="?attr/colorControlNormal"
android:textSize="24sp"
android:textStyle="bold" />
<Space
android:layout_width="0dp"
android:layout_height="wrap_content" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/_space2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:visibility="invisible"
app:backgroundTint="#color/colorSecondary"
app:fabSize="mini"
app:srcCompat="#android:drawable/ic_media_play" />
<Space
android:layout_width="20dp"
android:layout_height="wrap_content" />
</TableRow>
</TableLayout>
</RelativeLayout>
T3_TrampetActivity.java
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.EditText;
public class T3_TrampetActivity extends Activity implements View.OnClickListener {
ImageButton BtnRMinus, BtnRPlus, BtnPMinus, BtnPPlus, BtnSMinus, BtnSPlus, BtnTMinus, BtnTPlus;
EditText R_num, P_num, S_num, T_num, Result_num;
int R_counter = (1);
int P_counter, S_counter = (0);
double T_counter = (0.0);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.t3_trampetlayout);
R_num = (EditText) findViewById(R.id.Rnum);
P_num = (EditText) findViewById(R.id.Pnum);
S_num = (EditText) findViewById(R.id.Snum);
T_num = (EditText) findViewById(R.id.Tnum);
Result_num = (EditText) findViewById(R.id.Resultnum);
BtnRMinus = (ImageButton) findViewById(R.id.btn_r_minus);
BtnRPlus = (ImageButton) findViewById(R.id.btn_r_plus);
BtnPMinus = (ImageButton) findViewById(R.id.btn_p_minus);
BtnPPlus = (ImageButton) findViewById(R.id.btn_p_plus);
BtnSMinus = (ImageButton) findViewById(R.id.btn_s_minus);
BtnSPlus = (ImageButton) findViewById(R.id.btn_s_plus);
BtnTMinus = (ImageButton) findViewById(R.id.btn_t_minus);
BtnTPlus = (ImageButton) findViewById(R.id.btn_t_plus);
BtnRMinus.setOnClickListener(this);
BtnRPlus.setOnClickListener(this);
BtnPMinus.setOnClickListener(this);
BtnPPlus.setOnClickListener(this);
BtnSMinus.setOnClickListener(this);
BtnSPlus.setOnClickListener(this);
BtnTMinus.setOnClickListener(this);
BtnTPlus.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_r_minus:
if (R_counter > 1) {
--R_counter;
R_num.setText(String.valueOf(R_counter));
}
break;
case R.id.btn_r_plus:
if (R_counter < 3) {
++R_counter;
R_num.setText(String.valueOf(R_counter));
}
break;
case R.id.btn_p_minus:
if (P_counter > 0) {
--P_counter;
P_num.setText(String.valueOf(P_counter));
}
break;
case R.id.btn_p_plus:
if (P_counter < 3) {
++P_counter;
P_num.setText(String.valueOf(P_counter));
}
break;
case R.id.btn_s_minus:
if (S_counter > 0) {
--S_counter;
S_num.setText(String.valueOf(S_counter));
}
break;
case R.id.btn_s_plus:
if (S_counter < 3) {
++S_counter;
S_num.setText(String.valueOf(S_counter));
}
break;
case R.id.btn_t_minus:
if (T_counter > 0) {
T_counter = (T_counter - 0.5);
T_num.setText(String.valueOf(T_counter));
}
break;
case R.id.btn_t_plus:
if (T_counter < 5.5) {
T_counter = (T_counter + 0.5);
T_num.setText(String.valueOf(T_counter));
}
break;
default:
break;
}
}
}
strings.xml
<resources>
<string name="app_name">TG Mobile</string>
<string name="in_app_name">TeamGym Mobile</string>
<string name="sRnum">1</string>
<string name="sPnum">0</string>
<string name="sSnum">0</string>
<string name="sTnum">0.0</string>
<string name="sResultnum">0.00</string>
</resources>
Create T3_TrampetActivity like this And Call Your Fragment from Activity:
public class T3_TrampetActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Fragment fragment = new T3_TrampetFragment();
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_frame, fragment, fragment.getClass().getSimpleName()).addToBackStack(null).commit();
}
}
Create activity_main.xml as like this:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fragment_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Update T3_TrampetFragment.java
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class T3_TrampetFragment extends Fragment implements View.OnClickListener {
ImageButton BtnRMinus, BtnRPlus, BtnPMinus, BtnPPlus, BtnSMinus, BtnSPlus, BtnTMinus, BtnTPlus;
EditText R_num, P_num, S_num, T_num, Result_num;
int R_counter = (1);
int P_counter, S_counter = (0);
double T_counter = (0.0);
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.t3_trampetlayout, container, false);
R_num = (EditText) view.findViewById(R.id.Rnum);
P_num = (EditText) view.findViewById(R.id.Pnum);
S_num = (EditText) view.findViewById(R.id.Snum);
T_num = (EditText) view.findViewById(R.id.Tnum);
Result_num = (EditText) view.findViewById(R.id.Resultnum);
BtnRMinus = (ImageButton) view.findViewById(R.id.btn_r_minus);
BtnRPlus = (ImageButton)view.findViewById(R.id.btn_r_plus);
BtnPMinus = (ImageButton) view.findViewById(R.id.btn_p_minus);
BtnPPlus = (ImageButton) view.findViewById(R.id.btn_p_plus);
BtnSMinus = (ImageButton) view.findViewById(R.id.btn_s_minus);
BtnSPlus = (ImageButton) view.findViewById(R.id.btn_s_plus);
BtnTMinus = (ImageButton) view.findViewById(R.id.btn_t_minus);
BtnTPlus = (ImageButton) view.findViewById(R.id.btn_t_plus);
BtnRMinus.setOnClickListener(this);
BtnRPlus.setOnClickListener(this);
BtnPMinus.setOnClickListener(this);
BtnPPlus.setOnClickListener(this);
BtnSMinus.setOnClickListener(this);
BtnSPlus.setOnClickListener(this);
BtnTMinus.setOnClickListener(this);
BtnTPlus.setOnClickListener(this);
return view;
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_r_minus:
if (R_counter > 1) {
--R_counter;
R_num.setText(String.valueOf(R_counter));
}
break;
case R.id.btn_r_plus:
if (R_counter < 3) {
++R_counter;
R_num.setText(String.valueOf(R_counter));
}
break;
case R.id.btn_p_minus:
if (P_counter > 0) {
--P_counter;
P_num.setText(String.valueOf(P_counter));
}
break;
case R.id.btn_p_plus:
if (P_counter < 3) {
++P_counter;
P_num.setText(String.valueOf(P_counter));
}
break;
case R.id.btn_s_minus:
if (S_counter > 0) {
--S_counter;
S_num.setText(String.valueOf(S_counter));
}
break;
case R.id.btn_s_plus:
if (S_counter < 3) {
++S_counter;
S_num.setText(String.valueOf(S_counter));
}
break;
case R.id.btn_t_minus:
if (T_counter > 0) {
T_counter = (T_counter - 0.5);
T_num.setText(String.valueOf(T_counter));
}
break;
case R.id.btn_t_plus:
if (T_counter < 5.5) {
T_counter = (T_counter + 0.5);
T_num.setText(String.valueOf(T_counter));
}
break;
default:
break;
}
}
}
t3_trampetlayout.xml Use same layou for Fragment.
Related
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);
}
java
there is problem in total.I have already tried try and catch.It always
show 0 at t17.looks like it does not set the total value.
It does not total the value given by total=i1+i2+i3+i4+i5;
t17.setText(String.valueOf(total));it always show 0 at t17
package com.example.myproject1;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
public class Bill extends AppCompatActivity {
TextView t,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17;
Button b,b1;
int total;
int i1,i2,i3,i4,i5;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bill);
t=findViewById(R.id.textView);
t1=findViewById(R.id.textView5);
t2=findViewById(R.id.textView10);
t3=findViewById(R.id.textView15);
t4=findViewById(R.id.textView6);
t5=findViewById(R.id.textView11);
t6=findViewById(R.id.textView16);
t7=findViewById(R.id.textView7);
t8=findViewById(R.id.textView12);
t9=findViewById(R.id.textView17);
t10=findViewById(R.id.textView8);
t11=findViewById(R.id.textView13);
t12=findViewById(R.id.textView18);
t13=findViewById(R.id.textView9);
t14=findViewById(R.id.textView14);
t15=findViewById(R.id.textView19);
t16=findViewById(R.id.textView20);
t17=findViewById(R.id.textView21);
b=findViewById(R.id.button22);
b1=findViewById(R.id.button23);
Intent obj2 = getIntent();
String r = obj2.getStringExtra("k");
t.setText(r);
String res = obj2.getStringExtra("key");
String res1 = obj2.getStringExtra("key2");
String res2 = obj2.getStringExtra("key3");
String res3 = obj2.getStringExtra("key4");
String res4 = obj2.getStringExtra("key5");
String res5 = obj2.getStringExtra("key6");
String res6 = obj2.getStringExtra("key7");
String res7 = obj2.getStringExtra("key8");
String res8 = obj2.getStringExtra("key9");
String res9 = obj2.getStringExtra("key10");
String res10 = obj2.getStringExtra("key11");
String res11 = obj2.getStringExtra("key12");
String res12 = obj2.getStringExtra("key13");
String res13 = obj2.getStringExtra("key14");
String res14 = obj2.getStringExtra("key15");
t1.setText(res);
t2.setText(res1);
t3.setText(res2);
t4.setText(res3);
t5.setText(res4);
t6.setText(res5);
t7.setText(res6);
t8.setText(res7);
t9.setText(res8);
t10.setText(res9);
t11.setText(res10);
t12.setText(res11);
t13.setText(res12);
t14.setText(res13);
t15.setText(res14);
try{
if (res2 != null) {
i1 = Integer.parseInt(res2);
} else {
i1 = 0;
}
if (res5 != null) {
i2 = Integer.parseInt(res5);
} else {
i2 = 0;
}
if (res8 != null) {
i3 = Integer.parseInt(res8);
} else {
i3 = 0;
}
if (res11 != null) {
i4 = Integer.parseInt(res11);
} else {
i4 = 0;
}
if (res14 != null) {
i5 = Integer.parseInt(res14);
} else {
i5 = 0;
}
}catch (NumberFormatException e){
}
t16.setText("Total Price:");
total=i1+i2+i3+i4+i5;
t17.setText(String.valueOf(total));
b.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent obj = new Intent(Bill.this, Menu.class);
startActivity(obj);
}
});
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent obj1 = new Intent(Bill.this, MainActivity.class);
startActivity(obj1);
}
});
}
}
XML
the xml of my code is given as below though it has nothing to do with
my coding part.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/bill4"
tools:context=".Bill">
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="224dp"
android:layout_marginTop="5dp"
android:background="#92278F"
android:gravity="center"
android:text="user"
android:textColor="#0066FF"
android:textSize="24sp"
android:textStyle="bold"
app:fontFamily="#font/merienda_one"
tools:layout_editor_absoluteX="161dp"
tools:layout_editor_absoluteY="64dp" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="#CD81DB"
android:fontFamily="#font/joti_one"
android:text="Bill"
android:textColor="#111111"
android:textSize="#android:dimen/app_icon_size"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="18dp"
android:layout_marginTop="60dp"
android:background="#92278F"
android:gravity="center"
android:paddingLeft="25dp"
android:paddingRight="25dp"
android:text="Item"
android:textColor="#0066FF"
android:textSize="24dp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="13dp"
android:layout_marginTop="60dp"
android:background="#92278F"
android:gravity="center"
android:paddingLeft="25dp"
android:paddingRight="25dp"
android:text="Quantity"
android:textColor="#0066FF"
android:textSize="24dp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="60dp"
android:background="#92278F"
android:gravity="center"
android:paddingLeft="25dp"
android:paddingRight="25dp"
android:text="Price"
android:textColor="#0066FF"
android:textSize="24dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="18dp"
android:orientation="vertical">
<TextView
android:id="#+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#111111"
android:layout_marginTop="10dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textView6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#111111"
android:layout_marginTop="10dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textView7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#111111"
android:layout_marginTop="10dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textView8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#111111"
android:layout_marginTop="10dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textView9"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#111111"
android:layout_marginTop="10dp"
android:textStyle="bold"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="80dp"
android:orientation="vertical">
<TextView
android:id="#+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#111111"
android:layout_marginTop="10dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textView11"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#111111"
android:layout_marginTop="10dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textView12"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#111111"
android:layout_marginTop="10dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textView13"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#111111"
android:layout_marginTop="10dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textView14"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#111111"
android:layout_marginTop="10dp"
android:textStyle="bold"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="120dp"
android:orientation="vertical">
<TextView
android:id="#+id/textView15"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#111111"
android:layout_marginTop="10dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textView16"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#111111"
android:layout_marginTop="10dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textView17"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#111111"
android:layout_marginTop="10dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textView18"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#111111"
android:layout_marginTop="10dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textView19"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#111111"
android:layout_marginTop="10dp"
android:textStyle="bold"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/textView20"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="20dp"
android:textColor="#111111"
android:text=""
android:textSize="14dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textView21"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="200dp"
android:layout_marginTop="20dp"
android:textColor="#111111"
android:textSize="14dp"
android:textStyle="bold"
android:text="" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/button22"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="20dp"
android:background="#92278F"
android:textColor="#0066FF"
android:textStyle="bold"
app:fontFamily="#font/merienda_one"
android:text="Cancel" />
<Button
android:id="#+id/button23"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="165dp"
android:layout_marginTop="20dp"
android:background="#92278F"
android:textColor="#0066FF"
android:textStyle="bold"
app:fontFamily="#font/merienda_one"
android:text="Order" />
</LinearLayout>
</LinearLayout>
I have used Sharedpreferences instead of intent however it is possible
from both.
Data recieving class
public class class_name extends AppCompatActivity {
SharedPreferences sharedPref;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bill);
sharedPref=this.getSharedPreferences("calis",Context.MODE_PRIVATE);
String res = sharedPref.getString("k1",null);
String res1 = sharedPref.getString("k2",null);
String res2 = sharedPref.getString("k3",null);
Integer res15 = sharedPref.getInt("k4",0);
Integer vres15 = sharedPref.getInt("k5",0);
int total2 = res15+vres15;
t17.setText(String.valueOf(total2));
}
}
Data sending class
public class class_name2 extends Fragment {
SharedPreferences sp;
sp=this.getActivity().getSharedPreferences("calis", Context.MODE_PRIVATE);
SharedPreferences.Editor editor=sp.edit();
editor.putString("k1",value1);
editor.putInt("k4", value2);
editor.commit();
}
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.
I have an activity which is not parent in that I want to call a fragment in that activity on click of an image view. So I have added onclickListner on my image view. I am getting toast on click of image view but the fragment is not getting called. What can be the issue?? Can anyone help please..
GoSend activity layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:fitsSystemWindows="true"
android:id="#+id/LinearLayoutGoSend">
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/LinearContainer">
<ScrollView
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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:layout_marginRight="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/DriversNear"
android:id="#+id/textView10"
android:layout_marginStart="20dp"
android:layout_marginTop="10dp" />
<fragment android:layout_width="match_parent"
android:layout_height="250dp"
android:id="#+id/map"
tools:context=".GoSend"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_marginTop="10dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1.00"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/From"
android:id="#+id/textView11"
android:layout_marginStart="20dp"
android:layout_marginTop="10dp" />
<ImageView
android:layout_width="match_parent"
android:layout_height="08dp"
android:id="#+id/imageView11"
android:background="#drawable/line2"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView10"
android:layout_marginStart="20dp"
android:background="#drawable/ic_place_black_48dp"
android:layout_marginTop="05dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editText_from"
android:text="#string/Loc"
android:visibility="visible"
android:drawableEnd="#drawable/ic_chevron_right_black_24dp"
android:layout_marginEnd="10dp"
android:cursorVisible="false"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView12"
android:layout_marginStart="20dp"
android:background="#drawable/ic_description_black_48dp"
android:layout_marginTop="05dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editText_from_details"
android:layout_marginEnd="10dp"
android:hint="Location details"
android:cursorVisible="true"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView12"
android:layout_marginStart="48dp"
android:hint="House no./Floor/Landmark" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/LinearLayoutAdditionalContactFrom">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView13"
android:layout_marginStart="20dp"
android:background="#drawable/ic_person_black_48dp"
android:layout_marginTop="05dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/contactDetailsFrom"
android:layout_marginEnd="10dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:drawableEnd="#drawable/ic_expand_more_black_24dp"
android:text="#string/additionalContact"
android:layout_gravity="center_vertical"
android:layout_marginTop="05dp"
android:layout_marginStart="05dp" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView15"
android:layout_marginStart="48dp"
android:hint="House no./Floor/Landmark" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="#+id/LinearLayoutAdditionalContactTo">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView18"
android:layout_marginStart="20dp"
android:background="#drawable/ic_person_black_48dp"
android:layout_marginTop="05dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/contactDetailsTo"
android:layout_marginEnd="10dp"
android:text="#string/additionalContact"
android:textAppearance="?android:attr/textAppearanceMedium"
android:drawableEnd="#drawable/ic_expand_more_black_24dp"
android:layout_marginTop="05dp"
android:layout_marginStart="05dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="60dp"
android:layout_marginEnd="50dp"
android:layout_gravity="center"
android:visibility="gone"
android:id="#+id/LinearLayoutTo">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editTex"
android:layout_weight="1"
android:hint="Name"
android:layout_gravity="center"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editTe"
android:layout_weight="1"
android:hint="Phone"
android:layout_gravity="center"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="OR"
android:id="#+id/textView"
android:layout_gravity="center" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView_next"
android:layout_gravity="center_horizontal"
android:layout_weight="0.42"
android:background="#drawable/ic_chevron_right_black_48dp"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
GoSend activity
public class GoSend extends AppCompatActivity {
private GoogleMap mMap;
private MarkerOptions markerOptions;
private LinearLayout ll;
private TextView additionalContactFrom;
private TextView additionalContactTo;
private LinearLayout linearLayoutFrom;
private LinearLayout linearLayoutTo;
private ImageView next;
private Toolbar toolbar;
private EditText editTextLocation;
private EditText edtxt_from;
private EditText edtxt_to;
private String stringAddress;
String stringAddress1;
String stringAddressTo;
EditText locdetailsFrom;
EditText locdetailsTo;
private Intent i;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gosendlayout);
setUI();
if (Build.VERSION.SDK_INT >= 21) {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
getWindow().setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark));
}
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
public void setUI() {
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("COURIER");
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
edtxt_from=(EditText)findViewById(R.id.editText_from);
edtxt_to=(EditText)findViewById(R.id.editText_to);
locdetailsFrom = (EditText) findViewById(R.id.editText_from_details);
locdetailsTo = (EditText) findViewById(R.id.editText_to_details);
additionalContactFrom = (TextView)findViewById(R.id.contactDetailsFrom);
additionalContactTo = (TextView)findViewById(R.id.contactDetailsTo);
linearLayoutFrom = (LinearLayout)findViewById(R.id.LinearLayoutFrom);
linearLayoutTo = (LinearLayout)findViewById(R.id.LinearLayoutTo);
next = (ImageView)findViewById(R.id.imageView_next);
try {
if (mMap == null) {
mMap = ((MapFragment) getFragmentManager().
findFragmentById(R.id.map)).getMap();
}
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
mMap.setMyLocationEnabled(true);
} catch (Exception e) {
e.printStackTrace();
}
edtxt_from.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
i=new Intent(getApplicationContext(),PickLocationActivity.class);
startActivity(i);
}
});
edtxt_to.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
i=new Intent(getApplicationContext(),PickLocationActivity.class);
startActivity(i);
}
});
additionalContactFrom.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(linearLayoutFrom.getVisibility() == View.GONE){
linearLayoutFrom.setVisibility(View.VISIBLE);
}else{
linearLayoutFrom.setVisibility(View.GONE);
}
}
});
additionalContactTo.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(linearLayoutTo.getVisibility() == View.GONE){
linearLayoutTo.setVisibility(View.VISIBLE);
}else{
linearLayoutTo.setVisibility(View.GONE);
}
}
});
next.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
DetailsFragment fragment = new DetailsFragment();
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.LinearContainer, fragment).commit();
Toast toast = Toast.makeText(getApplicationContext(),"Done",Toast.LENGTH_LONG);
toast.show();
}
});
}
#Override
public void onResume() {
super.onResume(); // Always call the superclass method first
}
}
DetailsFragment layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal|top"
android:background="#android:color/transparent">
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#android:color/white"
android:layout_marginTop="20dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/Details"
android:id="#+id/textView22"
android:layout_gravity="center_vertical"
android:layout_marginTop="15dp"
android:layout_marginStart="15dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/payment"
android:id="#+id/textView24"
android:layout_marginStart="15dp"
android:layout_marginTop="15dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="08dp"
android:id="#+id/imageView23"
android:background="#drawable/line2"
android:layout_marginTop="10dp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:weightSum="1">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/imageView24"
android:background="#drawable/coins49"
android:layout_marginStart="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/price"
android:id="#+id/textView25"
android:layout_gravity="center_vertical"
android:layout_marginStart="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView26"
android:layout_gravity="center_vertical"
android:layout_marginStart="190dp" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="08dp"
android:id="#+id/imageView26"
android:background="#drawable/line2"
android:layout_marginTop="05dp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/imageView25"
android:layout_marginStart="10dp"
android:background="#drawable/currency13" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/total"
android:id="#+id/textView27"
android:layout_marginStart="10dp"
android:layout_gravity="center_vertical" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView28"
android:layout_gravity="center_vertical"
android:layout_marginStart="190dp" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="08dp"
android:id="#+id/imageView27"
android:background="#drawable/line2"
android:layout_marginTop="05dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/imageView28"
android:layout_marginStart="10dp"
android:background="#drawable/credit101" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/paywith"
android:id="#+id/textView29"
android:layout_gravity="center_vertical"
android:layout_marginStart="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView30"
android:layout_gravity="center_vertical"
android:layout_marginStart="180dp" />
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView29"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="#drawable/ic_chevron_right_black_48dp" />
</LinearLayout>
DetailsFragment
public class DetailsFragment extends Fragment {
private Toolbar toolbar;
public DetailsFragment() {
// Required empty public constructor
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_details, container, false);
return view;
}
}
Please help..
There is nothing in your activity layout with android:id="#+id/LinearContainer, and so FragmentManager does not have anywhere to place your DetailsFragment.
I want to call one fragment onclick of next image view. So I have put OnClickListener on image view but it is not getting called at all..
What can be the issue??
GoSend xml Layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:fitsSystemWindows="true"
android:id="#+id/LinearLayoutGoSend">
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
/>
<ScrollView
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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:layout_marginRight="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/DriversNear"
android:id="#+id/textView10"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp" />
<fragment android:layout_width="match_parent"
android:layout_height="250dp"
android:id="#+id/map"
tools:context=".GoSend"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_marginTop="10dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1.00"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/From"
android:id="#+id/textView11"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp" />
<ImageView
android:layout_width="match_parent"
android:layout_height="08dp"
android:id="#+id/imageView11"
android:background="#drawable/line2"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView10"
android:layout_marginLeft="20dp"
android:background="#drawable/ic_place_black_48dp"
android:layout_marginTop="05dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editText_from"
android:text="#string/Loc"
android:visibility="visible"
android:drawableRight="#drawable/ic_chevron_right_black_24dp"
android:layout_marginRight="10dp"
android:cursorVisible="false"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView12"
android:layout_marginLeft="20dp"
android:background="#drawable/ic_description_black_48dp"
android:layout_marginTop="05dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editText_from_details"
android:layout_marginRight="10dp"
android:hint="Location details"
android:cursorVisible="true"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView12"
android:layout_marginLeft="48dp"
android:hint="House no./Floor/Landmark" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/LinearLayoutAdditionalContactFrom">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView13"
android:layout_marginLeft="20dp"
android:background="#drawable/ic_person_black_48dp"
android:layout_marginTop="05dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/contactDetailsFrom"
android:layout_marginRight="10dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:drawableRight="#drawable/ic_expand_more_black_24dp"
android:text="#string/additionalContact"
android:layout_gravity="center_vertical"
android:layout_marginTop="05dp"
android:layout_marginLeft="05dp" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView13"
android:layout_marginLeft="48dp"
android:hint="Input if you're not sender" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView15"
android:layout_marginLeft="48dp"
android:hint="House no./Floor/Landmark" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView16"
android:layout_marginLeft="48dp"
android:hint="input if you're not receiver" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_weight="1.00">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/Details"
android:id="#+id/textView17"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
/>
<ImageView
android:layout_width="match_parent"
android:layout_height="08dp"
android:id="#+id/imageView16"
android:background="#drawable/line2"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView"
android:layout_marginLeft="20dp"
android:background="#drawable/ic_check_circle_black_48dp"
android:layout_marginTop="05dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/pickup"
android:id="#+id/textView18"
android:layout_marginLeft="10dp"
android:layout_marginTop="05dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView20"
android:layout_marginLeft="20dp"
android:background="#drawable/box5"
android:layout_marginTop="05dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editText_pac"
android:layout_marginRight="10dp"
android:hint="Items to deliver"/>
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView_next"
android:layout_gravity="center_horizontal"
android:layout_weight="0.42"
android:clickable="true"
android:background="#drawable/ic_chevron_right_black_48dp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
Calling this in GoSend Activity
next.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
DetailsFragment fragment = new DetailsFragment();
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.LinearLayoutGoSend, fragment).commit();
}
});
GoSend activity
public class GoSend extends AppCompatActivity {
private GoogleMap mMap;
private MarkerOptions markerOptions;
private LinearLayout ll;
private TextView additionalContactFrom;
private TextView additionalContactTo;
private LinearLayout linearLayoutFrom;
private LinearLayout linearLayoutTo;
private ImageView next;
private Toolbar toolbar;
private EditText editTextLocation;
private EditText edtxt_from;
private EditText edtxt_to;
private String stringAddress;
String stringAddress1;
String stringAddressTo;
EditText locdetailsFrom;
EditText locdetailsTo;
private Intent i;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gosendlayout);
setUI();
if (Build.VERSION.SDK_INT >= 21) {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
getWindow().setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark));
}
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
public void setUI() {
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("COURIER");
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
edtxt_from=(EditText)findViewById(R.id.editText_from);
edtxt_to=(EditText)findViewById(R.id.editText_to);
locdetailsFrom = (EditText) findViewById(R.id.editText_from_details);
locdetailsTo = (EditText) findViewById(R.id.editText_to_details);
additionalContactFrom = (TextView)findViewById(R.id.contactDetailsFrom);
additionalContactTo = (TextView)findViewById(R.id.contactDetailsTo);
linearLayoutFrom = (LinearLayout)findViewById(R.id.LinearLayoutFrom);
linearLayoutTo = (LinearLayout)findViewById(R.id.LinearLayoutTo);
next = (ImageView)findViewById(R.id.imageView_next);
next.setClickable(true);
try {
if (mMap == null) {
mMap = ((MapFragment) getFragmentManager().
findFragmentById(R.id.map)).getMap();
}
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
mMap.setMyLocationEnabled(true);
} catch (Exception e) {
e.printStackTrace();
}
edtxt_from.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
i=new Intent(getApplicationContext(),PickLocationActivity.class);
startActivity(i);
}
});
edtxt_to.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
i=new Intent(getApplicationContext(),PickLocationActivity.class);
startActivity(i);
}
});
additionalContactFrom.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(linearLayoutFrom.getVisibility() == View.GONE){
linearLayoutFrom.setVisibility(View.VISIBLE);
}else{
linearLayoutFrom.setVisibility(View.GONE);
}
}
});
additionalContactTo.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(linearLayoutTo.getVisibility() == View.GONE){
linearLayoutTo.setVisibility(View.VISIBLE);
}else{
linearLayoutTo.setVisibility(View.GONE);
}
}
});
next.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
DetailsFragment fragment = new DetailsFragment();
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.LinearLayoutGoSend, fragment).commit();
}
});
}
#Override
public void onResume() {
super.onResume(); // Always call the superclass method first
Bundle bundle = getIntent().getExtras();
if(bundle != null)
stringAddress = bundle.getString("address");
}
}
DetailsFragment
public class DetailsFragment extends Fragment {
private Toolbar toolbar;
public DetailsFragment() {
// Required empty public constructor
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_details, container, false);
return view;
}
}
Fragment layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal|top"
android:background="#android:color/transparent">
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#android:color/white"
android:layout_marginTop="20dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/Details"
android:id="#+id/textView22"
android:layout_gravity="center_vertical"
android:layout_marginTop="15dp"
android:layout_marginStart="15dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/payment"
android:id="#+id/textView24"
android:layout_marginStart="15dp"
android:layout_marginTop="15dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="08dp"
android:id="#+id/imageView23"
android:background="#drawable/line2"
android:layout_marginTop="10dp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:weightSum="1">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/imageView24"
android:background="#drawable/coins49"
android:layout_marginStart="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/price"
android:id="#+id/textView25"
android:layout_gravity="center_vertical"
android:layout_marginStart="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView26"
android:layout_gravity="center_vertical"
android:layout_marginStart="190dp" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="08dp"
android:id="#+id/imageView26"
android:background="#drawable/line2"
android:layout_marginTop="05dp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/imageView25"
android:layout_marginStart="10dp"
android:background="#drawable/currency13" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/total"
android:id="#+id/textView27"
android:layout_marginStart="10dp"
android:layout_gravity="center_vertical" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView28"
android:layout_gravity="center_vertical"
android:layout_marginStart="190dp" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="08dp"
android:id="#+id/imageView27"
android:background="#drawable/line2"
android:layout_marginTop="05dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/imageView28"
android:layout_marginStart="10dp"
android:background="#drawable/credit101" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/paywith"
android:id="#+id/textView29"
android:layout_gravity="center_vertical"
android:layout_marginStart="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView30"
android:layout_gravity="center_vertical"
android:layout_marginStart="180dp" />
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView29"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="#drawable/ic_chevron_right_black_48dp" />
</LinearLayout>
Please Help...
why are you using these below lines of code, please remove them and check the effect:-
android:clickable="true"
next.setClickable(true);
It's not realize to work but it works in maximum cases.
If you set the view to be clickable, then it will consume the click and not propagate it to the container.