parse two different XML files at one time in listview android2019 Community Moderator ElectionHow to parse an xml to java class with recycler view or in adapter of recyclerviewCalculating the difference between two Java date instancesDownload a file with Android, and showing the progress in a ProgressDialogHow Do You Parse and Process HTML/XML in PHP?Why is subtracting these two times (in 1927) giving a strange result?Performing XML parsing with XML Pull Parser in AndroidXml Parsing to android ListView Using IBM exampleThe best node module for XML parsingXml pull parsing not working after a period of time in androidXML Parsing in AndroidParse XML in android?

Is it true that real estate prices mainly go up?

Reverse string, can I make it faster?

Placing subfig vertically

Should QA ask requirements to developers?

Is there an equal sign with wider gap?

Can someone explain what is being said here in color publishing in the American Mathematical Monthly?

In the late 1940’s to early 1950’s what technology was available that could melt a LOT of ice?

Why don't MCU characters ever seem to have language issues?

Why is this plane circling around the Lucknow airport every day?

Replacing Windows 7 security updates with anti-virus?

Built-In Shelves/Bookcases - IKEA vs Built

Finding algorithms of QGIS commands?

Rejected in 4th interview round citing insufficient years of experience

How much stiffer are 23c tires over 28c?

Is there an elementary proof that there are infinitely many primes that are *not* completely split in an abelian extension?

Do items de-spawn in Diablo?

Accountant/ lawyer will not return my call

Unreachable code, but reachable with exception

Force user to remove USB token

How could our ancestors have domesticated a solitary predator?

Time travel short story where dinosaur doesn't taste like chicken

Is Gradient Descent central to every optimizer?

Fourth person (in Slavey language)

Why the color red for the Republican Party



parse two different XML files at one time in listview android



2019 Community Moderator ElectionHow to parse an xml to java class with recycler view or in adapter of recyclerviewCalculating the difference between two Java date instancesDownload a file with Android, and showing the progress in a ProgressDialogHow Do You Parse and Process HTML/XML in PHP?Why is subtracting these two times (in 1927) giving a strange result?Performing XML parsing with XML Pull Parser in AndroidXml Parsing to android ListView Using IBM exampleThe best node module for XML parsingXml pull parsing not working after a period of time in androidXML Parsing in AndroidParse XML in android?










2















I am working on xml in my android project and I am a beginner. i have a same xml in different language too like that



<sura index="1" name="الفاتحة">
<aya index="1" text="الْحَمْدُ لِلَّهِ رَبِّ الْعَالَمِينَ" bismillah="بِسْمِ اللَّهِ الرَّحْمَنِ
الرَّحِيمِ" />
<aya index="2" text="الرَّحْمَنِ الرَّحِيمِ" />
<aya index="3" text="مَالِكِ يَوْمِ الدِّينِ" />
<aya index="4" text="إِيَّاكَ نَعْبُدُ وَإِيَّاكَ نَسْتَعِينُ" />
<aya index="5" text="اهْدِنَا الصِّرَاطَ الْمُسْتَقِيمَ" />
<aya index="6" text="صِرَاطَ الَّذِينَ أَنْعَمْتَ عَلَيْهِمْ غَيْرِ الْمَغْضُوبِ عَلَيْهِمْ وَلَا الضَّالِّينَ" />
</sura>


this one is in arabic



<sura index="1" name="الفاتحة">
<aya index="1" text="In the name of Allah, most benevolent, ever-merciful."/>
<aya index="2" text="ALL PRAISE BE to Allah, Lord of all the worlds,"/>
<aya index="3" text="Most beneficent, ever-merciful,"/>
<aya index="4" text="King of the Day of Judgement."/>
<aya index="5" text="You alone we worship, and to You alone turn for help."/>
<aya index="6" text="Guide us (O Lord) to the path that is straight,"/>
<aya index="7" text="The path of those You have blessed, Not of those who have earned Your anger, nor those who have gone astray."/>
</sura>


this one in english.



I have successfully done parsing for aya in arabic using this code



private List<String> getAllAyaFromSuraIndex(String suraIndex) throws XmlPullParserException, IOException 
list = new ArrayList<>();

XmlPullParser parser = getResources().getXml(R.xml.quran_arabic);
while (parser.getEventType() != XmlPullParser.END_DOCUMENT)
if (parser.getEventType() == XmlPullParser.START_TAG && parser.getName().equals("sura"))
String index = parser.getAttributeValue(0);

// Match given sure index
if (index.equals(suraIndex))
// Move to first aya tag inside matched sura index
parser.next();

// This loop will exit when it reaches sura end tag </sura>
while (parser.getName().equals("aya"))
if (parser.getEventType() == XmlPullParser.START_TAG)
list.add(parser.getAttributeValue(null,"index") + ".n" + parser.getAttributeValue(null,"text"));


// Move to next aya tag
parser.next();


break;



parser.next();


return list;



I have a listview with two textviews one for arabic and one for english. I tried everything but not getting the results.










share|improve this question
























  • Please don't tag questions with the android-studio tag just because you use it: the Android Studio tag should only be used when you have questions about the IDE itself, and not any code you write (or want to write) in it. See when is it appropriate to remove an IDE tag, How do I avoid misusing tags?, and the tagging guide

    – Zoe
    Mar 6 at 16:31











  • Related stackoverflow.com/a/53593870/7666442

    – Nilesh Rathod
    Mar 6 at 16:35











  • Im using 2 different xmls. The above example is working on xml using tags i have same 2 different xmls just in different language and text is same. I am asking how can i work 2 different xmls for same tag at a time. @NileshRathod

    – Khurram Ansar
    Mar 6 at 16:43
















2















I am working on xml in my android project and I am a beginner. i have a same xml in different language too like that



<sura index="1" name="الفاتحة">
<aya index="1" text="الْحَمْدُ لِلَّهِ رَبِّ الْعَالَمِينَ" bismillah="بِسْمِ اللَّهِ الرَّحْمَنِ
الرَّحِيمِ" />
<aya index="2" text="الرَّحْمَنِ الرَّحِيمِ" />
<aya index="3" text="مَالِكِ يَوْمِ الدِّينِ" />
<aya index="4" text="إِيَّاكَ نَعْبُدُ وَإِيَّاكَ نَسْتَعِينُ" />
<aya index="5" text="اهْدِنَا الصِّرَاطَ الْمُسْتَقِيمَ" />
<aya index="6" text="صِرَاطَ الَّذِينَ أَنْعَمْتَ عَلَيْهِمْ غَيْرِ الْمَغْضُوبِ عَلَيْهِمْ وَلَا الضَّالِّينَ" />
</sura>


this one is in arabic



<sura index="1" name="الفاتحة">
<aya index="1" text="In the name of Allah, most benevolent, ever-merciful."/>
<aya index="2" text="ALL PRAISE BE to Allah, Lord of all the worlds,"/>
<aya index="3" text="Most beneficent, ever-merciful,"/>
<aya index="4" text="King of the Day of Judgement."/>
<aya index="5" text="You alone we worship, and to You alone turn for help."/>
<aya index="6" text="Guide us (O Lord) to the path that is straight,"/>
<aya index="7" text="The path of those You have blessed, Not of those who have earned Your anger, nor those who have gone astray."/>
</sura>


this one in english.



I have successfully done parsing for aya in arabic using this code



private List<String> getAllAyaFromSuraIndex(String suraIndex) throws XmlPullParserException, IOException 
list = new ArrayList<>();

XmlPullParser parser = getResources().getXml(R.xml.quran_arabic);
while (parser.getEventType() != XmlPullParser.END_DOCUMENT)
if (parser.getEventType() == XmlPullParser.START_TAG && parser.getName().equals("sura"))
String index = parser.getAttributeValue(0);

// Match given sure index
if (index.equals(suraIndex))
// Move to first aya tag inside matched sura index
parser.next();

// This loop will exit when it reaches sura end tag </sura>
while (parser.getName().equals("aya"))
if (parser.getEventType() == XmlPullParser.START_TAG)
list.add(parser.getAttributeValue(null,"index") + ".n" + parser.getAttributeValue(null,"text"));


// Move to next aya tag
parser.next();


break;



parser.next();


return list;



I have a listview with two textviews one for arabic and one for english. I tried everything but not getting the results.










share|improve this question
























  • Please don't tag questions with the android-studio tag just because you use it: the Android Studio tag should only be used when you have questions about the IDE itself, and not any code you write (or want to write) in it. See when is it appropriate to remove an IDE tag, How do I avoid misusing tags?, and the tagging guide

    – Zoe
    Mar 6 at 16:31











  • Related stackoverflow.com/a/53593870/7666442

    – Nilesh Rathod
    Mar 6 at 16:35











  • Im using 2 different xmls. The above example is working on xml using tags i have same 2 different xmls just in different language and text is same. I am asking how can i work 2 different xmls for same tag at a time. @NileshRathod

    – Khurram Ansar
    Mar 6 at 16:43














2












2








2


1






I am working on xml in my android project and I am a beginner. i have a same xml in different language too like that



<sura index="1" name="الفاتحة">
<aya index="1" text="الْحَمْدُ لِلَّهِ رَبِّ الْعَالَمِينَ" bismillah="بِسْمِ اللَّهِ الرَّحْمَنِ
الرَّحِيمِ" />
<aya index="2" text="الرَّحْمَنِ الرَّحِيمِ" />
<aya index="3" text="مَالِكِ يَوْمِ الدِّينِ" />
<aya index="4" text="إِيَّاكَ نَعْبُدُ وَإِيَّاكَ نَسْتَعِينُ" />
<aya index="5" text="اهْدِنَا الصِّرَاطَ الْمُسْتَقِيمَ" />
<aya index="6" text="صِرَاطَ الَّذِينَ أَنْعَمْتَ عَلَيْهِمْ غَيْرِ الْمَغْضُوبِ عَلَيْهِمْ وَلَا الضَّالِّينَ" />
</sura>


this one is in arabic



<sura index="1" name="الفاتحة">
<aya index="1" text="In the name of Allah, most benevolent, ever-merciful."/>
<aya index="2" text="ALL PRAISE BE to Allah, Lord of all the worlds,"/>
<aya index="3" text="Most beneficent, ever-merciful,"/>
<aya index="4" text="King of the Day of Judgement."/>
<aya index="5" text="You alone we worship, and to You alone turn for help."/>
<aya index="6" text="Guide us (O Lord) to the path that is straight,"/>
<aya index="7" text="The path of those You have blessed, Not of those who have earned Your anger, nor those who have gone astray."/>
</sura>


this one in english.



I have successfully done parsing for aya in arabic using this code



private List<String> getAllAyaFromSuraIndex(String suraIndex) throws XmlPullParserException, IOException 
list = new ArrayList<>();

XmlPullParser parser = getResources().getXml(R.xml.quran_arabic);
while (parser.getEventType() != XmlPullParser.END_DOCUMENT)
if (parser.getEventType() == XmlPullParser.START_TAG && parser.getName().equals("sura"))
String index = parser.getAttributeValue(0);

// Match given sure index
if (index.equals(suraIndex))
// Move to first aya tag inside matched sura index
parser.next();

// This loop will exit when it reaches sura end tag </sura>
while (parser.getName().equals("aya"))
if (parser.getEventType() == XmlPullParser.START_TAG)
list.add(parser.getAttributeValue(null,"index") + ".n" + parser.getAttributeValue(null,"text"));


// Move to next aya tag
parser.next();


break;



parser.next();


return list;



I have a listview with two textviews one for arabic and one for english. I tried everything but not getting the results.










share|improve this question
















I am working on xml in my android project and I am a beginner. i have a same xml in different language too like that



<sura index="1" name="الفاتحة">
<aya index="1" text="الْحَمْدُ لِلَّهِ رَبِّ الْعَالَمِينَ" bismillah="بِسْمِ اللَّهِ الرَّحْمَنِ
الرَّحِيمِ" />
<aya index="2" text="الرَّحْمَنِ الرَّحِيمِ" />
<aya index="3" text="مَالِكِ يَوْمِ الدِّينِ" />
<aya index="4" text="إِيَّاكَ نَعْبُدُ وَإِيَّاكَ نَسْتَعِينُ" />
<aya index="5" text="اهْدِنَا الصِّرَاطَ الْمُسْتَقِيمَ" />
<aya index="6" text="صِرَاطَ الَّذِينَ أَنْعَمْتَ عَلَيْهِمْ غَيْرِ الْمَغْضُوبِ عَلَيْهِمْ وَلَا الضَّالِّينَ" />
</sura>


this one is in arabic



<sura index="1" name="الفاتحة">
<aya index="1" text="In the name of Allah, most benevolent, ever-merciful."/>
<aya index="2" text="ALL PRAISE BE to Allah, Lord of all the worlds,"/>
<aya index="3" text="Most beneficent, ever-merciful,"/>
<aya index="4" text="King of the Day of Judgement."/>
<aya index="5" text="You alone we worship, and to You alone turn for help."/>
<aya index="6" text="Guide us (O Lord) to the path that is straight,"/>
<aya index="7" text="The path of those You have blessed, Not of those who have earned Your anger, nor those who have gone astray."/>
</sura>


this one in english.



I have successfully done parsing for aya in arabic using this code



private List<String> getAllAyaFromSuraIndex(String suraIndex) throws XmlPullParserException, IOException 
list = new ArrayList<>();

XmlPullParser parser = getResources().getXml(R.xml.quran_arabic);
while (parser.getEventType() != XmlPullParser.END_DOCUMENT)
if (parser.getEventType() == XmlPullParser.START_TAG && parser.getName().equals("sura"))
String index = parser.getAttributeValue(0);

// Match given sure index
if (index.equals(suraIndex))
// Move to first aya tag inside matched sura index
parser.next();

// This loop will exit when it reaches sura end tag </sura>
while (parser.getName().equals("aya"))
if (parser.getEventType() == XmlPullParser.START_TAG)
list.add(parser.getAttributeValue(null,"index") + ".n" + parser.getAttributeValue(null,"text"));


// Move to next aya tag
parser.next();


break;



parser.next();


return list;



I have a listview with two textviews one for arabic and one for english. I tried everything but not getting the results.







java xml-parsing xmlpullparser






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 6 at 16:41







Khurram Ansar

















asked Mar 6 at 16:27









Khurram AnsarKhurram Ansar

336




336












  • Please don't tag questions with the android-studio tag just because you use it: the Android Studio tag should only be used when you have questions about the IDE itself, and not any code you write (or want to write) in it. See when is it appropriate to remove an IDE tag, How do I avoid misusing tags?, and the tagging guide

    – Zoe
    Mar 6 at 16:31











  • Related stackoverflow.com/a/53593870/7666442

    – Nilesh Rathod
    Mar 6 at 16:35











  • Im using 2 different xmls. The above example is working on xml using tags i have same 2 different xmls just in different language and text is same. I am asking how can i work 2 different xmls for same tag at a time. @NileshRathod

    – Khurram Ansar
    Mar 6 at 16:43


















  • Please don't tag questions with the android-studio tag just because you use it: the Android Studio tag should only be used when you have questions about the IDE itself, and not any code you write (or want to write) in it. See when is it appropriate to remove an IDE tag, How do I avoid misusing tags?, and the tagging guide

    – Zoe
    Mar 6 at 16:31











  • Related stackoverflow.com/a/53593870/7666442

    – Nilesh Rathod
    Mar 6 at 16:35











  • Im using 2 different xmls. The above example is working on xml using tags i have same 2 different xmls just in different language and text is same. I am asking how can i work 2 different xmls for same tag at a time. @NileshRathod

    – Khurram Ansar
    Mar 6 at 16:43

















Please don't tag questions with the android-studio tag just because you use it: the Android Studio tag should only be used when you have questions about the IDE itself, and not any code you write (or want to write) in it. See when is it appropriate to remove an IDE tag, How do I avoid misusing tags?, and the tagging guide

– Zoe
Mar 6 at 16:31





Please don't tag questions with the android-studio tag just because you use it: the Android Studio tag should only be used when you have questions about the IDE itself, and not any code you write (or want to write) in it. See when is it appropriate to remove an IDE tag, How do I avoid misusing tags?, and the tagging guide

– Zoe
Mar 6 at 16:31













Related stackoverflow.com/a/53593870/7666442

– Nilesh Rathod
Mar 6 at 16:35





Related stackoverflow.com/a/53593870/7666442

– Nilesh Rathod
Mar 6 at 16:35













Im using 2 different xmls. The above example is working on xml using tags i have same 2 different xmls just in different language and text is same. I am asking how can i work 2 different xmls for same tag at a time. @NileshRathod

– Khurram Ansar
Mar 6 at 16:43






Im using 2 different xmls. The above example is working on xml using tags i have same 2 different xmls just in different language and text is same. I am asking how can i work 2 different xmls for same tag at a time. @NileshRathod

– Khurram Ansar
Mar 6 at 16:43













1 Answer
1






active

oldest

votes


















6














When you are developing multilingual application the best way to handle translations in android is to define content in the locale category. Let me explain it you



1st Step
create directory with locale names mentioned values-(language) e.g values-ar



MyProject/
res/
values-es/
strings.xml
values-ar/
strings.xml


values-es/strings.xml



 <resources>
<string name="ayah1">ALL PRAISE BE to Allah, Lord of all the worlds,.</string>
<string name="ayah2">Most beneficent, ever-merciful,</string>
</resources>


values-ar/strings.xml



 <resources>
<string name="ayah1">الْحَمْدُ لِلَّهِ رَبِّ الْعَالَمِينَ</string>
<string name="ayah2">الرَّحْمَنِ الرَّحِيمِ</string>
</resources>


2nd Step now use these strings in your view files as



<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="com.javapapers.multilingualapp.MainActivity">

<TextView
android:id="@+id/string"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ayah1" //here the values being used
android:textSize="25sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />



</android.support.constraint.ConstraintLayout>


3rd and last step now whenever you want to change the language just change locale using the following function



public void setLocale(String localeName) 
if (!localeName.equals(currentLanguage))
myLocale = new Locale(localeName);
Resources res = getResources();
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
conf.locale = myLocale;
res.updateConfiguration(conf, dm);
Intent refresh = new Intent(this, MainActivity.class);
refresh.putExtra(currentLang, localeName);
startActivity(refresh);
else
Toast.makeText(MainActivity.this, "Language already selected!", Toast.LENGTH_SHORT).show();







share|improve this answer























  • Oh , I am sorry but I think you got me wrong. I am talking about xml parsing to show data in my app. I have 2 xmls of full Quran in two languages. when user click the specific surah, All Ayats of specific surah will open and they will in 2 languages I.e arabic and English. I want to parse both xmls using XMLPullParser to show in List View . In my above I am successfully parsing arabic language but how can i parse second xml too at that time?

    – Khurram Ansar
    Mar 7 at 9:35










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55027874%2fparse-two-different-xml-files-at-one-time-in-listview-android%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









6














When you are developing multilingual application the best way to handle translations in android is to define content in the locale category. Let me explain it you



1st Step
create directory with locale names mentioned values-(language) e.g values-ar



MyProject/
res/
values-es/
strings.xml
values-ar/
strings.xml


values-es/strings.xml



 <resources>
<string name="ayah1">ALL PRAISE BE to Allah, Lord of all the worlds,.</string>
<string name="ayah2">Most beneficent, ever-merciful,</string>
</resources>


values-ar/strings.xml



 <resources>
<string name="ayah1">الْحَمْدُ لِلَّهِ رَبِّ الْعَالَمِينَ</string>
<string name="ayah2">الرَّحْمَنِ الرَّحِيمِ</string>
</resources>


2nd Step now use these strings in your view files as



<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="com.javapapers.multilingualapp.MainActivity">

<TextView
android:id="@+id/string"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ayah1" //here the values being used
android:textSize="25sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />



</android.support.constraint.ConstraintLayout>


3rd and last step now whenever you want to change the language just change locale using the following function



public void setLocale(String localeName) 
if (!localeName.equals(currentLanguage))
myLocale = new Locale(localeName);
Resources res = getResources();
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
conf.locale = myLocale;
res.updateConfiguration(conf, dm);
Intent refresh = new Intent(this, MainActivity.class);
refresh.putExtra(currentLang, localeName);
startActivity(refresh);
else
Toast.makeText(MainActivity.this, "Language already selected!", Toast.LENGTH_SHORT).show();







share|improve this answer























  • Oh , I am sorry but I think you got me wrong. I am talking about xml parsing to show data in my app. I have 2 xmls of full Quran in two languages. when user click the specific surah, All Ayats of specific surah will open and they will in 2 languages I.e arabic and English. I want to parse both xmls using XMLPullParser to show in List View . In my above I am successfully parsing arabic language but how can i parse second xml too at that time?

    – Khurram Ansar
    Mar 7 at 9:35















6














When you are developing multilingual application the best way to handle translations in android is to define content in the locale category. Let me explain it you



1st Step
create directory with locale names mentioned values-(language) e.g values-ar



MyProject/
res/
values-es/
strings.xml
values-ar/
strings.xml


values-es/strings.xml



 <resources>
<string name="ayah1">ALL PRAISE BE to Allah, Lord of all the worlds,.</string>
<string name="ayah2">Most beneficent, ever-merciful,</string>
</resources>


values-ar/strings.xml



 <resources>
<string name="ayah1">الْحَمْدُ لِلَّهِ رَبِّ الْعَالَمِينَ</string>
<string name="ayah2">الرَّحْمَنِ الرَّحِيمِ</string>
</resources>


2nd Step now use these strings in your view files as



<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="com.javapapers.multilingualapp.MainActivity">

<TextView
android:id="@+id/string"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ayah1" //here the values being used
android:textSize="25sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />



</android.support.constraint.ConstraintLayout>


3rd and last step now whenever you want to change the language just change locale using the following function



public void setLocale(String localeName) 
if (!localeName.equals(currentLanguage))
myLocale = new Locale(localeName);
Resources res = getResources();
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
conf.locale = myLocale;
res.updateConfiguration(conf, dm);
Intent refresh = new Intent(this, MainActivity.class);
refresh.putExtra(currentLang, localeName);
startActivity(refresh);
else
Toast.makeText(MainActivity.this, "Language already selected!", Toast.LENGTH_SHORT).show();







share|improve this answer























  • Oh , I am sorry but I think you got me wrong. I am talking about xml parsing to show data in my app. I have 2 xmls of full Quran in two languages. when user click the specific surah, All Ayats of specific surah will open and they will in 2 languages I.e arabic and English. I want to parse both xmls using XMLPullParser to show in List View . In my above I am successfully parsing arabic language but how can i parse second xml too at that time?

    – Khurram Ansar
    Mar 7 at 9:35













6












6








6







When you are developing multilingual application the best way to handle translations in android is to define content in the locale category. Let me explain it you



1st Step
create directory with locale names mentioned values-(language) e.g values-ar



MyProject/
res/
values-es/
strings.xml
values-ar/
strings.xml


values-es/strings.xml



 <resources>
<string name="ayah1">ALL PRAISE BE to Allah, Lord of all the worlds,.</string>
<string name="ayah2">Most beneficent, ever-merciful,</string>
</resources>


values-ar/strings.xml



 <resources>
<string name="ayah1">الْحَمْدُ لِلَّهِ رَبِّ الْعَالَمِينَ</string>
<string name="ayah2">الرَّحْمَنِ الرَّحِيمِ</string>
</resources>


2nd Step now use these strings in your view files as



<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="com.javapapers.multilingualapp.MainActivity">

<TextView
android:id="@+id/string"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ayah1" //here the values being used
android:textSize="25sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />



</android.support.constraint.ConstraintLayout>


3rd and last step now whenever you want to change the language just change locale using the following function



public void setLocale(String localeName) 
if (!localeName.equals(currentLanguage))
myLocale = new Locale(localeName);
Resources res = getResources();
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
conf.locale = myLocale;
res.updateConfiguration(conf, dm);
Intent refresh = new Intent(this, MainActivity.class);
refresh.putExtra(currentLang, localeName);
startActivity(refresh);
else
Toast.makeText(MainActivity.this, "Language already selected!", Toast.LENGTH_SHORT).show();







share|improve this answer













When you are developing multilingual application the best way to handle translations in android is to define content in the locale category. Let me explain it you



1st Step
create directory with locale names mentioned values-(language) e.g values-ar



MyProject/
res/
values-es/
strings.xml
values-ar/
strings.xml


values-es/strings.xml



 <resources>
<string name="ayah1">ALL PRAISE BE to Allah, Lord of all the worlds,.</string>
<string name="ayah2">Most beneficent, ever-merciful,</string>
</resources>


values-ar/strings.xml



 <resources>
<string name="ayah1">الْحَمْدُ لِلَّهِ رَبِّ الْعَالَمِينَ</string>
<string name="ayah2">الرَّحْمَنِ الرَّحِيمِ</string>
</resources>


2nd Step now use these strings in your view files as



<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="com.javapapers.multilingualapp.MainActivity">

<TextView
android:id="@+id/string"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ayah1" //here the values being used
android:textSize="25sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />



</android.support.constraint.ConstraintLayout>


3rd and last step now whenever you want to change the language just change locale using the following function



public void setLocale(String localeName) 
if (!localeName.equals(currentLanguage))
myLocale = new Locale(localeName);
Resources res = getResources();
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
conf.locale = myLocale;
res.updateConfiguration(conf, dm);
Intent refresh = new Intent(this, MainActivity.class);
refresh.putExtra(currentLang, localeName);
startActivity(refresh);
else
Toast.makeText(MainActivity.this, "Language already selected!", Toast.LENGTH_SHORT).show();








share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 6 at 17:20









Muhammad IbrahimMuhammad Ibrahim

196214




196214












  • Oh , I am sorry but I think you got me wrong. I am talking about xml parsing to show data in my app. I have 2 xmls of full Quran in two languages. when user click the specific surah, All Ayats of specific surah will open and they will in 2 languages I.e arabic and English. I want to parse both xmls using XMLPullParser to show in List View . In my above I am successfully parsing arabic language but how can i parse second xml too at that time?

    – Khurram Ansar
    Mar 7 at 9:35

















  • Oh , I am sorry but I think you got me wrong. I am talking about xml parsing to show data in my app. I have 2 xmls of full Quran in two languages. when user click the specific surah, All Ayats of specific surah will open and they will in 2 languages I.e arabic and English. I want to parse both xmls using XMLPullParser to show in List View . In my above I am successfully parsing arabic language but how can i parse second xml too at that time?

    – Khurram Ansar
    Mar 7 at 9:35
















Oh , I am sorry but I think you got me wrong. I am talking about xml parsing to show data in my app. I have 2 xmls of full Quran in two languages. when user click the specific surah, All Ayats of specific surah will open and they will in 2 languages I.e arabic and English. I want to parse both xmls using XMLPullParser to show in List View . In my above I am successfully parsing arabic language but how can i parse second xml too at that time?

– Khurram Ansar
Mar 7 at 9:35





Oh , I am sorry but I think you got me wrong. I am talking about xml parsing to show data in my app. I have 2 xmls of full Quran in two languages. when user click the specific surah, All Ayats of specific surah will open and they will in 2 languages I.e arabic and English. I want to parse both xmls using XMLPullParser to show in List View . In my above I am successfully parsing arabic language but how can i parse second xml too at that time?

– Khurram Ansar
Mar 7 at 9:35



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55027874%2fparse-two-different-xml-files-at-one-time-in-listview-android%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

1928 у кіно

Захаров Федір Захарович

Ель Греко