۱۳۹۴/۱۰/۱۲, ۱۲:۲۳ ب.ظ
آخر خودم حلش کردم
اینم کل کد که قشنگ کار می کنه
اینم کل کد که قشنگ کار می کنه
کد پیاچپی:
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;
/** 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.ibsearchh);
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(resID));
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);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, final View view,int position, long id)
{
//این کد می گوید کلیک کن و در ارایه مد نظز خانه که انتخاب شده مقدار داخل آن را داخله رشته بریز
String favorite_number = Favorites_numbers.get(position);
//چون در اکتیوتی حرکات ما از عدد استفاده کردیم حالا رشته را به عدد تبدیل می کنیم
int a=Integer.parseInt(favorite_number);
//********************0-276
if(a<277)
{
Intent i = new Intent(AFavorites.this, Asubharakat.class);
i.putExtra("harakat1", a);
startActivity(i);
finish();
}
//****************277-283
else if(a<284)
{
Intent i = new Intent(AFavorites.this, Asubfigor.class);
i.putExtra("harakat1", a);
startActivity(i);
finish();
}
else if(a<287)
//****************284-286
{
Intent i = new Intent(AFavorites.this, Asubbarnameh.class);
i.putExtra("harakat1", a);
startActivity(i);
finish();
}
}
});
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;
}
}
}