PDA

View Full Version : سوال: پیدا کردن تکست ویو در لیست ویو که نمایش داده می شود



vid4259
جمعه 04 دی 1394, 21:33 عصر
سلام تو اکلیپس یه برنامه نویشتم و دارای لیست علاقه مندی هست که لیست ویو را کدهای زیر پر می کنم حالا مشکلم اینه که می خوام فونت لیست ویو رو تغییر بدم ولی نمی تونم و لی اگر بتونم تکست ویو روپیدا کنم می تونم اون رو تغیر بدم
درضمن layout که برای برای نمایش لیست ویوم از یک ایمیج باکس و تکست ویو اتفاده کردم


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.ibsearc hh);



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);


// Adding items to list view
adapter = new ArrayAdapter<String>(this, R.layout.row_layoutfavorites, R.id.populationf, Favorites_strings);
lv.setAdapter(adapter);


TextView v=(TextView) findViewById( R.id.populationf);

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();
}
}


});



{

vid4259
سه شنبه 15 دی 1394, 18:01 عصر
سلام اخرش حودم حلش کردم و اینم کد نهایی



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);
}





}