Skip to content

Commit ceb15c2

Browse files
author
MOB-2
committed
bug fixing
1 parent d529a2f commit ceb15c2

File tree

4 files changed

+29
-16
lines changed

4 files changed

+29
-16
lines changed

app/src/main/java/com/rk/currencyview/MainActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ protected void onCreate(Bundle savedInstanceState) {
2626
// currency_edt.setMaxLimit(999);
2727

2828
final CurrencyTextView currency_tv = findViewById(R.id.currency_tv);
29-
currency_tv.setCurrecy(currency);
29+
currency_tv.setCurrency(currency);
3030

3131
findViewById(R.id.btnDone).setOnClickListener(new View.OnClickListener() {
3232
@Override
3333
public void onClick(View view) {
34-
currency_tv.setText("" + currency_edt.getRateWithOutCurrency());
34+
currency_tv.setText(currency_edt.getRateWithOutCurrency());
3535
}
3636
});
3737
}

app/src/main/res/layout/activity_main.xml

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,30 @@
2121
android:id="@+id/btnDone"
2222
android:layout_width="wrap_content"
2323
android:layout_height="wrap_content"
24-
android:layout_marginTop="10dp"
2524
android:layout_gravity="center_horizontal"
25+
android:layout_marginTop="10dp"
2626
android:text="Done" />
2727

28-
<com.rk.libcurrencyview.CurrencyTextView
29-
android:id="@+id/currency_tv"
30-
android:layout_width="match_parent"
28+
<LinearLayout
29+
android:layout_width="wrap_content"
3130
android:layout_height="wrap_content"
32-
android:layout_marginTop="10dp"
33-
android:padding="10dp"
34-
android:textColor="@android:color/black"
35-
tools:text="@string/app_name" />
31+
android:layout_margin="10dp"
32+
android:orientation="horizontal"
33+
android:padding="10dp">
34+
35+
<TextView
36+
android:layout_width="wrap_content"
37+
android:layout_height="wrap_content"
38+
android:layout_marginEnd="5dp"
39+
android:layout_marginRight="5dp"
40+
android:text="Entered Amount" />
41+
42+
<com.rk.libcurrencyview.CurrencyTextView
43+
android:id="@+id/currency_tv"
44+
android:layout_width="match_parent"
45+
android:layout_height="wrap_content"
46+
android:textColor="@android:color/black"
47+
tools:text="@string/app_name" />
48+
</LinearLayout>
3649

3750
</LinearLayout>

libcurrencyview/src/main/java/com/rk/libcurrencyview/CurrencyEditText.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ public void afterTextChanged(Editable editable) {
7979
});
8080
}
8181

82-
public double getRateWithOutCurrency() {
82+
public String getRateWithOutCurrency() {
8383
if (isNullOrEmpty(getText().toString().trim())) {
84-
return 0;
84+
return "0";
8585
} else {
8686
String amount = getText().toString().trim().replace(strCurrency, "");
8787
if (amount.equals(".")) {
88-
return 0;
88+
return "0";
8989
} else {
90-
return Double.parseDouble(amount);
90+
return amount;
9191
}
9292
}
9393
}

libcurrencyview/src/main/java/com/rk/libcurrencyview/CurrencyTextView.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void setText(CharSequence text, BufferType type) {
3434
try {
3535
// The comma in the format specifier does the trick
3636
DecimalFormat formatter = (DecimalFormat) NumberFormat.getInstance(Locale.getDefault());
37-
formatter.applyPattern("#,##,##,##,###.##");
37+
formatter.applyPattern("#,##,##,##,###.###");
3838
formatedString = sCurrency + formatter.format(Double.parseDouble(text.toString())); // adds rupee symbol and thousand seperater
3939
} catch (NumberFormatException e) {
4040
Log.d(TAG, "Rupee TextView NumberFormatException");
@@ -46,7 +46,7 @@ public void setText(CharSequence text, BufferType type) {
4646
}
4747
}
4848

49-
public void setCurrecy(String sCurrency) {
49+
public void setCurrency(String sCurrency) {
5050
this.sCurrency = sCurrency;
5151
}
5252

0 commit comments

Comments
 (0)