سلام اخرش حودم حلش کردم و اینم کد نهایی
public class AFavorites extends Activity {
TextView TextViewonvan;
EditText search;
EditText editTextSearch;
TextView textviewonvanehdialog;
TextView textviwedialogmessag;
ImageButton imagebutton;
public int Subjects_total_number;
public Globals global = new Globals();
public List<String> Favorites_numbers;
public List<String> Favorites_strings;
String each_subject;
public String[] Subjects;
TextView onvan;
TextView population;
Typeface tf;
// List view
private ListView lv;
// List view Adapter
ArrayAdapter<String> adapter;
Animation animation1;
Animation animation2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.favorites);
tf = Typeface.createFromAsset(getAssets(), "fonts/Mj_Beirut.TTF");
onvan=(TextView)findViewById(R.id.TextViewonvanf);
onvan.setTypeface(tf);
onvan.setText("لیست علاقه مندی ها");
search=(EditText)findViewById(R.id.etsearchh);
imagebutton=(ImageButton)findViewById(R.id.ibsearc hh);
animation1 = AnimationUtils.loadAnimation(getApplicationContext (), R.anim.ani1);
animation2 = AnimationUtils.loadAnimation(getApplicationContext (), R.anim.ani2);
Favorites_strings = new ArrayList<String>();
Favorites_numbers = new ArrayList<String>();
final SharedPreferences shared = getSharedPreferences("Prefs", MODE_PRIVATE);
Subjects_total_number = global.Subjects_total_number;
for(int x = 0; x < Subjects_total_number+1; x = x+1)
{
each_subject = "subject_" + String.valueOf(x);
Boolean b = shared.getBoolean(each_subject, false);
//اگر مقدار رشته در لیست علاقه مندی باشد وارد دستور زیر می شود
if(b)
{
String this_subject = "subject_" + String.valueOf(x);
int resID = getResources().getIdentifier(this_subject, "string", getPackageName());
Favorites_strings.add(getResources().getString(res ID));
String x_string = String.valueOf(x);
Favorites_numbers.add(x_string);
}
}
lv = (ListView) findViewById(R.id.listViewf);
MyAdapter adapter = new MyAdapter(AFavorites.this, R.layout.row_layoutfavorites, R.id.populationf,Favorites_strings);
// Adding items to list view
//adapter = new ArrayAdapter<String>(this, R.layout.row_layoutfavorites, R.id.populationf, Favorites_strings);
lv.setAdapter(adapter);
}
private class MyAdapter extends ArrayAdapter<String>{
public MyAdapter(Context context, int resource, int textViewResourceId, List<String> strings)
{
super(context, resource, textViewResourceId, strings);
// TODO Auto-generated constructor stub
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.row_layoutfavorites, parent, false);
//در اینجا از مقداری که در لیست نام بر که از اول پر می شود استفاده می کنیم
//Favorites_strings[a,b,c,,d,]
//Favorites_numbers[1,2,3,4]=[12,23,24]
//Favorites_numbers.get(position)=12=subject_12=a
String this_subject = "subject_" + Favorites_numbers.get(position);
int resID = getResources().getIdentifier(this_subject, "string", getPackageName());
String my_string = getResources().getString(resID);
TextView tv = (TextView) row.findViewById(R.id.populationf);
tv.setText(my_string);
tf = Typeface.createFromAsset(getAssets(), "fonts/Mj_Beirut.TTF");
tv.setTypeface(tf);
return row;
}
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if (keyCode == KeyEvent.KEYCODE_BACK)
{
finish();
overridePendingTransition(R.anim.ani1,R.anim.ani2) ;
}
return super.onKeyDown(keyCode, event);
}
}