I am currently writing the "net.superlinux.tcltktutorials" you can find it on play store now.
now in the application, I want to use the standard way of using locales instead of my way of doing locales. I had to add for Arabic /res/vlaues-ar and I have the default for English /res/values.
The app is about ad based YouTube Playlist TCL/Tk programming language tutorials. now the playlist can be in Arabic and in English. What I noticed is that if you have in the default /res/values 36 entries and in /res/values-ar 35 entries for the same playlist, this will make the ResourceNotFound exception. All you have to do is add the missing entry as empty at the bottom of your list just to make it equal in numbers in English and Arabic, Even if the English playlist is less in numbers.
This was my method of adding to the playlist formed inside the list activity, and also a clever way of using the resources as xml built in data:
package net.superlinux.tcltktutorials;
import java.util.ArrayList;
import java.util.List;
import android.app.ListActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class ListOfVideos extends ListActivity {
List<String> model = new ArrayList<String>();
ArrayAdapter<String> adapter = null;
List<String> filename = new ArrayList<String>();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listview);
adapter = new ArrayAdapter<String> (this, R.layout.list_item, model);
load_playlist();
setListAdapter(adapter);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
String selected_youtube_video=filename.get(position);
try {Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:"+selected_youtube_video));
startActivity(i);
}
catch(Exception e){
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v="+selected_youtube_video+"&loop=1&autoplay=1")));
e.printStackTrace();
}
}
void load_playlist()
{
int display_id=0;
int file_id=0;
//loop forever until nothing has to be added to the ListView or stop if the list item
// to be added does not exist.
for (int i=0;;i++){
display_id=getResources().getIdentifier("display_"+i, "string", getPackageName());
if (display_id!=0 && getString(display_id).length()!=0)
adapter.add(getString(display_id));
else {
Log.e("string id not found or empty","R.string.display_"+i );
return;
}
file_id=getResources().getIdentifier("file_"+i, "string", getPackageName());
if (file_id!=0 && getString(file_id).length()!=0){
filename.add(getString(file_id));
}
else {
Log.e("string id not found or empty","R.string.file_"+i );
return;
}
}
}
}