Edit Text And Count Down Timer in Android Studio - java

I have a Counttimer and edittext on my app. I want write a number in edittext, and when I click button, then countdown timer will start, and the time is edittext variable. In XML, I have got an example number, because when I delete it, then it's not working. When I start countdown timer, then it works, but if I change edittext, then it uses the old edittext data. How can I solve my problem?
pomodoro.XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".pomodoro"
android:background="#drawable/backround_home">
<
<EditText
android:id="#+id/edittextcalisma"
android:layout_width="80dp"
android:layout_height="40dp"
android:text="20"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="25dp"
android:background="#drawable/edittext"
android:layout_marginLeft="30dp"
android:visibility="visible"
android:inputType="number"
android:maxLength="2"
android:lines="1"
/>
<EditText
android:id="#+id/edittextmola"
android:layout_width="80dp"
android:layout_height="40dp"
android:text="5"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="25dp"
android:background="#drawable/edittext"
android:visibility="visible"
android:layout_marginLeft="30dp"
android:inputType="number"
android:maxLength="2"
android:lines="1"
/>
<Button
android:id="#+id/baslatbutton"
android:layout_width="150dp"
android:layout_height="50dp"
android:text="Başla"
android:textSize="25dp"
android:layout_marginTop="400dp"
android:textColor="#ffffff"
android:fontFamily="#font/montserrat_regular"
android:background="#drawable/button"
android:layout_centerHorizontal="true"
android:visibility="visible"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40dp"
android:layout_centerInParent="true"
android:fontFamily="#font/montserrat_regular"
android:textColor="#000000"
android:id="#+id/pomodoro"
android:visibility="invisible"
/>
</RelativeLayout>
Java.class
public class pomodoro extends AppCompatActivity {
Button baslat;
EditText edittextcalisma,edittextmola;
TextView textcalisma,textmola,pomodoro;
CountDownTimer calisma,mola;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pomodoro);
baslat = findViewById(R.id.baslatbutton);
edittextcalisma = findViewById(R.id.edittextcalisma);
edittextmola = findViewById(R.id.edittextmola);
textcalisma = findViewById(R.id.textcalisma);
textmola = findViewById(R.id.textmola);
String timercalisma = edittextcalisma.getText().toString();
String timermola = edittextmola.getText().toString();
long calismapo = Long.parseLong(timercalisma) * 60000;
long molapo = Long.parseLong(timermola) * 60000;
pomodoro = findViewById(R.id.pomodoro);
baslat.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
pomodoro.setVisibility(View.VISIBLE);
calisma.start();
}
});
calisma = new CountDownTimer(calismapo, 1000) {
#Override
public void onTick(long millis) {
int minuted1 = (int) (millis / 1000) / 60;
int secondd1 = (int) (millis / 1000) % 60;
pomodoro.setText(minuted1 + ":" + secondd1);
if (secondd1 < 10) {
pomodoro.setText(minuted1 + ":0" + secondd1);
}
}
#Override
public void onFinish() {
calisma.cancel();
mola.start();
}
};
mola = new CountDownTimer(molapo, 1000) {
#Override
public void onTick(long molapo) {
int minuted1 = (int) (molapo / 1000) / 60;
int secondd1 = (int) (molapo / 1000) % 60;
pomodoro.setText(minuted1 + ":" + secondd1);
if (secondd1 < 10) {
pomodoro.setText(minuted1 + ":0" + secondd1);
}
}
#Override
public void onFinish() {
mola.cancel();
pomodoro.setText("Bitti");
}
};
}
}

and the time is edittext variable. In XML, I have got an example
number, because when I delete it, then it's not working.
Because you read your EditText fields in the onCreate and your code expects a number, then that is why you need to set the "example" numbers in XML.
When you remove the number from XML, you either need to:
check for null
String timercalisma = edittextcalisma.getText().toString();
String timermola = edittextmola.getText().toString();
if(timercalisma == null || timercalisma.isEmpty()) {
timercalisma = "0";
}
if(timermola == null || timermola.isEmpty()) {
timermola = "0";
}
long calismapo = Long.parseLong(timercalisma) * 60000;
long molapo = Long.parseLong(timermola) * 60000;
or read the fields on button press
baslat.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String timercalisma = edittextcalisma.getText().toString();
String timermola = edittextmola.getText().toString();
long calismapo = Long.parseLong(timercalisma) * 60000;
long molapo = Long.parseLong(timermola) * 60000;
pomodoro.setVisibility(View.VISIBLE);
calisma.start();
}
});

Related

Recyclerview is Scrolling when media Player is playing. How can i fix it?

I'm developing a ChatApp with the function of Audio Messages. The Recording and playing of this Audio Messages are working very well, but if i click on Play Button the Recyclerview is scrolling up. Anyone have an idea?
Sorry for my bad english, i'm from Germany ;)
AdapterChat.Java
private static final int MSG_TYPE_LEFT = 0;
private static final int MSG_TYPE_RIGHT = 1;
Context context;
List<ModelChat> chatList;
String imageUrl;
FirebaseUser fUser;
public AdapterChat(Context context, List<ModelChat> chatList, String imageUrl) {
this.context = context;
this.chatList = chatList;
this.imageUrl = imageUrl;
}
#NonNull
#Override
public MyHolder onCreateViewHolder(#NonNull ViewGroup viewGroup, int i) {
//inflate layouts: row_chat_left.xml for receiver, row_chat_right.xml for sender
if (i == MSG_TYPE_RIGHT) {
View view = LayoutInflater.from(context).inflate(R.layout.row_chat_right, viewGroup, false);
return new MyHolder(view);
}
else {
View view = LayoutInflater.from(context).inflate(R.layout.row_chat_left, viewGroup, false);
return new MyHolder(view);
}
}
public void add(ModelChat object) {
chatList.add(object);
add(object);
}
#SuppressLint("ClickableViewAccessibility")
#Override
public void onBindViewHolder(#NonNull final MyHolder myHolder, final int i) {
final String message = chatList.get(i).getMessage();
String timeStamp = chatList.get(i).getTimestamp();
String type = chatList.get(i).getType();
if (type.equals("text") || message.equals(R.string.message_was_deleted)) {
//text message
myHolder.messageTv.setVisibility(View.VISIBLE);
myHolder.messageIv.setVisibility(View.GONE);
myHolder.playAudioBtn.setVisibility(View.GONE);
myHolder.messageVoiceSb.setVisibility(View.GONE);
myHolder.sbCurrentTime.setVisibility(View.GONE);
myHolder.sbTotalDuration.setVisibility(View.GONE);
myHolder.messageTv.setText(message);
}
else if (type.equals("audio")) {
//audio message
myHolder.messageTv.setVisibility(View.GONE);
myHolder.messageIv.setVisibility(View.GONE);
myHolder.playAudioBtn.setVisibility(View.VISIBLE);
myHolder.messageVoiceSb.setVisibility(View.VISIBLE);
myHolder.sbCurrentTime.setVisibility(View.VISIBLE);
myHolder.sbTotalDuration.setVisibility(View.VISIBLE);
myHolder.voiceMessageUrl = message;
myHolder.getAdapterPosition();
myHolder.playAudioBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (myHolder.mediaPlayer.isPlaying()) {
myHolder.handler.removeCallbacks(myHolder.updater);
myHolder.mediaPlayer.pause();
myHolder.playAudioBtn.setImageResource(R.drawable.ic_play_btn);
}
else {
myHolder.mediaPlayer.start();
myHolder.playAudioBtn.setImageResource(R.drawable.ic_pause_btn);
myHolder.updateSeekbar();
}
}
});
myHolder.prepareMediaPlayer();
myHolder.messageVoiceSb.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View view, MotionEvent motionEvent) {
SeekBar seekBar = (SeekBar) view;
int playPosition = (myHolder.mediaPlayer.getDuration() / 100) * seekBar.getProgress();
myHolder.mediaPlayer.seekTo(playPosition);
myHolder.sbCurrentTime.setText(myHolder.milliSecondsToTimer(myHolder.mediaPlayer.getCurrentPosition()));
return false;
}
});
myHolder.mediaPlayer.setOnBufferingUpdateListener(new MediaPlayer.OnBufferingUpdateListener() {
#Override
public void onBufferingUpdate(MediaPlayer mediaPlayer, int i) {
myHolder.messageVoiceSb.setSecondaryProgress(i);
}
});
myHolder.mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mediaPlayer) {
myHolder.messageVoiceSb.setProgress(0);
myHolder.playAudioBtn.setImageResource(R.drawable.ic_play_btn);
myHolder.mediaPlayer.reset();
myHolder.prepareMediaPlayer();
}
});
}
else {
//image message
myHolder.messageIv.setVisibility(View.VISIBLE);
myHolder.messageTv.setVisibility(View.GONE);
myHolder.playAudioBtn.setVisibility(View.GONE);
myHolder.messageVoiceSb.setVisibility(View.GONE);
myHolder.sbCurrentTime.setVisibility(View.GONE);
myHolder.sbTotalDuration.setVisibility(View.GONE);
Picasso.get().load(message).placeholder(R.drawable.ic_image_black).into(myHolder.messageIv);
}
//set data
myHolder.messageTv.setText(message);
myHolder.timeTv.setText(timeStamp);
try {
Picasso.get().load(imageUrl).into(myHolder.profileIv);
}
catch (Exception e) {
}
myHolder.messageLayout.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
//show delete message confirm dialog
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.delete);
builder.setMessage("Are you sure to delete this message?");
//delete button
builder.setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
deleteMessage(i);
}
});
//cancel delete button
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
//dismiss dialog
dialog.dismiss();
}
});
//create and show dialog
builder.create().show();
return false;
}
});
//set seen/delivered status of message
if (i==chatList.size()-1) {
if (chatList.get(i).isSeen()) {
myHolder.isSeenTv.setText("Seen");
}
else {
myHolder.isSeenTv.setText("Delivered");
}
}
else {
myHolder.isSeenTv.setVisibility(View.GONE);
}
}
private void deleteMessage(int position) {
final String myUID = FirebaseAuth.getInstance().getCurrentUser().getUid();
/*Logic:
* Get timeStamp of clicked message
* Compare the timeStamp of the clicked message with all messages in CHats
* Where both values matches, delete that message
* This will allow sender to delete his and receiver's message*/
String msgTimeStamp = chatList.get(position).getTimestamp();
final String type = chatList.get(position).getType();
DatabaseReference dbRef = FirebaseDatabase.getInstance().getReference("Chats");
Query query = dbRef.orderByChild("timestamp").equalTo(msgTimeStamp);
query.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot ds: dataSnapshot.getChildren()) {
/*if you want to allow sender to delete only his message then
* compare sender value with current user's uid
* if they match means its the message of sender that is trying to delete*/
if (ds.child("sender").getValue().equals(myUID)) {
if (type.equals("audio")) {
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("type", "text");
ds.getRef().updateChildren(hashMap);
} else if (type.equals("image")) {
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("type", "text");
ds.getRef().updateChildren(hashMap);
}
/*We can do one of two things here
* 1) Remove the message from chats
* 2) Set the value of message "This messages was deleted..." */
//1) Remove the message from Chats
//ds.getRef().removeValue();
//2) Set the value of message "This message was deleted..."
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("message", "This message was deleted...");
ds.getRef().updateChildren(hashMap);
Toast.makeText(context, "message deleted...", Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(context, "You can delete only your messages...", Toast.LENGTH_SHORT).show();
}
}
}
#Override
public void onCancelled(#NonNull DatabaseError error) {
}
});
}
#Override
public int getItemCount() {
return chatList.size();
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public int getItemViewType(int position) {
//get currently signed in user
fUser = FirebaseAuth.getInstance().getCurrentUser();
if (chatList.get(position).getSender().equals(fUser.getUid())) {
return MSG_TYPE_RIGHT;
}
else {
return MSG_TYPE_LEFT;
}
}
//view holder class
class MyHolder extends RecyclerView.ViewHolder {
//views
ImageView profileIv, messageIv;
ImageButton playAudioBtn;
SeekBar messageVoiceSb;
TextView messageTv, timeTv, isSeenTv, sbCurrentTime, sbTotalDuration;
LinearLayout messageLayout; //for click listener to show delete option
MediaPlayer mediaPlayer;
Handler handler = new Handler();
String voiceMessageUrl = null;
#SuppressLint("ClickableViewAccessibility")
public MyHolder(#NonNull View itemView) {
super(itemView);
//init views
profileIv = itemView.findViewById(R.id.profileIv);
messageIv = itemView.findViewById(R.id.messageIV);
messageTv = itemView.findViewById(R.id.messageTv);
messageVoiceSb = itemView.findViewById(R.id.messageVoiceSb);
playAudioBtn = itemView.findViewById(R.id.playAudioBtn);
sbCurrentTime = itemView.findViewById(R.id.sbCurrentTime);
sbTotalDuration = itemView.findViewById(R.id.sbTotalDuration);
timeTv = itemView.findViewById(R.id.timeTv);
isSeenTv = itemView.findViewById(R.id.isSeenTv);
messageLayout = itemView.findViewById(R.id.messageLayout);
mediaPlayer = new MediaPlayer();
messageVoiceSb.setMax(100);
}
private void prepareMediaPlayer() {
try {
mediaPlayer.setDataSource(voiceMessageUrl); //url of audio file to play
mediaPlayer.prepare();
sbTotalDuration.setText(milliSecondsToTimer(mediaPlayer.getDuration()));
} catch (Exception e) {
Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
private Runnable updater = new Runnable() {
#Override
public void run() {
updateSeekbar();
long currentDuration = mediaPlayer.getCurrentPosition();
sbCurrentTime.setText(milliSecondsToTimer(currentDuration));
}
};
private void updateSeekbar() {
if (mediaPlayer.isPlaying()) {
messageVoiceSb.setProgress((int) (((float) mediaPlayer.getCurrentPosition() / mediaPlayer.getDuration()) * 100));
handler.postDelayed(updater, 1000);
}
}
private String milliSecondsToTimer(long milliSeconds) {
String timerString = "";
String secondsString;
int hours = (int) (milliSeconds / (1000 * 60 * 60));
int minutes = (int) (milliSeconds % (1000 * 60 * 60)) / (1000 * 60);
int seconds = (int) ((milliSeconds % (1000 * 60 * 60)) % (1000 * 60) / 1000);
if (hours > 0) {
timerString = hours + ":";
}
if (seconds < 10) {
secondsString = "0" + seconds;
} else {
secondsString = "" + seconds;
}
timerString = timerString + minutes + ":" + secondsString;
return timerString;
}
}
chatActivity.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/chatBackground"
tools:context=".ChatActivity">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="#color/colorPrimaryDark"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/profileIv"
android:layout_width="35dp"
android:layout_height="35dp"
android:scaleType="centerCrop"
android:src="#drawable/ic_default"
app:civ_circle_background_color="#color/colorPrimaryDark"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:layout_marginStart="20dp">
<!-- Receiver Name-->
<TextView
android:id="#+id/nameTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="His Name"
android:textColor="#color/colorWhite"
android:textSize="18sp"
android:textStyle="bold" />
<!-- Receiver Status i.e online or offline-->
<TextView
android:id="#+id/userStatusTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="online"
android:textColor="#color/colorWhite"
android:textSize="12sp"
android:textStyle="bold" />
</LinearLayout>
<ImageView
android:id="#+id/blockIv"
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="5dp"
android:src="#drawable/ic_unblocked_green"
android:visibility="invisible"/>
</LinearLayout>
</androidx.appcompat.widget.Toolbar>
<!-- RecyclerView-->
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/chat_recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/toolbar"
android:layout_above="#id/chatLayout" />
<!-- send message edit text and button in layout-->
<LinearLayout
android:id="#+id/chatLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center"
android:background="#color/textInputBackground"
android:orientation="horizontal">
<!-- ImageButton: to send Image-->
<ImageButton
android:id="#+id/attachBtn"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#null"
android:src="#drawable/ic_attach_black" />
<!-- EditText: input message-->
<EditText
android:id="#+id/messageEt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#null"
android:inputType="textCapSentences|textMultiLine"
android:padding="15dp"
android:hint="Start typing" />
<Chronometer
android:id="#+id/record_timer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:textSize="14sp"
android:textColor="#color/colorPrimary" />
<!-- Button: voice message-->
<ImageButton
android:id="#+id/recordBtn"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#null"
android:src="#drawable/ic_record_btn_stopped" />
<!-- Button: send message-->
<ImageButton
android:id="#+id/sendBtn"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#null"
android:src="#drawable/ic_send" />
</LinearLayout>
row_chat_right.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:id="#+id/messageLayout"
android:padding="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="end">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/profileIv"
app:civ_border_color="#null"
android:visibility="gone"
android:src="#drawable/ic_default_img" />
<TextView
android:id="#+id/messageTv"
android:layout_weight="1"
android:textSize="16sp"
android:textColor="#color/textColor"
android:background="#drawable/bg_sender"
android:padding="15dp"
android:text="His Message"
android:visibility="gone"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/messageIV"
android:layout_width="200dp"
android:layout_height="200dp"
android:adjustViewBounds="true"
android:padding="15dp"
android:src="#drawable/ic_image_black"
android:scaleType="fitCenter"
android:background="#drawable/bg_sender" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/bg_sender"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/playAudioBtn"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginTop="20dp"
android:background="#null"
android:src="#drawable/ic_play_btn" />
<SeekBar
android:id="#+id/messageVoiceSb"
android:visibility="gone"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/playAudioBtn"
android:padding="10dp"
android:layout_marginTop="10dp"
android:max="100"
android:progress="0" />
<TextView
android:id="#+id/sbCurrentTime"
android:visibility="gone"
android:text="0:00"
android:textStyle="bold"
android:textSize="12sp"
android:layout_marginStart="2dp"
android:layout_below="#id/messageVoiceSb"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/sbTotalDuration"
android:visibility="gone"
android:textStyle="bold"
android:text="0:10"
android:textSize="12sp"
android:layout_below="#id/messageVoiceSb"
android:layout_toEndOf="#id/messageVoiceSb"
android:layout_marginEnd="12dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</LinearLayout>
<TextView
android:id="#+id/timeTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:textAlignment="textEnd"
android:text="07/08/2020 23:00PM"
android:textColor="#color/textColor"
android:textSize="12sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/isSeenTv"
android:gravity="end"
android:textAlignment="textEnd"
android:text="delivered" />
Here is the Fix!!
<TextView
android:layout_width="match_parent" <-- This is what I changed
android:layout_height="wrap_content"/>
<SeekBar
android:layout_width="match_parent" <-- Check this as well
android:layout_height="wrap_content"/>

Splash Screen Android - Count Down Timer Display

I am trying to use splash screen for my app.
I want to display Count down timer in my splash screen.
So far I am able to achieve the splash screen working but don't know how to display count down timer. I created layout for count down timer. I want splash screen to stay for 5 Hours then take to the next activity.
Splashactivity.java
public class splash_screen extends AppCompatActivity {
private float imageAplha = 1f;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_screen);
//splashScreenUseTimer(5000);
splashScreenUseAsyncTask();
}
// Show splash screen until network load data complete.
private void splashScreenUseAsyncTask()
{
// Create a AsyncTask object.
final RetrieveDateTask retrieveDateTask = new RetrieveDateTask();
retrieveDateTask.execute("", "", "");
// Get splash image view object.
final ImageView splashImageView = (ImageView) findViewById(R.id.logo_id);
// Create a count down timer object.It will count down every 0.1 seconds and last for milliSeconds milliseconds..
CountDownTimer countDownTimer = new CountDownTimer(5000, 100) {
#Override
public void onTick(long l) {
// Reduce the splash screen background image's alpha value for each count down.
splashImageView.setAlpha(imageAplha);
imageAplha -= 0.1;
if(imageAplha <= 0)
{
imageAplha = 1;
}
}
#Override
public void onFinish() {
// When count down complete, set the image to invisible.
imageAplha = 0;
splashImageView.setAlpha(imageAplha);
// If AsyncTask is not complete, restart the counter to count again.
if(!retrieveDateTask.isAsyncTaskComplete()) {
this.start();
}
}
};
// Start the count down timer.
countDownTimer.start();
}
// This is the async task class that get data from network.
private class RetrieveDateTask extends AsyncTask<String, String, String>{
// Indicate whether AsyncTask complete or not.
private boolean asyncTaskComplete = false;
public boolean isAsyncTaskComplete() {
return asyncTaskComplete;
}
public void setAsyncTaskComplete(boolean asyncTaskComplete) {
this.asyncTaskComplete = asyncTaskComplete;
}
// This method will be called before AsyncTask run.
#Override
protected void onPreExecute() {
this.asyncTaskComplete = false;
}
// This method will be called when AsyncTask run.
#Override
protected String doInBackground(String... strings) {
try {
// Simulate a network operation which will last for 10 seconds.
Thread currTread = Thread.currentThread();
for (int i = 0; i < 10; i++) {
currTread.sleep(1000);
}
}catch(Exception ex)
{
ex.printStackTrace();
}finally {
return null;
}
}
// This method will be called after AsyncTask run.
#Override
protected void onPostExecute(String s) {
// Start SplashScreenMainActivity.
Intent mainIntent = new Intent(splash_screen.this,
MainActivity.class);
splash_screen.this.startActivity(mainIntent);
// Close SplashScreenActivity.
splash_screen.this.finish();
this.asyncTaskComplete = true;
}
}
}
Layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0"
android:background="#color/White"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:id="#+id/logo_id"
android:layout_width="350dp"
android:layout_height="match_parent"
app:srcCompat="#drawable/ts_logo"
android:layout_gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="vertical">
<LinearLayout
android:id="#+id/linear_layout_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/black"
android:visibility="visible">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/tv_hour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="00"
android:textColor="#android:color/white"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_hour_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Hour"
android:textColor="#android:color/white"
android:textSize="20dp"
android:textStyle="normal" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/tv_minute"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="00"
android:textColor="#android:color/white"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_minute_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Minute"
android:textColor="#android:color/white"
android:textSize="20dp"
android:textStyle="normal" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/tv_second"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="00"
android:textColor="#android:color/white"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_second_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Second"
android:textColor="#android:color/white"
android:textSize="20dp"
android:textStyle="normal" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
#contact dummy I edited #Dev code with small modification.try this one. Based on your animation requirement increase and decrease imageAlpha size.
private float imageAplha = 1f;
private boolean imageStatus = false;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
splashScreenUseAsyncTask();
}
// Show splash screen until network load data complete.
private void splashScreenUseAsyncTask()
{
// Create a AsyncTask object.
final RetrieveDateTask retrieveDateTask = new RetrieveDateTask();
retrieveDateTask.execute("", "", "");
// Get splash image view object.
final ImageView splashImageView = (ImageView) findViewById(R.id.logo_id);
final TextView tv_hour = (TextView) findViewById(R.id.tv_hour);
final TextView tv_minute = (TextView) findViewById(R.id.tv_minute);
final TextView tv_second = (TextView) findViewById(R.id.tv_second);
// Create a count down timer object.It will count down every 0.1 seconds and last for milliSeconds milliseconds..
final int time= 3600000*5;
CountDownTimer countDownTimer = new CountDownTimer(time, 1000) {
#Override
public void onTick(long l) {
long Days = l / (24 * 60 * 60 * 1000);
long Hours = l / (60 * 60 * 1000) % 24;
long Minutes = l / (60 * 1000) % 60;
long Seconds = l / 1000 % 60;
//
// tv_days.setText(String.format("%02d", Days));
tv_hour.setText(String.format("%02d", Hours));
tv_minute.setText(String.format("%02d", Minutes));
tv_second.setText(String.format("%02d", Seconds));
splashImageView.setAlpha(imageAplha);
if(imageStatus){
imageAplha += 1;
if(imageAplha >= 1)
{
// imageAplha-= 0.5;
imageStatus = false;
}
}else{
imageAplha -= 1;
if(imageAplha <= 0)
{
imageStatus = true;
}
}
}
#Override
public void onFinish() {
// When count down complete, set the image to invisible.
imageAplha = 0;
splashImageView.setAlpha(imageAplha);
// If AsyncTask is not complete, restart the counter to count again.
if(!retrieveDateTask.isAsyncTaskComplete()) {
this.start();
}
}
};
// Start the count down timer.
countDownTimer.start();
}
// This is the async task class that get data from network.
private class RetrieveDateTask extends AsyncTask<String, String, String> {
// Indicate whether AsyncTask complete or not.
private boolean asyncTaskComplete = false;
public boolean isAsyncTaskComplete() {
return asyncTaskComplete;
}
public void setAsyncTaskComplete(boolean asyncTaskComplete) {
this.asyncTaskComplete = asyncTaskComplete;
}
// This method will be called before AsyncTask run.
#Override
protected void onPreExecute() {
this.asyncTaskComplete = false;
}
// This method will be called when AsyncTask run.
#Override
protected String doInBackground(String... strings) {
try {
// Simulate a network operation which will last for 10 seconds.
Thread currTread = Thread.currentThread();
for (int i = 0; i < 18000000; i++) {
currTread.sleep(1000);
}
}catch(Exception ex)
{
ex.printStackTrace();
}finally {
return null;
}
}
// This method will be called after AsyncTask run.
#Override
protected void onPostExecute(String s) {
// Start SplashScreenMainActivity.
Intent mainIntent = new Intent(splash_screen .this,
MainActvity.class);
splash_screen.this.startActivity(mainIntent);
// Close SplashScreenActivity.
splash_screen.this.finish();
this.asyncTaskComplete = true;
}
}
}
#contact dummy I have edited your code try using this
// Show splash screen until network load data complete.
private void splashScreenUseAsyncTask()
{
// Create a AsyncTask object.
final RetrieveDateTask retrieveDateTask = new RetrieveDateTask();
retrieveDateTask.execute("", "", "");
// Get splash image view object.
final ImageView splashImageView = (ImageView) findViewById(R.id.logo_id);
//for 5 Hours
final int time= 3600000*5;
CountDownTimer countDownTimer = new CountDownTimer(time, 1000) {
#Override
public void onTick(long l) {
long Days = l / (24 * 60 * 60 * 1000);
long Hours = l / (60 * 60 * 1000) % 24;
long Minutes = l / (60 * 1000) % 60;
long Seconds = l / 1000 % 60;
//
tv_days.setText(String.format("%02d", Days));
tv_hour.setText(String.format("%02d", Hours));
tv_minute.setText(String.format("%02d", Minutes));
tv_second.setText(String.format("%02d", Seconds));
splashImageView.setAlpha(imageAplha);
imageAplha -= 0.1;
if(imageAplha <= 0)
{
imageAplha = 1;
}
}
#Override
public void onFinish() {
// When count down complete, set the image to invisible.
imageAplha = 0;
splashImageView.setAlpha(imageAplha);
// If AsyncTask is not complete, restart the counter to count again.
if(!retrieveDateTask.isAsyncTaskComplete()) {
this.start();
}
}
};
// Start the count down timer.
countDownTimer.start();
}

How to efficiently put a multitude of stopwatches on one activity?

I made a single working stopwatch, but I can't figure out a way to add several to the same page. What would be an effective way to do this? I tried copying the code and changing all the parameters but that did not seem to work.
The code I have at the moment:
XML
<RelativeLayout
android:layout_width="368dp"
android:layout_height="495dp"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
<EditText
android:id="#+id/topTextInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:layout_toLeftOf="#+id/timeOne"
android:layout_toStartOf="#+id/timeOne"
android:width="300dp"
android:elevation="1dp" />
<TextView
android:id="#+id/timeOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/topTextInput"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="13dp"
android:layout_marginRight="13dp"
android:layout_marginTop="50dp"
android:clickable="false"
android:elevation="4dp"
android:text="00:00:00"
android:textSize="24sp"
android:visibility="visible" />
<Button
android:id="#+id/stopbuttonOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/topTextInput"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/topTextInput"
android:layout_toEndOf="#+id/topTextInput"
android:layout_toRightOf="#+id/topTextInput"
android:width="110dp"
android:background="#android:color/darker_gray"
android:onClick="stopClick"
android:text=""
android:visibility="invisible" />
<Button
android:id="#+id/startbuttonOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/topTextInput"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/topTextInput"
android:layout_toEndOf="#+id/topTextInput"
android:layout_toRightOf="#+id/topTextInput"
android:width="120dp"
android:onClick="startClick"
android:text=""
android:visibility="visible" />
<Button
android:id="#+id/resetButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Reset"
android:onClick="resetClick" />
<TextView
android:id="#+id/millitimeOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/timeOne"
android:visibility="visible" />
</RelativeLayout>
Java:
package com.keur.joran.time;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity
{
private TextView tempTextView; //Temporary TextView
private Button tempBtn; //Temporary Button
private Handler mHandler = new Handler();
private Handler m2Handler = new Handler();
private long startTime;
private long elapsedTime;
private long start2Time;
private long elapsed2Time;
private final int REFRESH_RATE = 100;
private String hours,minutes,seconds,milliseconds;
private long secs,mins,hrs,msecs;
private boolean stopped = false;
private Runnable startTimer = new Runnable() { public void run() { elapsedTime = System.currentTimeMillis() - startTime; updateTimer(elapsedTime); mHandler.postDelayed(this,REFRESH_RATE); } };
private Runnable start2Timer = new Runnable() { public void run() { elapsed2Time = System.currentTimeMillis() - start2Time; updateTimer(elapsed2Time); mHandler.postDelayed(this,REFRESH_RATE); } };
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void stopClick (View view){ hideStopButton(); mHandler.removeCallbacks(startTimer); stopped = true; }
public void startClick (View view){ showStopButton(); if(stopped){ startTime = System.currentTimeMillis() - elapsedTime; } else{ startTime = System.currentTimeMillis(); } mHandler.removeCallbacks(startTimer); mHandler.postDelayed(startTimer, 0); }
public void resetClick (View view){ stopped = false; ((TextView)findViewById(R.id.timeOne)).setText("00:00:00"); ((TextView)findViewById(R.id.millitimeOne)).setText(".0"); }
private void showStopButton(){ ((Button)findViewById(R.id.startbuttonOne)).setVisibility(View.GONE);
((Button)findViewById(R.id.stopbuttonOne)).setVisibility(View.VISIBLE);
}
private void hideStopButton(){ ((Button)findViewById(R.id.startbuttonOne)).setVisibility(View.VISIBLE);
((Button)findViewById(R.id.stopbuttonOne)).setVisibility(View.GONE);
}
private void updateTimer (float time){ secs = (long)(time/1000);
mins = (long)((time/1000)/60); hrs = (long)(((time/1000)/60)/60);
/* Convert the seconds to String * and format to ensure it has * a leading zero when required */
secs = secs % 60;seconds=String.valueOf(secs);
if(secs == 0){ seconds = "00"; } if(secs <10 && secs > 0){ seconds = "0"+seconds;
}
/* Convert the minutes to String and format the String */ mins = mins % 60; minutes=String.valueOf(mins); if(mins == 0){ minutes = "00"; } if(mins <10 && mins > 0){ minutes = "0"+minutes; } /* Convert the hours to String and format the String */ hours=String.valueOf(hrs); if(hrs == 0){ hours = "00"; } if(hrs <10 && hrs > 0){ hours = "0"+hours; } /* Although we are not using milliseconds on the timer in this example * I included the code in the event that you wanted to include it on your own */ milliseconds = String.valueOf((long)time); if(milliseconds.length()==2){ milliseconds = "0"+milliseconds; } if(milliseconds.length()<=1){ milliseconds = "00"; } milliseconds = milliseconds.substring(milliseconds.length()-3, milliseconds.length()-2); /* Setting the timer text to the elapsed time */ ((TextView)findViewById(R.id.timeOne)).setText(hours + ":" + minutes + ":" + seconds); ((TextView)findViewById(R.id.millitimeOne)).setText("." + milliseconds); }
}
Turn the stopwatch into either a custom view or fragment. Then you should only need to include the view/fragment in the xml, and call the appropriate event handler functions you added in the java code.

The timer not let the user to edit

I'm a begginer and i build a timer app and i want the app to allow the user to edit the time. like in the android build in timer. and i wrote the code and it not really works it's show like it can be edit but when i'm trying to write something, it's change for a sec and go back to what it's been before..
xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_stopwatch"
android:layout_width="match_parent"
android:layout_height="match_parent"
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="com.adir.stopwatch.StopwatchActivity"
android:background="#000000"
>
<Button
android:id="#+id/reset_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClickReset"
android:text="#string/reset"
android:textColor="#FFFFFF"
android:layout_below="#+id/stop_button"
android:layout_alignLeft="#+id/stop_button"
android:layout_alignStart="#+id/stop_button" />
<EditText
android:id="#+id/time_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="17dp"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="92sp"
android:textColor="#FFFFFF"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:inputType="time"
/>
<Button
android:id="#+id/start_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClickStart"
android:text="#string/start"
android:textColor="#FFFFFF"
android:layout_below="#+id/time_view"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp" />
<Button
android:id="#+id/stop_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClickStop"
android:text="#string/stop"
android:textColor="#FFFFFF"
android:layout_alignLeft="#+id/start_button"
android:layout_alignStart="#+id/start_button"
android:layout_below="#+id/start_button"></Button>
</RelativeLayout>
Java:
public class StopwatchActivity extends Activity {
private int seconds=0;
private boolean running;
private boolean wasRunning;
public String time;
public int hours=seconds/3600;
public int minutes=(seconds%3600)/60;
public int secs=seconds%60;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_stopwatch);
if(savedInstanceState!=null){
seconds=savedInstanceState.getInt("seconds");
running=savedInstanceState.getBoolean("running");
wasRunning=savedInstanceState.getBoolean("wasRunning");
}
runTimer();
}
public void onClickStart(View view) {
running = true;
}
protected void onStop(){
super.onStop();
wasRunning=running;
running=false;
}
protected void onStart() {
super.onStart();
if(wasRunning){
running=true;
}
}
public void onClickStop(View view) {
running = false;
}
public void onClickReset(View view) {
running = false;
seconds = 0;
}
private void runTimer() {
final EditText timeView = (EditText) findViewById(R.id.time_view);
time=timeView.getText().toString();
final Handler handler = new Handler();
handler.post(new Runnable() {
#Override
public void run() {
time = String.format("%d:%02d:%02d",hours, minutes, secs);
timeView.setText(time);
if (running) {
seconds--;
}
handler.postDelayed(this, 1000);
}
});
}
public void onSaveInstanceState(Bundle savedInstanceState){
savedInstanceState.putInt("seconds",seconds);
savedInstanceState.putBoolean("running",running);
savedInstanceState.putBoolean("wasRunning",wasRunning);
}
protected void onPause(){
super.onPause();
wasRunning=running;
running=false;
}
protected void onResume(){
super.onResume();
if(wasRunning){
running=true;
}
}
}
What do i need to fix?
The code below will give you a good idea of what to do. When you click the button, it will get the text of the EditText and put it into string. Then it will convert into int. Then you can put the new int variable time into your CountDownTimer function's 1st parameter to set the length of the timer.
Button submit;
TextView timerText;
EditText editTextTime;
CountdownTimer yourTimer;
String timeString;
int time;
submit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
timeString = String.valueOf(editTextTime.getText());
time = Integer.valueOf(timeString);
}
});
yourTimer = new CountDownTimer(time, 1000) {
#Override
public void onTick(long millisUntilFinished) {
int seconds = (int) millisUntilFinished / 1000;
int minutes = seconds / 60;
seconds %= 60;
minutes %= 60;
if (seconds < 10 && seconds >= 1) {
timerText.setText("" + seconds);
}
}
#Override
public void onFinish() {
}
}.start();

setMinimumHeight() on LinearLayout isn't working (in subclass)

I have a subclass of a liner layout (referenced from XML custom type) The minimum height I've tried to set just isn't working nor is setting the layout. I need to do this programatically...
Why isn't setMinimumHeight() working?
NB: The complexity of the code can be ignored, the value it is setting is 70
public class SummaryDynamicSpacer extends LinearLayout {
private static final String TAG = "mymeter-DynamicSpacer";
int dpWidth = 0;
int dpHeight = 0;
public SummaryDynamicSpacer(Context context) {
super(context);
init(context);
}
public SummaryDynamicSpacer(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
private void init(Context context) {
DisplayMetrics metrics = new DisplayMetrics();
((Activity)context).getWindowManager().getDefaultDisplay().getMetrics(metrics);
//Set dpWidth, this is the key metric we use for scaling.
float density = getResources().getDisplayMetrics().density;
float dpWidth = metrics.widthPixels / density;
float dpHeight = metrics.heightPixels / density;
this.dpWidth = (int)dpWidth;
this.dpHeight = (int)dpHeight;
Log.d(TAG, "zyxHeightDP: "+metrics.heightPixels / density);
int id = this.getId();
int increment = 10;
int adjustment = getValueForLargeDevice(increment);
if(id == R.id.betweenAddressAndTopBox) {
doBetweenAddressAndTopBox(context, adjustment);
} else if(id == R.id.betweenTopAndAddress) {
doBetweenTopAndAddress(context, adjustment);
}
Log.d(TAG, "SettingHeight: "+adjustment);
this.setBackgroundColor(Color.BLUE);
}
private void doBetweenAddressAndTopBox(Context context, int adjustment) {
this.setMinimumHeight(adjustment);
}
private void doBetweenTopAndAddress(Context context, int adjustment) {
this.setMinimumHeight(adjustment);
}
private int getValueForLargeDevice(double increment) {
int largeDeviceAdjustment = 0;
if(dpHeight > 750) {
int difference = (int)dpHeight - 750;
int interval = 25;
int iterations = (difference / interval) > 12 ? 12 : (difference / interval);
int increasePerInterval = 0;
for(int i=0; i < iterations; i++) {
largeDeviceAdjustment += increment;
}
return largeDeviceAdjustment;
} else {
return 1;
}
}
}
I think your code is fine. Your layout likely has an issue. Did you set the layout as follows?
<com.example.dynamicspacerlayout.SummaryDynamicSpacer
android:id="#+id/betweenAddressAndTopBox"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
See this also does minHeight do anything?
GalaxyNexus Screen Shot running your code
Nexus7 Screen Shot
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Top Text">
<requestFocus />
</EditText>
<com.example.dynamicspacerlayout.SummaryDynamicSpacer
android:id="#+id/betweenAddressAndTopBox"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textColor="#android:color/white"
/>
</com.example.dynamicspacerlayout.SummaryDynamicSpacer>
<EditText
android:id="#+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Bottom Text"
/>
</LinearLayout>
MainActivity.java
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
int minimumHeight = findViewById(R.id.betweenAddressAndTopBox).getHeight();
TextView text = (TextView) findViewById(R.id.textView1);
text.setText("Height: " + minimumHeight);
// text.setVisibility(minimumHeight > 1 ? View.VISIBLE : View.GONE);
}
}, 1000);
}
}
Hope that Helps!

Categories