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>
Related
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>
I am trying to call constructor on onClick listener of getSurfaceView for swipe layout but it is not happening.
RideAdapter.java
#Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View view;
if (viewType == RIDE_ITEM_TYPE) {
view = inflater.inflate(R.layout.item_upcoming_share_ride, parent, false);
swipeLayout = (SwipeLayout) view.findViewById(R.id.sample2);
swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown);
swipeLayout.addDrag(SwipeLayout.DragEdge.Right, swipeLayout.findViewWithTag("Bottom2"));
// sample2.setShowMode(SwipeLayout.ShowMode.PullOut);
swipeLayout.findViewById(R.id.edit).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(context, "Star", Toast.LENGTH_SHORT).show();
}
});`
swipeLayout.findViewById(R.id.delete).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(context, "Magnifier", Toast.LENGTH_SHORT).show();
}
});
swipeLayout.getSurfaceView().setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
v = inflater.inflate(R.layout.item_upcoming_share_ride, parent, false);
new OfferedRideCardViewHolder(v);
}
});
return new OfferedRideCardViewHolder(view);
and OfferedRideCardViewHolder class:
class OfferedRideCardViewHolder extends BaseRideViewHolder {
#BindView(R.id.imgVechicleImage) ImageView imgVechicle;
#BindView(R.id.imgRideIcon) ImageView imgRideIcon;
#BindView(R.id.fromTextView) TextView txtFromLocation;
#BindView(R.id.toTextView) TextView txtToLocation;
#BindView(R.id.txtVichecleModel) TextView txtVichecleModel;
#BindView(R.id.txtRegisterationNo) TextView txtRegisterationNo;
#BindView(R.id.txtDateTime) TextView txtDateTime;
#BindView(R.id.buttonStartEnd) Button startEndRideButton;
#BindView(R.id.matchCountTextView) TextView matchCountTextView;
#BindView(R.id.matchesTextView) TextView matchesTextView;
#BindView(R.id.vehicleContainer) LinearLayout vehicleContainer;
OfferedRideCardViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
item_upcoming_share_ride.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/cv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="4dp"
app:cardCornerRadius="4dp">
<com.daimajia.swipe.SwipeLayout
android:id="#+id/sample2"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:tag="Bottom2"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<ImageView
android:id="#+id/edit"
android:src="#drawable/edit"
android:layout_width="70dp"
android:background="#00FF00"
android:paddingLeft="25dp"
android:paddingRight="25dp"
android:layout_height="match_parent" />
<ImageView
android:id="#+id/delete"
android:src="#drawable/delete_grey"
android:layout_width="70dp"
android:background="#FF0000"
android:paddingLeft="25dp"
android:paddingRight="25dp"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:id="#+id/llMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
>
<View
android:id="#+id/view"
android:layout_width="16dp"
android:layout_height="0dp"
android:layout_marginStart="16dp"
android:background="#drawable/vetical_rounded_corner_orange_background"
app:layout_constraintBottom_toBottomOf="#+id/toTextView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/fromTextView"
/>
<TextView
android:id="#+id/fromTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="12dp"
android:layout_marginTop="16dp"
android:ellipsize="end"
android:fontFamily="#font/lato_regular"
android:maxLines="1"
android:text="Sector 39A, Sector 32, Sector 39, Noida, Uttar Pradesh 201303"
android:textColor="#color/secondary_text"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/view"
app:layout_constraintTop_toTopOf="parent"
/>
<TextView
android:id="#+id/toTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:ellipsize="end"
android:fontFamily="#font/lato_regular"
android:maxLines="1"
android:text="Sector 39A, Sector 32, Sector 39, Noida, Uttar Pradesh 201303"
android:textColor="#color/secondary_text"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="#+id/fromTextView"
app:layout_constraintStart_toStartOf="#+id/fromTextView"
app:layout_constraintTop_toBottomOf="#+id/fromTextView"
/>
<ImageView
android:id="#+id/from_dot_view"
android:layout_width="8dp"
android:layout_height="8dp"
android:src="#drawable/current_location"
android:tint="#color/white"
app:layout_constraintBottom_toBottomOf="#+id/fromTextView"
app:layout_constraintEnd_toEndOf="#+id/view"
app:layout_constraintStart_toStartOf="#+id/view"
app:layout_constraintTop_toTopOf="#+id/fromTextView"
/>
<ImageView
android:id="#+id/to_dot_view"
android:layout_width="8dp"
android:layout_height="wrap_content"
android:src="#drawable/pin_red"
android:tint="#color/white"
app:layout_constraintBottom_toBottomOf="#+id/toTextView"
app:layout_constraintEnd_toEndOf="#+id/view"
app:layout_constraintStart_toStartOf="#+id/view"
app:layout_constraintTop_toTopOf="#+id/toTextView"
/>
<TextView
android:id="#+id/txtDateTime"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
android:fontFamily="#font/montserrat_regular"
android:gravity="center_vertical"
android:text="23rd jan,2016 2.30 pm"
android:textColor="#color/secondary_text"
android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/toTextView"
app:layout_constraintStart_toStartOf="#+id/toTextView"
app:layout_constraintTop_toBottomOf="#+id/view"
/>
<ImageView
android:id="#+id/imageView11"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_marginTop="8dp"
android:adjustViewBounds="true"
android:tint="#color/colorPrimaryLight"
app:layout_constraintBottom_toBottomOf="#+id/txtDateTime"
app:layout_constraintEnd_toEndOf="#+id/view"
app:layout_constraintStart_toStartOf="#+id/view"
app:layout_constraintTop_toBottomOf="#+id/view"
app:srcCompat="#drawable/ic_clock_white_24dp"
/>
</android.support.constraint.ConstraintLayout>
<LinearLayout
android:id="#+id/vehicleContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/dp_10"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingBottom="#dimen/dp_5"
android:paddingLeft="#dimen/dp_10"
android:paddingRight="#dimen/sp_10"
android:paddingTop="#dimen/dp_5"
>
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/imgVechicleImage"
android:layout_width="48dp"
android:layout_height="48dp"
android:src="#drawable/imgcar_fullsize"
tools:layout_editor_absoluteX="18dp"
tools:layout_editor_absoluteY="38dp"
/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical"
>
<TextView
android:id="#+id/txtVichecleModel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_marginStart="8dp"
android:fontFamily="#font/montserrat_regular"
android:text="Camaro 45"
android:textColor="#color/secondary_text"
android:textSize="12sp"
/>
<TextView
android:id="#+id/txtRegisterationNo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="2dp"
android:fontFamily="#font/lato_regular"
android:text="Reg no. 1234"
android:textColor="#color/secondary_text"
android:textSize="12sp"
/>
</LinearLayout>
<android.support.constraint.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:padding="#dimen/dp_5"
>
<ImageView
android:id="#+id/imgRideIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="0dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginStart="8dp"
android:layout_marginTop="0dp"
android:padding="#dimen/dp_5"
android:src="#drawable/driver"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<TextView
android:id="#+id/matchCountTextView"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_marginBottom="4dp"
android:layout_marginTop="8dp"
android:background="#drawable/fill_circle_red"
android:fontFamily="#font/lato_regular"
android:gravity="center"
android:text="5"
android:textColor="#color/white"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="#+id/guideline3"
app:layout_constraintRight_toRightOf="#+id/imgRideIcon"
app:layout_constraintTop_toTopOf="parent"
/>
<android.support.constraint.Guideline
android:id="#+id/guideline3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5"
/>
</android.support.constraint.ConstraintLayout>
</LinearLayout>
<TextView
android:id="#+id/matchesTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:fontFamily="#font/montserrat_regular"
android:padding="4dp"
android:text="You have 12 matches available"
android:textColor="#color/colorAccent"
android:textSize="14sp"
android:visibility="visible"
/>
<!--<Button
android:id="#+id/button_invite"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Invite"
app:font="MontserratRegular"
android:textColor="#color/white"
android:background="#color/colorAccent"
android:layout_marginTop="8dp"
/>-->
<android.support.v7.widget.AppCompatButton
android:id="#+id/buttonStartEnd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginTop="8dp"
android:background="#FF8A65"
android:fontFamily="#font/montserrat_regular"
android:text="Start Ride"
android:textAllCaps="false"
android:textColor="#color/white"
android:textSize="16sp"
android:visibility="visible"
/>
</LinearLayout>
</com.daimajia.swipe.SwipeLayout>
</android.support.v7.widget.CardView>
DisplayMyRideFragmentViewHolder
package com.techugo.buno.fragments;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.CardView;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.daimajia.swipe.SwipeLayout;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.techugo.buno.ActivityNavigator;
import com.techugo.buno.R;
import com.techugo.buno.activities.NewRideActivity;
import com.techugo.buno.activities.RatePassengersActivity;
import com.techugo.buno.app.MyApplication;
import com.techugo.buno.callbacks.RetrofitCallback;
import com.techugo.buno.common.BaseViewHolder;
import com.techugo.buno.common.events.HideLoadingEvent;
import com.techugo.buno.common.events.RefreshDependenciesEvent;
import com.techugo.buno.common.events.ShowLoadingEvent;
import com.techugo.buno.constant.AppConstant;
import com.techugo.buno.constant.ServerConstants;
import com.techugo.buno.dialog.RateDriverDialog;
import com.techugo.buno.helpers.AppUtilis;
import com.techugo.buno.home.events.ShowAddNameDialogEvent;
import com.techugo.buno.home.searchrides.SearchRideFragmentViewHolder;
import com.techugo.buno.home.sharerides.RidesAdapter;
import com.techugo.buno.loginsignup.models.User;
import com.techugo.buno.modals.NotificationResponseModel;
import com.techugo.buno.modals.UpcomingPromoModel;
import com.techugo.buno.modals.UpcomingResultModel;
import com.techugo.buno.networkInterFace.RetrofitApiService;
import com.techugo.buno.offers.OffersActivity;
import com.techugo.buno.ridedetail.Ride;
import com.techugo.buno.ridedetail.events.RideDetailEvents;
import com.techugo.framework.helper.TUGPrefs;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Named;
import butterknife.BindView;
import butterknife.OnClick;
public class DisplayMyRideFragmentViewHolder extends BaseViewHolder<List<Ride>> {
#Inject
RetrofitApiService retrofitApiService;
#Inject #Named("currentLoggedInUser")
User user;
#Inject
ActivityNavigator activityNavigator;
#BindView(R.id.upcomingRidesRecyclerView)
RecyclerView recyclerView;
#BindView(R.id.emptyLayout)
LinearLayout emptyLayout;
#BindView(R.id.text_no_internet_connection)
TextView noInternetTextView;
#BindView(R.id.loading_layout) LinearLayout progressBar;
#BindView(R.id.promo_card_view)
CardView promoCard;
#BindView(R.id.promo_title) TextView promoTitle;
private RidesAdapter ridesAdapter;
private List<Ride> myRidesModels;
private UpcomingPromoModel myPromoModel;
public DisplayMyRideFragmentViewHolder(View view, List<Ride> data, Context context) {
super(view,data,context);
this.myRidesModels = data;
this.context = context;
setUpRecyclerView();
setData(myRidesModels);
}
private void getUpComingRides() {
HashMap<String, Object> params = new HashMap<>();
params.put("method", ServerConstants.ALL_UPCOMING_RIDES);
params.put("user_id", user.getUser_id());
params.put("offset", "0");
params.put("limit", "20");
emptyLayout.setVisibility(View.GONE);
//progressBar.setVisibility(View.VISIBLE);
EventBus.getDefault().post(new ShowLoadingEvent(DisplayMyRideFragmentViewHolder.this.getClass().getSimpleName()));
//DisplayUtils.disableUserInteraction((Activity)context);
retrofitApiService.getUpComingRides(params)
.enqueue(new RetrofitCallback<UpcomingResultModel>() {
#Override protected void onSuccess(UpcomingResultModel upcomingResultModel) {
//progressBar.setVisibility(View.GONE);
EventBus.getDefault()
.post(new HideLoadingEvent(
DisplayMyRideFragmentViewHolder.this.getClass().getSimpleName()));
//DisplayUtils.enableUserInteraction((Activity)context);
myRidesModels.clear();
myRidesModels.addAll(upcomingResultModel.getData());
if(upcomingResultModel.getOffers() != null && upcomingResultModel.getOffers().size() > 0) {
myPromoModel = upcomingResultModel.getOffers().get(0);
promoCard.setVisibility(View.VISIBLE);
promoTitle.setText(myPromoModel.getPromo_title());
} else {
promoCard.setVisibility(View.GONE);
}
TUGPrefs.putString(AppConstant.IS_ANY_ACTIVE,
upcomingResultModel.getActive_ride_status());
initializeView(myRidesModels);
}
#Override protected void onError(String errorMessage) {
//progressBar.setVisibility(View.GONE);
//DisplayUtils.enableUserInteraction((Activity)context);
EventBus.getDefault()
.post(new HideLoadingEvent(
DisplayMyRideFragmentViewHolder.this.getClass().getSimpleName()));
Toast.makeText(context, errorMessage, Toast.LENGTH_SHORT).show();
if (!AppUtilis.isNetworkAvailable(context)) {
emptyLayout.setVisibility(View.GONE);
noInternetTextView.setVisibility(View.VISIBLE);
}
}
});
}
private void setUpRecyclerView() {
ridesAdapter = new RidesAdapter(myRidesModels, context);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(linearLayoutManager);
// recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL));
recyclerView.setAdapter(ridesAdapter);
// ridesAdapter.notifyDataSetChanged();
}
#Override
protected void attachListeners(List<Ride> data) {
}
#Override
protected void initializeView(#NonNull List<Ride> data) {
if (ridesAdapter != null && data.size() != 0) {
emptyLayout.setVisibility(View.GONE);
recyclerView.setVisibility(View.VISIBLE);
ridesAdapter.setData(data);
} else {
recyclerView.setVisibility(View.GONE);
emptyLayout.setVisibility(View.VISIBLE);
}
noInternetTextView.setVisibility(View.GONE);
}
public void refreshView() {
MyApplication.getInstance().getNetComponent().inject(this);
getUpComingRides();
}
#OnClick(R.id.fab_search_ride) void onShareRideFabClick() {
//Intent intent = new Intent(context, FindRideActivity.class);
//context.startActivity(intent);
//if (user.getSignin_type().equals("1") && user.getReg_process().equals("0")) {
// AppUtilis.goToActivity(context, PhoneVerifyActivity.class);
// TUGPrefs.putString("ISFINDRIDE", "yes");
//} else {
//
//}
if (user.getFull_name() == null || user.getFull_name().isEmpty()) {
EventBus.getDefault().post(new ShowAddNameDialogEvent());
return;
}
activityNavigator.startActivity(context, NewRideActivity.class);
}
#OnClick(R.id.promo_card_view) void onPromoCardClick() {
activityNavigator.startActivity(context, OffersActivity.class);
}
#Override public void onStart() {
super.onStart();
EventBus.getDefault().register(this);
refreshView();
}
#Override public void onResume() {
super.onResume();
}
#Override public void onStop() {
super.onStop();
EventBus.getDefault().unregister(this);
}
#Subscribe(threadMode = ThreadMode.MAIN)
public void onReloadComponents(RefreshDependenciesEvent event) {
MyApplication.getInstance().getNetComponent().inject(this);
}
#Subscribe(threadMode = ThreadMode.MAIN)
public void onRideRefresh(RideDetailEvents.RefreshRideDetailEvent event) {
refreshView();
String noty_retrieve = TUGPrefs.getString(AppConstant.IS_RATE_HAS_VALUE, "");
if (noty_retrieve.length() > 0) {
Gson gson = new Gson();
Type type = new TypeToken<NotificationResponseModel>() {
}.getType();
NotificationResponseModel notificationResponseModel = gson.fromJson(noty_retrieve, type);
if (notificationResponseModel != null) {
if (notificationResponseModel.getUser_type() != null
&& notificationResponseModel.getUser_type().equalsIgnoreCase("Driver")) {
Intent intent =
activityNavigator.getIntent(context, RatePassengersActivity.class);
intent.putExtra(AppConstant.NOTY_PASSANGER_DATA, noty_retrieve);
context.startActivity(intent);
} else {
new RateDriverDialog(context, notificationResponseModel).show();
}
}
}
}
}
Toast is working but constructor is not doing anything
I'm trying to find out how to set a string that will be read out-loud.
For example:
String text = "Hello";
You can find a very detail example that show how to convert text to speech on this site. HTH.
Your MainActivity.java should look something like this
import android.app.Activity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import java.util.Locale;
import android.widget.Toast;
public class MainActivity extends Activity {
TextToSpeech t1;
EditText ed1;
Button b1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ed1=(EditText)findViewById(R.id.editText);
b1=(Button)findViewById(R.id.button);
t1=new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
#Override
public void onInit(int status) {
if(status != TextToSpeech.ERROR) {
t1.setLanguage(Locale.UK);
}
}
});
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String toSpeak = ed1.getText().toString();
Toast.makeText(getApplicationContext(), toSpeak,Toast.LENGTH_SHORT).show();
t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
}
});
}
public void onPause(){
if(t1 !=null){
t1.stop();
t1.shutdown();
}
super.onPause();
}
}
And here is the content of activity_main.xml
<?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=".MainActivity"
android:transitionGroup="true">
<TextView android:text="Text to Speech" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textview"
android:textSize="35dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tutorials point"
android:id="#+id/textView"
android:layout_below="#+id/textview"
android:layout_centerHorizontal="true"
android:textColor="#ff7aff24"
android:textSize="35dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:src="#drawable/abc"
android:layout_below="#+id/textView"
android:layout_centerHorizontal="true"
android:theme="#style/Base.TextAppearance.AppCompat" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:layout_below="#+id/imageView"
android:layout_marginTop="46dp"
android:hint="Enter Text"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#ff7aff10"
android:textColorHint="#ffff23d1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text to Speech"
android:id="#+id/button"
android:layout_below="#+id/editText"
android:layout_centerHorizontal="true"
android:layout_marginTop="46dp" />
</RelativeLayout>
Every time i try to type in the edittext everything goes up and the header disappears. How do i make a linearlayaout linear1 stay put when i try to type in the edittext. i also tried adding "android:windowSoftInputMode="adjustPan">" to the manifest and it is still not working.
This is my layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="100"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linear1"
android:weightSum="4"
android:orientation="horizontal"
android:layout_width="0dp"
android:background="#5D4037"
android:layout_height="wrap_content"
android:layout_weight="10"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
>
<ImageView
android:id="#+id/imageView1"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:src="#drawable/ic_launcher"
android:isScrollContainer="false"
android:layout_alignParentLeft="true" />
<TextView
android:id="#+id/user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="51dp"
android:text="TextView"
android:textColor="#f0f0f0"
android:textSize="24sp"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/imageView1"
android:layout_toEndOf="#+id/imageView1"
android:layout_marginStart="51dp" />
</LinearLayout>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/relativeLayout1"
android:background="#f0f0f0"
android:layout_weight="80"
android:layout_below="#+id/linear1">
</ListView>
<LinearLayout
android:id="#+id/relativeLayout1"
android:weightSum="4"
android:orientation="horizontal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="10"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:background="#f0f0f0" >
<EditText
android:id="#+id/mess"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:maxHeight="300dp"
android:clickable="true"
android:layout_weight="3"
android:background="#ffffff"
android:focusableInTouchMode="true"
android:scrollbarSize="40dp" >
<requestFocus />
</EditText>
<ImageButton
android:id="#+id/send"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/ic_send"
android:layout_weight="1" />
</LinearLayout>
</RelativeLayout>
This is me java class
import com.obi.thinker.logins.R;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
public class Chatting extends ListActivity {
EditText mess;
ImageButton send;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.yon);
mess = (EditText) findViewById(R.id.mess);
mess.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
}
}
});
}
}
I don't want the soft keyboard to push the header . it should push only the list view up.
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");
}