When android emulator runs it shows blank screen - java

I created an activity to edit some data by clicking the edit button it will send the key of it to another activity. All of my activity works normally except this particular one that does not show anything other than blank screen.
These are my codes where the problem occured.
jadual_Activity_EditSlot_Pengajar.java
package com.example.karismatuitioncentre.jadual.j_pengajar;
import android.app.TimePickerDialog;
import android.content.Intent;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.example.karismatuitioncentre.R;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
public class Jadual_Activity_EditSlot_Pengajar extends AppCompatActivity {
EditText et_editSlot_subjek,et_editSlot_pengajar;
Button btn_editSlot_submit,btn_editSlot_back;
TextView tvTimeBeforeSet,tvTimeAfterSet,tvEditSlot_masaStart,tvEditSlot_masaEnd,tvSubjectSet,tvPengajarSet;
int t1Hour,t1Minute,t2Hour,t2Minute;
protected void OnCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hari_editslot_pengajar);
String day_key=getIntent().getStringExtra("day_key");
String slot_key=getIntent().getStringExtra("slot_key");
tvSubjectSet= findViewById(R.id.tvSubjectSet);
tvPengajarSet= findViewById(R.id.tvPengajarSet);
tvTimeBeforeSet= findViewById(R.id.tvTimeBeforeSet);
tvTimeAfterSet= findViewById(R.id.tvTimeAfterSet);
et_editSlot_subjek= findViewById(R.id.et_editSlot_subjek);
et_editSlot_pengajar= findViewById(R.id.et_editSlot_pengajar);
tvEditSlot_masaStart= findViewById(R.id.tvEditSlot_masaStart);
tvEditSlot_masaEnd= findViewById(R.id.tvEditSlot_masaEnd);
btn_editSlot_submit= findViewById(R.id.btn_editSlot_submit);
FirebaseDatabase.getInstance().getReference().child(day_key).child(slot_key).addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot snapshot) {
if (snapshot.exists()){
String SubjectSet= Objects.requireNonNull(snapshot.child("subjek").getValue()).toString();
String PengajarSet= Objects.requireNonNull(snapshot.child("pengajar").getValue()).toString();
String HourBeforeSet= Objects.requireNonNull(snapshot.child("masaSHour").getValue()).toString();
String MinuteBeforeSet= Objects.requireNonNull(snapshot.child("masaSMin").getValue()).toString();
String HourAfterSet= Objects.requireNonNull(snapshot.child("masaEHour").getValue()).toString();
String MinuteAfterSet= Objects.requireNonNull(snapshot.child("masaEMin").getValue()).toString();
int startH=Integer.parseInt(HourBeforeSet);
int startM=Integer.parseInt(MinuteBeforeSet);
int endH=Integer.parseInt(HourAfterSet);
int endM=Integer.parseInt(MinuteAfterSet);
tvSubjectSet.setText(SubjectSet);
tvPengajarSet.setText(PengajarSet);
Calendar calendar = Calendar.getInstance();
calendar.set(0,0,0,startH,startM);
tvTimeBeforeSet.setText(DateFormat.format("hh:mm aa",calendar));
Calendar calendar1 = Calendar.getInstance();
calendar1.set(0,0,0,endH,endM);
tvTimeAfterSet.setText(DateFormat.format("hh:mm aa",calendar1));
}
}
#Override
public void onCancelled(#NonNull DatabaseError error) {
}
});
tvEditSlot_masaStart.setOnClickListener(view -> {
TimePickerDialog timePickerDialog=new TimePickerDialog(
Jadual_Activity_EditSlot_Pengajar.this,
(view1, hourOfDay, minute) -> {
t1Hour=hourOfDay;
t1Minute=minute;
Calendar calendar = Calendar.getInstance();
calendar.set(0,0,0,t1Hour,t1Minute);
tvEditSlot_masaStart.setText(DateFormat.format("hh:mm aa",calendar));
},12,0,false
);
timePickerDialog.updateTime(t1Hour,t1Minute);
timePickerDialog.show();
});
tvEditSlot_masaEnd.setOnClickListener(view -> {
TimePickerDialog timePickerDialog=new TimePickerDialog(
Jadual_Activity_EditSlot_Pengajar.this,
(view1, hourOfDay, minute) -> {
t2Hour=hourOfDay;
t2Minute=minute;
Calendar calendar = Calendar.getInstance();
calendar.set(0,0,0,t2Hour,t2Minute);
tvEditSlot_masaEnd.setText(DateFormat.format("hh:mm aa",calendar));
},12,0,false
);
timePickerDialog.updateTime(t2Hour,t2Minute);
timePickerDialog.show();
});
btn_editSlot_submit.setOnClickListener(view -> {
Map<String,Object> map=new HashMap<>();
map.put("subjek",et_editSlot_subjek.getText().toString());
map.put("pengajar",et_editSlot_pengajar.getText().toString());
map.put("masaSHour",t1Hour);
map.put("masaEHour",t2Hour);
map.put("masaSMin",t1Minute);
map.put("masaEMin",t2Minute);
FirebaseDatabase.getInstance().getReference().child(day_key).child(slot_key)
.setValue(map)
.addOnSuccessListener(aVoid -> {
et_editSlot_subjek.setText("");
et_editSlot_pengajar.setText("");
Toast.makeText(getApplicationContext(),"Penambahan berjaya",Toast.LENGTH_LONG).show();
Intent intent = new Intent(getApplicationContext(), Jadual_Activity_ViewSchedule_Pengajar_Test.class);
intent.putExtra("day_key", day_key);
startActivity(intent);
finish();
})
.addOnFailureListener(e -> Toast.makeText(getApplicationContext(),"Tidak Berjaya",Toast.LENGTH_LONG).show());
});
}
}
activity_hari_editslot_pengajar.java
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat 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:gravity="center"
android:background="#drawable/whitebg">
<TextView
android:id="#+id/tvSubjectSet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:text="TextView"
android:textSize="20sp" />
<EditText
android:id="#+id/et_editSlot_subjek"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:layout_marginBottom="15dp"
android:hint="Nama Subjek"
android:inputType="text"
android:textColor="#000"
android:textColorHint="#95150D0D"
android:textSize="20sp" />
<TextView
android:id="#+id/tvPengajarSet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="20sp" />
<EditText
android:id="#+id/et_editSlot_pengajar"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:layout_marginBottom="15dp"
android:hint="Nama Pengajar"
android:inputType="text"
android:textColor="#000"
android:textColorHint="#95150D0D"
android:textSize="20sp" />
<TextView
android:id="#+id/tvTimeBeforeSet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="20sp" />
<TextView
android:id="#+id/tvEditSlot_masaStart"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:layout_marginBottom="15dp"
android:background="#4BA8E697"
android:drawablePadding="16dp"
android:gravity="center"
android:hint="Waktu Kelas Bermula"
android:textColorHint="#95150D0D"
android:textSize="20sp"
android:textStyle="italic"
app:drawableTopCompat="#drawable/ic_time" />
<TextView
android:id="#+id/tvTimeAfterSet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="20sp" />
<TextView
android:id="#+id/tvEditSlot_masaEnd"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:layout_marginBottom="15dp"
android:background="#68CDB1B0"
android:drawablePadding="16dp"
android:gravity="center"
android:hint="Waktu Kelas Tamat"
android:textColorHint="#95150D0D"
android:textSize="20sp"
android:textStyle="italic"
app:drawableTopCompat="#drawable/ic_time" />
<Button
android:id="#+id/btn_editSlot_submit"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginBottom="15dp"
android:background="#1E88E5"
android:text="Hantar"
android:textColor="#F6F6F6"
android:textSize="20sp" />
<Button
android:id="#+id/btn_editSlot_back"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:background="#00ACC1"
android:text="Kembali"
android:textColor="#FFFFFF"
android:textSize="20sp" />
</androidx.appcompat.widget.LinearLayoutCompat>

Related

DatePickerDialog issue with fragments

I have a fragment with editText that is meant to open a date picker. I have done everything seemingly correctly, however I can't figure out why I get the following error.
It has something to do with the fact that I'm working with a fragment.
Could you please help with this error?
EditProfileFragment.java
import android.app.DatePickerDialog;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.DatePicker;
import com.archive.pod.R;
import com.google.android.material.textfield.TextInputEditText;
import java.util.Calendar;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
public class EditProfileFragment extends Fragment {
//Initializing
private TextInputEditText mDisplayDate;
private DatePickerDialog.OnDateSetListener mDateSetListener;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_editprofile, container, false);
//EditText
mDisplayDate = view.findViewById(R.id.etDateOfBirth);
//Date picker dialog box
mDisplayDate.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int day = cal.get(Calendar.DAY_OF_MONTH);
DatePickerDialog dialog = new DatePickerDialog(
requireContext(),
android.R.style.Theme_DeviceDefault_Dialog_MinWidth,
mDateSetListener,
year, month, day);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();
}
});
mDateSetListener = new DatePickerDialog.OnDateSetListener() {
#Override
public void onDateSet(DatePicker datePicker, int year, int month, int day) {
month = month + 1;
String date = month + "/" + day + "/" + year;
mDisplayDate.setText(date);
}
};
return view;
}
}
Error Log
/AndroidRuntime: FATAL EXCEPTION: main
Process: com.archive.pod, PID: 20399
java.lang.ClassCastException: com.google.android.material.textfield.TextInputLayout cannot be cast to com.google.android.material.textfield.TextInputEditText
at com.archive.pod.Profile.EditProfileFragment.onCreateView(EditProfileFragment.java: 33)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java: 2600)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java: 881)
at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java: 1238)
at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java: 434)
Fragment Layout
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/userProfilePicture"
android:src="#drawable/ic_profile_picture_default"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="20dp"
android:layout_centerHorizontal="true" />
<ImageButton
android:id="#+id/changeUserPhoto"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginTop="90dp"
android:layout_marginLeft="200dp"
android:layout_marginStart="200dp"
android:elevation="10dp"
android:background="#drawable/ic_add_circle"/>
<RelativeLayout
android:id="#+id/sectionTitle1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/changeUserPhoto"
android:layout_marginTop="50dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="true"
android:textSize="12sp"
android:textColor="#color/label"
android:text="Primary Information"/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/relLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_below="#+id/sectionTitle1">
<!-- Full name input -->
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/etFullname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions"
app:errorEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/full_name" />
</com.google.android.material.textfield.TextInputLayout>
<!-- Email input -->
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/etEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/etFullname"
app:errorEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/emailAddress"
android:inputType="textEmailAddress"/>
</com.google.android.material.textfield.TextInputLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/sectionTitle2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/relLayout1"
android:layout_marginTop="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="true"
android:textSize="12sp"
android:textColor="#color/label"
android:text="Private Information"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/sectionTitle2">
<!-- Phone number input -->
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/etPhoneNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:longClickable="false"
android:focusableInTouchMode="false"
app:errorEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/phone_number"
android:inputType="date"/>
</com.google.android.material.textfield.TextInputLayout>
<!-- Date of birth input -->
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/etDateOfBirth"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/etPhoneNumber"
android:focusable="false"
android:longClickable="false"
android:focusableInTouchMode="false"
app:errorEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/dob"
android:inputType="date"/>
</com.google.android.material.textfield.TextInputLayout>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</merge>
It just tells you that the first parameter of the DatePickerDialog constructor is not as supposed to be; where you put a Fragment, while it expects a context, so replace below line
DatePickerDialog dialog = new DatePickerDialog(
EditProfileFragment.this,
android.R.style.Theme_DeviceDefault_Dialog_MinWidth,
mDateSetListener,
year, month, day);
with
DatePickerDialog dialog = new DatePickerDialog(
requireContext(),
android.R.style.Theme_DeviceDefault_Dialog_MinWidth,
mDateSetListener,
year, month, day);
Use getapplicationcontext() and remove Edittextprofilefragment.this

how to build and bind custom exoplayer layout

I want to build an app that display movies through internet. and i want to use exoplayer to play the movies . I initialized the exoplayer and the exoplayer plays the url i passed to . But i want to change the layout of playback_controller and put my own layout but i dont know how to bind the custom layout with exoplayer.
i also dont how to set the progress bar,default time bar(or seek bar), and other buttons you will see in my layout.
these are my java code
package com.example.novin.exoplayer;
import android.net.Uri;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Surface;
import android.view.SurfaceView;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.ExoPlayerFactory;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.Renderer;
import com.google.android.exoplayer2.RendererCapabilities;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.decoder.DecoderCounters;
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
import com.google.android.exoplayer2.extractor.ExtractorInput;
import com.google.android.exoplayer2.extractor.ExtractorsFactory;
import com.google.android.exoplayer2.extractor.ts.TsPayloadReader;
import com.google.android.exoplayer2.source.ExtractorMediaSource;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.source.hls.HlsDataSourceFactory;
import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.trackselection.TrackSelection;
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.google.android.exoplayer2.trackselection.TrackSelector;
import com.google.android.exoplayer2.trackselection.TrackSelectorResult;
import com.google.android.exoplayer2.ui.DefaultTimeBar;
import com.google.android.exoplayer2.ui.SimpleExoPlayerView;
import com.google.android.exoplayer2.upstream.BandwidthMeter;
import com.google.android.exoplayer2.upstream.DataSpec;
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
import com.google.android.exoplayer2.upstream.RawResourceDataSource;
import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.VideoRendererEventListener;
import javax.sql.DataSource;
import static com.google.android.exoplayer2.Player.*;
public class MainActivity extends AppCompatActivity {
SimpleExoPlayerView playerView ;
SimpleExoPlayer exoPlayer ;
Uri enternetUri= Uri.parse("https://developers.google.com/training/images/tacoma_narrows.mp4");
ImageButton btnPause , btnPlay;
DefaultTimeBar seekBar ;
RelativeLayout loadingBar ;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_exo);
playerView= (SimpleExoPlayerView) findViewById(R.id.playerView);
playerView.setUseController(true);
loadingBar= (RelativeLayout) findViewById(R.id.loading_bar);
btnPause = (ImageButton) findViewById(R.id.btn_pause);
btnPlay = (ImageButton) findViewById(R.id.btn_play);
seekBar= (DefaultTimeBar) findViewById(R.id.exo_progress);
try {
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelector trackSelector = new DefaultTrackSelector(new AdaptiveTrackSelection.Factory(bandwidthMeter));
exoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector);
DefaultHttpDataSourceFactory dataSourceFactory = new DefaultHttpDataSourceFactory("exoplayer_video");
ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
final MediaSource mediasource = new ExtractorMediaSource(enternetUri, dataSourceFactory, extractorsFactory, null, null);
playerView.setPlayer(exoPlayer);
exoPlayer.prepare(mediasource);
btnPlay.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
exoPlayer.setPlayWhenReady(true);
btnPlay.setVisibility(View.GONE);
btnPause.setVisibility(View.VISIBLE);
}
});
btnPause.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
exoPlayer.setPlayWhenReady(false);
btnPause.setVisibility(View.GONE);
btnPlay.setVisibility(View.VISIBLE);
}
});
}catch (Exception e){
Log.e("MainActivity","exoplayer error" + e.toString());
}
}
#Override
protected void onPause() {
super.onPause();
exoPlayer.setPlayWhenReady(false);
}
public class ExoplayerClass implements ExoPlayer.EventListener {
#Override
public void onTimelineChanged(Timeline timeline, Object manifest) {
}
#Override
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
}
#Override
public void onLoadingChanged(boolean isLoading) {
}
#Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
}
#Override
public void onRepeatModeChanged(int repeatMode) {
}
#Override
public void onPlayerError(ExoPlaybackException error) {
}
#Override
public void onPositionDiscontinuity() {
}
#Override
public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {
}
}
}
this is my exo_playback_control_view.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">
<RelativeLayout
android:id="#+id/loading_bar"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ProgressBar
android:id="#+id/pro_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/root">
<LinearLayout
android:id="#+id/top"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="48dp"
android:gravity="center"
android:paddingRight="50dp"
android:background="#96000000">
<ImageButton
android:id="#+id/btn_back"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#f2ffffff"
android:src="#drawable/ic_back2"
android:layout_gravity="center"
android:layout_marginLeft="5dp"/>
<TextView
android:id="#+id/text_title"
android:text="Video Title"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="24sp"
android:gravity="center|left"
android:paddingLeft="10dp"
android:textColor="#fefffe"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="40dp" />
<ImageButton
android:id="#+id/btn_cast"
android:src="#drawable/chrom_cast"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_height="48dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/middle"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:id="#+id/seekbar_time"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#96000000">
<TextView
android:id="#+id/text_current_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="00:00:00"
android:textColor="#ffffff"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingLeft="20dp"/>
<com.google.android.exoplayer2.ui.DefaultTimeBar
android:id="#+id/exo_progress"
android:layout_marginRight="10dp"
android:layout_width="400dp"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/text_total_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="00:00:00"
android:textColor="#ffffff"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingLeft="0dp"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:id="#+id/cotrols"
android:layout_width="match_parent"
android:layout_height="48dp"
android:paddingBottom="10dp"
android:background="#96000000">
<ImageButton
android:src="#drawable/lock2"
android:layout_weight="0"
android:id="#+id/btn_lock"
android:scaleType="fitXY"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="right"
android:background="#fafcfa"
android:layout_marginLeft="30dp"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center"
android:layout_marginLeft="70dp"
android:layout_marginRight="70dp">
<ImageButton
android:layout_marginLeft="10dp"
android:src="#drawable/prev"
android:scaleType="fitXY"
android:id="#+id/btn_prev"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="center"
android:background="#f9fcf9"/>
<ImageButton
android:id="#+id/btn_rev"
android:background="#f2f2f2"
android:scaleType="fitXY"
android:src="#drawable/rewind"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginLeft="24dp"/>
<ImageButton
android:background="#f1e2e2"
android:src="#drawable/play"
android:id="#+id/btn_play"
android:layout_marginLeft="24dp"
android:layout_width="32dp"
android:layout_height="32dp" />
<ImageButton
android:background="#0a0a0a"
android:src="#drawable/pouse"
android:layout_marginLeft="24dp"
android:id="#+id/btn_pause"
android:visibility="gone"
android:layout_width="32dp"
android:layout_height="32dp" />
<ImageButton
android:id="#+id/btn_forw"
android:background="#f2f2f2"
android:rotation="180"
android:scaleType="fitXY"
android:src="#drawable/rewind"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginLeft="24dp"/>
<ImageButton
android:src="#drawable/prev"
android:scaleType="fitXY"
android:id="#+id/btn_next"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginLeft="24dp"
android:rotation="180"
android:layout_gravity="center"
android:background="#f9fcf9"/>
</LinearLayout>
<ImageButton
android:scaleType="fitXY"
android:src="#drawable/subtitles"
android:id="#+id/btn_sub"
android:layout_weight="0"
android:layout_marginRight="24dp"
android:layout_gravity="center"
android:layout_width="40dp"
android:layout_height="40dp"
android:cropToPadding="false"
android:alpha="1"/>
<ImageButton
android:layout_marginRight="20dp"
android:id="#+id/btn_setting"
android:layout_weight="0"
android:layout_gravity="right"
android:scaleType="fitXY"
android:src="#drawable/setting"
android:layout_width="40dp"
android:layout_height="40dp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>

Click a button and be directed to new activity, Android

MainActivity.Java
package com.example.drexsprint.login;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
Button b1,b2;
EditText ed1,ed2;
TextView tx1;
int counter = 3;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1=(Button)findViewById(R.id.button);
ed1=(EditText)findViewById(R.id.editText);
ed2=(EditText)findViewById(R.id.editText2);
b2=(Button)findViewById(R.id.button2);
tx1=(TextView)findViewById(R.id.textView3);
tx1.setVisibility(View.GONE);
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(ed1.getText().toString().equals("admin") &&
ed2.getText().toString().equals("1234")) {
Toast.makeText(getApplicationContext(), "Redirecting...",Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(getApplicationContext(), "Wrong Credentials",Toast.LENGTH_SHORT).show();
tx1.setVisibility(View.VISIBLE);
tx1.setBackgroundColor(Color.RED);
counter--;
tx1.setText(Integer.toString(counter));
if (counter == 0) {
b1.setEnabled(false);
}
}
}
});
b2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});
}}
activity_main.xml
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Arduino Security"
android:id="#+id/textView"
android:textColor="#ff7aff24"
android:textSize="35dp"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:hint="Enter Name"
android:focusable="true"
android:textColorHighlight="#ff7eff15"
android:textColorHint="#ffff25e6"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/editText2"
android:layout_below="#+id/editText"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="#+id/editText"
android:layout_alignEnd="#+id/editText"
android:textColorHint="#ffff299f"
android:hint="Password" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Attempts Left:"
android:id="#+id/textView2"
android:layout_below="#+id/editText2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="25dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/textView3"
android:layout_alignTop="#+id/textView2"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignBottom="#+id/textView2"
android:textSize="25dp"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="login"
android:id="#+id/button"
android:layout_alignParentBottom="true"
android:textColor="#ddec0d"
android:background="#0e17c2"
android:layout_alignLeft="#+id/textView"
android:layout_alignStart="#+id/textView"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:id="#+id/button2"
android:layout_alignParentBottom="true"
android:background="#df0c0c"
android:textColor="#0dca07"
android:layout_alignRight="#+id/textView"
android:layout_alignEnd="#+id/textView"
android:layout_centerHorizontal="true" />
<TextView
android:text="Please Login:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView4"
android:textSize="35dp"
android:layout_below="#+id/textView"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp" />
</RelativeLayout>
Second Screen App
screen.Java
package com.example.drexsprint.login;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class Screen extends AppCompatActivity {
private WebView myWebView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myWebView = (WebView) findViewById(R.id.webView);
myWebView.getSettings().setDomStorageEnabled(true);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});
}
public void Left(View view) {
myWebView.loadUrl("http://admin:0000000AA#10.0.1.16/?button2");
}
public void Right (View view) {
myWebView.loadUrl("http://admin:0000000AA#10.0.1.16/?button3");
}
public void Temp (View view) {
myWebView.loadUrl("http://admin:0000000AA#10.0.1.16/?button1");
}
public void Hum (View view) {
myWebView.loadUrl("http://admin:0000000AA#10.0.1.16/button1");
}
public void Photo (View view) {
goToUrl("http://admin:0000000AA#10.0.1.6/image.jpg");
}
private void goToUrl(String url) {
Uri uriUrl = Uri.parse(url);
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
startActivity(launchBrowser);
/** public void Photo (View view) {
// myWebView.loadUrl("http://admin:0000000AA#10.0.1.6/image.jpg");
}**/
}}
screen_layout
<WebView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/webView"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:visibility="invisible"
android:layout_above="#+id/button" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rotate Left"
android:id="#+id/button"
android:onClick="Left"
android:backgroundTint="#0f50e8"
android:textColor="#f4d318"
android:layout_above="#+id/button4"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toStartOf="#+id/button5"
android:layout_alignRight="#+id/button4"
android:layout_alignEnd="#+id/button4" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rotate Right"
android:id="#+id/button2"
android:onClick="Right"
android:backgroundTint="#0f50e8"
android:textColor="#f4d318"
android:layout_below="#+id/webView"
android:layout_alignRight="#+id/webView"
android:layout_alignEnd="#+id/webView"
android:layout_alignLeft="#+id/button3"
android:layout_alignStart="#+id/button3" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Temp."
android:id="#+id/button3"
android:onClick="Temp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:backgroundTint="#369d7c"
android:textColor="#f4d318" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Hum."
android:id="#+id/button4"
android:onClick="Hum"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:backgroundTint="#369d7c"
android:textColor="#f4d318" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Take Photo"
android:id="#+id/button5"
android:onClick="Photo"
android:backgroundTint="#589d36"
android:textColor="#f4d318"
android:layout_below="#+id/webView"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true" />
<VideoView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/videoView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_above="#+id/webView"
android:background="#0a0a0a"
android:clickable="true"
android:contextClickable="true"
android:focusable="true" />
</RelativeLayout>
Okay! So I got two aplications, the first one is a login screen and the second one is a main menu of what the application should do, I want to find a way so that when a user insert the correct credentials and click on the Login button the app executes the second screen the main menu, how can i do this, Join the two apps together.
Wat i wanna achieve is on the the click of "Login Button" on the first app it Launches the Second app as a window! Thanks!! Kind of new in android any detailed help would be much appreciated.
Use startActivityForResult() to get the result from another activity.
By the help of android startActivityForResult() method, we can send information from one activity to another and vice-versa.
Intent intent=new Intent(this,Class2.class);
startActivityForResult(intent,10);

Why the imageView which is in "userProfilePic" id, changes quickly to the old one stored in database, after selecting a new picture [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I want to change the picture in the imageView id "userProfilePic" to the new one selected by the user, and update that picture to the database. But once I choose a new picture, the image under "userProfilePic" id quickly changes to the new one and again it changes to the old one( which is already in the database) so I am unable to upload new pictures for the "userProfilePic" id. I am a beginner to Android development and I know only small amount of android, So please help me to solve this issue. This is my EditUserProfile.java file
package com.example.kasun.timetable;
import android.app.DatePickerDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v7.app.ActionBarActivity;
import android.util.Base64;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Locale;
public class EditYourProfile extends ActionBarActivity implements View.OnClickListener {
private static final int Result_Load_Image=1;
private Button bSave2,bBack2,bImageUpload;
private EditText etUsernameEdit,etFirstNameEdit,etLastNameEdit,etPasswordEdit,etPositionEdit,etBirthDateEdit,etQualificationEdit,etEmailEdit;
private Calendar myCalendar = Calendar.getInstance();
private UserLocalDatabase userLocalDatabase;
private ImageView userProfilePic;
private static final String SERVER_ADDRESS="http://172.21.18.170/Timetable/";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_your_profile);
bBack2=(Button)findViewById(R.id.bBack2);
bSave2=(Button)findViewById(R.id.bSave2);
etUsernameEdit=(EditText)findViewById(R.id.etUserNameEdit);
etFirstNameEdit=(EditText)findViewById(R.id.etFirstNameEdit);
etLastNameEdit=(EditText)findViewById(R.id.etLastNameEdit);
etPasswordEdit=(EditText)findViewById(R.id.etPasswordEdit);
etEmailEdit=(EditText)findViewById(R.id.etEmailEdit);
etQualificationEdit=(EditText)findViewById(R.id.etQualificationEdit);
etPositionEdit=(EditText)findViewById(R.id.etPositionEdit);
etBirthDateEdit=(EditText)findViewById(R.id.etBirthDateEdit);
userProfilePic=(ImageView)findViewById(R.id.userProfilePic);
bImageUpload=(Button)findViewById(R.id.bImageUpload);
bSave2.setOnClickListener(this);
bBack2.setOnClickListener(this);
userProfilePic.setOnClickListener(this);
bImageUpload.setOnClickListener(this);
userLocalDatabase = new UserLocalDatabase(this);
final DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
#Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
// TODO Auto-generated method stub
myCalendar.set(Calendar.YEAR, year);
myCalendar.set(Calendar.MONTH, monthOfYear);
myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
updateLabel();
}
};
etBirthDateEdit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
new DatePickerDialog(EditYourProfile.this, date, myCalendar
.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
myCalendar.get(Calendar.DAY_OF_MONTH)).show();
}
});
}
private void updateLabel() {
String myFormat = "MM/dd/yy";
SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.US);
etBirthDateEdit.setText(sdf.format(myCalendar.getTime()));
}
#Override
protected void onStart() {
super.onStart();
if(authenticate()==true){
showDetails();
}
else {
startActivity(new Intent(this, MainActivity.class));
finish();
}
}
public boolean authenticate(){
return userLocalDatabase.getUserStatus();
}
public void showDetails(){
User user=userLocalDatabase.getLoggedInUser();
etFirstNameEdit.setText(user.firstName);
etLastNameEdit.setText(user.lastName);
etUsernameEdit.setText(user.userName);
etQualificationEdit.setText(user.qualification);
etPositionEdit.setText(user.position);
etPasswordEdit.setText(user.password);
etEmailEdit.setText(user.email);
new downloadImage(etUsernameEdit.getText().toString()).execute();
}
#Override
public void onClick(View v) {
switch(v.getId()){
case R.id.bSave2:
break;
case R.id.bBack2:
startActivity(new Intent(this,SelectTask.class));
break;
case R.id.userProfilePic:
Intent galleryIntent= new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent,Result_Load_Image);
break;
case R.id.bImageUpload:
Bitmap image=((BitmapDrawable) userProfilePic.getDrawable()).getBitmap();
new uploadImage(image,etUsernameEdit.getText().toString()).execute();
break;
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==Result_Load_Image && resultCode==RESULT_OK && data!=null){
Uri selectedImage= data.getData();
userProfilePic.setImageURI(selectedImage);
}
}
public class uploadImage extends AsyncTask<Void,Void,Void> {
private Bitmap image;
private String name;
public uploadImage(Bitmap image,String name){
this.image=image;
this.name=name;
}
#Override
protected Void doInBackground(Void... params) {
ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.JPEG,100,byteArrayOutputStream);
String encodedImage= Base64.encodeToString(byteArrayOutputStream.toByteArray(),Base64.DEFAULT);
ArrayList<NameValuePair> dataToSend1= new ArrayList<>();
dataToSend1.add(new BasicNameValuePair("image",encodedImage));
dataToSend1.add(new BasicNameValuePair("name",name));
HttpParams httpRequestParams= getHttpRequestParams();
HttpClient httpClient = new DefaultHttpClient(httpRequestParams);
HttpPost post= new HttpPost(SERVER_ADDRESS + "savePicture.php");
try{
post.setEntity(new UrlEncodedFormEntity(dataToSend1));
httpClient.execute(post);
}
catch(Exception e){
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
Toast.makeText(getApplicationContext(),"Image is uploaded",Toast.LENGTH_SHORT).show();
}
}
//----------------------------------------------------------------------------------------------
private HttpParams getHttpRequestParams(){
HttpParams httpRequestParams= new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpRequestParams, 1000 * 30);
HttpConnectionParams.setSoTimeout(httpRequestParams,1000 * 30);
return httpRequestParams;
}
public class downloadImage extends AsyncTask<Void,Void,Bitmap>{
private String name;
public downloadImage(String name){
this.name=name;
}
#Override
protected Bitmap doInBackground(Void... params) {
String url= SERVER_ADDRESS+"proPictures/"+name+".JPG";
try{
URLConnection connection= new URL(url).openConnection();
connection.setConnectTimeout(1000*30);
connection.setReadTimeout(1000 * 30);
return BitmapFactory.decodeStream((InputStream) connection.getContent(), null, null);
}catch(Exception e){
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(Bitmap bitmap) {
super.onPostExecute(bitmap);
if(bitmap!=null){
userProfilePic.setImageBitmap(bitmap);
}
}
}
}
here is my relavant 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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.example.kasun.timetable.EditYourProfile"
android:background="#303030">
<ScrollView
android:layout_width="match_parent"
android:layout_height="1000dp"
android:id="#+id/scroll">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="110dp"
android:layout_height="100dp"
android:id="#+id/userProfilePic"
android:layout_marginTop="34dp"
android:background="#c6c4c4"
android:layout_marginBottom="10dp"/>
<Button
android:layout_width="110dp"
android:layout_height="wrap_content"
android:text="Upload "
android:id="#+id/bImageUpload"
android:layout_marginBottom="10dp"
android:textColor="#ffffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/userNameText"
android:id="#+id/textView18"
android:layout_marginBottom="10dp"
android:textColor="#ffffffff" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/etUserNameEdit"
android:layout_marginBottom="10dp"
android:textColor="#ffffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/FirstNameText"
android:id="#+id/textView19"
android:layout_marginBottom="10dp"
android:textColor="#ffffffff" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/etFirstNameEdit"
android:layout_marginBottom="10dp"
android:textColor="#ffffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/LastNameText"
android:id="#+id/textView20"
android:layout_marginBottom="10dp"
android:textColor="#ffffffff" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/etLastNameEdit"
android:layout_marginBottom="10dp"
android:textColor="#ffffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/Password"
android:id="#+id/textView21"
android:layout_marginTop="16dp"
android:layout_marginBottom="10dp"
android:textColor="#ffffffff" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/etPasswordEdit"
android:layout_marginBottom="10dp"
android:textColor="#ffffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/Position"
android:id="#+id/textView23"
android:layout_marginTop="12dp"
android:layout_marginBottom="10dp"
android:textColor="#ffffffff" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/etPositionEdit"
android:layout_marginBottom="10dp"
android:textColor="#ffffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/Email"
android:id="#+id/textView24"
android:layout_marginTop="12dp"
android:layout_marginBottom="10dp"
android:textColor="#ffffffff" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/etEmailEdit"
android:layout_marginBottom="10dp"
android:textColor="#ffffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/Telephone"
android:id="#+id/textView25"
android:layout_marginTop="12dp"
android:layout_marginBottom="10dp"
android:textColor="#ffffffff" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/etTelephoneEdit"
android:layout_marginBottom="10dp"
android:textColor="#ffffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/BDate"
android:id="#+id/textView26"
android:layout_marginTop="16dp"
android:layout_marginBottom="10dp"
android:textColor="#ffffffff" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/etBirthDateEdit"
android:textColor="#ffffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/qualification"
android:id="#+id/textView26"
android:layout_marginTop="16dp"
android:layout_marginBottom="10dp"
android:textColor="#ffffffff" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/etQualificationEdit"/>
<!--<DatePicker-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:id="#+id/datePicker"-->
<!--android:layout_alignBottom="#+id/scroll"-->
<!--android:layout_centerHorizontal="true"-->
<!--android:layout_marginBottom="85dp" />-->
</LinearLayout>
</ScrollView>
<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="#string/LogoutButtonText"
android:id="#+id/bLogout2"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:gravity="center" />
<!--android:layout_alignParentRight="#+id/bBack2"-->
<!--android:layout_alignBottom="#+id/scroll"-->
<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="#string/BackButtonText"
android:id="#+id/bBack2"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:gravity="center" />
<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="#string/SaveButtonText"
android:id="#+id/bSave2"
android:layout_alignTop="#+id/bBack2"
android:layout_centerHorizontal="true"
android:gravity="center" />
</RelativeLayout>
I think it may come from the fact that you call showDetail on you onstart method which is called when you come back to your activity. Maybe it does something like that:
activityToPickUpAPic-->PickUpAPic-->Go back to that activity-->
Onstart-->May start to download your image->start on activity result-> charge your new image->finish to download your image from the server
When you come back to your activity onStart is called again so you may want to change this method and call the download picture just at the Oncreate method.
Let me know it that's the problem ;)
Edit:
boolean isImageSet = false;
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==Result_Load_Image && resultCode==RESULT_OK && data!=null){
Uri selectedImage= data.getData();
userProfilePic.setImageURI(selectedImage);
isImageSet = true;
}
}
and:
if(bitmap!=null && !isImageSet){
userProfilePic.setImageBitmap(bitmap);
}
For the Test you could just comment
//userProfilePic.setImageBitmap(bitmap);

i want to calculate the number and display results in textboxes of next screen layout in android

main activity.java
package abhilmohan.blogspot.com;
import android.R.string;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.app.ActionBar;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
public class MainActivity extends ActionBarActivity {
EditText amount1;
EditText amount2;
EditText amount3;
EditText amount4;
Button calculate;
double w=0;
double x=0;
double y=0;
double z=0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar bar= getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#ff0000")));
}
public void initcontrols() {
amount1=(EditText)findViewById(R.id.editText1);
amount2=(EditText)findViewById(R.id.editText2);
amount3=(EditText)findViewById(R.id.editText3);
amount4=(EditText)findViewById(R.id.editText4);
calculate=(Button)findViewById(R.id.button1);
}
public void calculate() {
w=Double.parseDouble(amount1.getText().toString());
x=Double.parseDouble(amount2.getText().toString());
y=w/12;
amount3.setText(Double.toString(y));
z=w*x/100;
amount4.setText(Double.toString(z));
}
public void gotoactivity (View v) {
Intent intent = new Intent(this,ResultPage.class);
calculate();
startActivity(intent);
}
am not getting result while calling calculator() void method on button click.i want my results to be published in two textviews created in reulst_page layout
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background"
android:gravity="left"
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="abhilmohan.blogspot.com.MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
style="#style/text_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="40dp"
android:layout_marginRight="40dp"
android:text="#string/ctc"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="75dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="20dp"
android:layout_marginTop="-15dp"
android:inputType="number"
android:background="#drawable/rounded_edit_text"
android:ems="10"
android:padding="20dp"
android:paddingBottom="50dp"
android:textColor="#000000" />
<TextView
android:id="#+id/textView2"
style="#style/text_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="90dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="-30dp"
android:text="#string/TDS"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="-70dp"
android:background="#drawable/rounded_edit_text"
android:inputType="number"
android:ems="10"
android:padding="20dp"
android:paddingBottom="50dp" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button1"
android:layout_width="177dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="60dp"
android:background="#drawable/button_style"
android:text="#string/ok"
android:textColor="#ffffff"
android:onClick="gotoactivity" />
</LinearLayout>
</RelativeLayout>
resultpage.java
package abhilmohan.blogspot.com;
import android.support.v7.app.ActionBarActivity;
import android.view.MenuItem;
import android.app.ActionBar;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
public class ResultPage extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.result_page);
getActionBar().setDisplayHomeAsUpEnabled(true);
ActionBar bar= getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#ff0000")));
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId()== android.R.id.home)
{
finish();
}
return super.onOptionsItemSelected(item);
}
}
result_page.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
style="#style/text_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="40dp"
android:layout_marginRight="40dp"
android:text="#string/amount"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="75dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="20dp"
android:layout_marginTop="-15dp"
android:background="#drawable/rounded_edit_text"
android:ems="10"
android:inputType="number"
android:padding="20dp"
android:paddingBottom="50dp"
android:textColor="#000000"
android:clickable="false"
android:cursorVisible="false"
android:focusable="false"
android:focusableInTouchMode="false" />
<TextView
android:id="#+id/textView2"
style="#style/text_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="90dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="-30dp"
android:text="#string/tdsamount"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/editText4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="-70dp"
android:background="#drawable/rounded_edit_text"
android:ems="10"
android:inputType="number"
android:padding="20dp"
android:paddingBottom="50dp"
android:clickable="false"
android:cursorVisible="false"
android:focusable="false"
android:focusableInTouchMode="false" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button2"
android:layout_width="177dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="60dp"
android:background="#drawable/button_style"
android:text="#string/rate"
android:textColor="#ffffff" />
</LinearLayout>
At the moment you are executing calculate() in the MainActivity.java second activity called ResultPage doesn't exist, therefore you can't change it's view (editText3and editText4).
In order to pass data to another activity you should fill your Intent with some extra data and then in your ResultPage activity's onCreate you would get underlying extras.
EDIT
MainActivity.java
public void gotoactivity (View v) {
calculate();
Intent intent = new Intent(this, ResultPage.class);
intent.putExtra("AMOUNT_3", y);
intent.putExtra("AMOUNT_4", z);
startActivity(intent);
}
ResultPage.java inside onCreate
Bundle extras = getIntent().getExtras();
if (extras != null) {
int amount3 = extras.getInt("AMOUNT_3");
int amount4 = extras.getInt("AMOUNT_4");
}

Categories