15,902,198 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by RookieStudent (Top 8 by date)
RookieStudent
22-Jul-21 23:20pm
View
Oh my gosh haha the issue has been resolved :D Thanks man! Cant believe that all that was needed was just simply to call finish () XD. Greatly appreciate you help here !
RookieStudent
22-Jul-21 21:53pm
View
nothing happens. It simply crashes as the error message states that I have not declared the Categories fragment within the manifest. But however as far as I know. You can not declare fragments within the manifest can you?
RookieStudent
9-Apr-20 5:20am
View
Deleted
but how do i do this in fragments though?is there like any examples of fragments that i could reference to?
RookieStudent
8-Apr-20 8:58am
View
umm what i meant is that how should the code for HomeFragment be written as I do not know if I need to use the code that is in the MainActivity and have it applied to the HomeFragment
RookieStudent
8-Apr-20 0:38am
View
ah sorry my bad. But I would like to ask though as im not very familiar with the use of fragments, for my HomeFragment is the code that should be used is as same as the one applied to the MainActivity though? My apologise if my question seems poorly structured.
RookieStudent
7-Apr-20 2:49am
View
but i had it written already though in my MainActivity, here it is:
package sg.edu.rp.c346.new4thappcurrencyconvertorpd;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.NavigationUI;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.text.BreakIterator;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class MainActivity extends AppCompatActivity {
public static BreakIterator data;
List<string> keysList;
Spinner toCurrency;
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
BottomNavigationView bottomNav = findViewById(R.id.bottom_nav);
bottomNav.setOnNavigationItemSelectedListener(navListener);
NavigationUI.setupWithNavController(bottomNav, navController);
getSupportFragmentManager().beginTransaction().replace(R.id.nav_host_fragment, new HomeFragment());
toCurrency = (Spinner)findViewById(R.id.planets_spinner);
final EditText edtEuroValue = (EditText)findViewById(R.id.editText4);
final Button btnConvert = (Button)findViewById(R.id.button);
textView =(TextView) findViewById(R.id.textView7);
try {
loadConvTypes();
} catch (IOException e) {
e.printStackTrace();
}
btnConvert.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(!edtEuroValue.getText().toString().isEmpty())
{
String toCurr = toCurrency.getSelectedItem().toString();
double euroVlaue = Double.valueOf(edtEuroValue.getText().toString());
Toast.makeText(MainActivity.this, "Please Wait..", Toast.LENGTH_SHORT).show();
try {
convertCurrency(toCurr, euroVlaue);
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
else
{
Toast.makeText(MainActivity.this, "Please Enter a Value to Convert..", Toast.LENGTH_SHORT).show();
}
}
});
}
public void loadConvTypes() throws IOException {
String url = "https://api.exchangeratesapi.io/latest";
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(url)
.header("Content-Type", "application/json")
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Request request, IOException e) {
String mMessage = e.getMessage().toString();
Log.w("failure Response",
RookieStudent
5-Apr-20 4:18am
View
hi, but after re-attempting it though i still encounter the same error. Does it have anything to do due to the fact that i did not place the set of codes as seen above into the java class where i have created the layout for ? sorry if my question seems poorly phrased here
RookieStudent
4-Apr-20 11:35am
View
sorry! but here it is
<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" tools:context=".HomeFragment">
<imageview
android:id="@+id/cashimage"
="" android:layout_width="100dp" android:layout_height="100dp" android:layout_alignend="@+id/button" android:layout_alignright="@+id/button" android:layout_alignparenttop="true" android:layout_gravity="center_horizontal" android:layout_margintop="20dp" android:layout_marginend="-45dp" android:layout_marginright="-45dp" android:src="@drawable/currency">
<textview
android:id="@+id/textView5"
="" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignstart="@+id/textView4" android:layout_alignparenttop="true" android:layout_marginstart="0dp" android:layout_margintop="231dp" android:text="Curency">
<spinner
android:id="@+id/planets_spinner"
="" android:layout_width="220dp" android:layout_height="wrap_content" android:layout_aligntop="@+id/textView5" android:layout_marginleft="70dp" android:layout_margintop="1dp">
<textview
android:id="@+id/textView4"
="" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentstart="true" android:layout_alignparentleft="true" android:layout_alignparenttop="true" android:layout_marginstart="41dp" android:layout_marginleft="41dp" android:layout_margintop="164dp" android:text="Amount">
<edittext
android:id="@+id/editText4"
="" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignbottom="@+id/textView4" android:layout_centerhorizontal="true" android:layout_marginbottom="-16dp" android:ems="10" android:inputtype="number">
<button
android:id="@+id/button"
="" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentstart="true" android:layout_alignparentleft="true" android:layout_alignparenttop="true" android:layout_marginstart="125dp" android:layout_marginleft="125dp" android:layout_margintop="297dp" android:text="Convert">
<textview
android:id="@+id/textView6"
="" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentstart="true" android:layout_alignparentleft="true" android:layout_alignparentbottom="true" android:layout_marginstart="51dp" android:layout_marginleft="51dp" android:layout_marginbottom="113dp" android:text="Value">
<textview
android:id="@+id/textView7"
="" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_aligntop="@+id/textView6" android:layout_marginstart="44dp" android:layout_margintop="0dp" android:layout_toendof="@+id/textView5" android:text="TextView">
Show More