Issue
I'm making a sign up activity, where i use drawables resources to interact. TextWatcher and some coding, then (example):
etPass.setCompoundDrawablesWithIntrinsicBounds(R.drawable.icon_lock_open, 0, R.drawable.icon_close, 0);
Now, i made a task to check e-mail on database. I would like to show a ProgressDialog while this task gets the result. I tried with a gif, but it doesn't animate properly. I want something like:
Note: I would like to do this through "setCompoundDrawablesWithIntrinsicBounds", once it already comes formatted and fit on the field. But i'm open to other ways.
Thanks !
Solution
Here's how I would do it:
Create a custom XML for the EditText
with ProgressBar
.
<?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="wrap_content" >
<EditText
android:layout_width="match_parent"
android:id="@+id/edit"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_launcher"
android:singleLine="true" />
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:id="@+id/progress"
android:visibility="invisible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/edit"
android:layout_alignBottom="@id/edit"
android:layout_alignRight="@id/edit"/>
</RelativeLayout>
Then, include it in the activity
<include
android:id="@+id/field1"
layout="@layout/progress_edittext"
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
and then retrieve it in onCreate()
public class MainActivity extends ActionBarActivity {
private View field1;
private EditText edit;
private ProgressBar progress;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
field1 = findViewById(R.id.field1);
edit = (EditText) field1.findViewById(R.id.edit);
progress = (ProgressBar) field1.findViewById(R.id.progress);
edit.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
progress.setVisibility(View.VISIBLE);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {}
@Override
public void afterTextChanged(Editable s) {
// YOUR LOGIC GOES HERE
}
});
}
}
Answered By - An SO User
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.