[英]How to change textsize(fontsize) in customlistview?
I tried to change textSize in my app. 我试图在我的应用程序中更改textSize。 I want to change my customlistview's textSize.
我想更改我的customlistview的textSize。 My listview's row XML file has image, 3 textView.
我的listview的行XML文件具有图像3 textView。 I want to change the textView's textSize when User click Optionmenu, and click AlertDialog's SingleChoiceItems checkbox.
当用户单击Optionmenu,然后单击AlertDialog的SingleChoiceItems复选框时,我想更改textView的textSize。
here is my code. 这是我的代码。
Do I need to change XMl file?.. Then How can I set my customAdapter?.. Do I need to change my adapter's getView method? 我需要更改XMl文件吗?。然后如何设置我的customAdapter?..我需要更改适配器的getView方法吗?
I'm Open to any answer. 我愿意接受任何答案。
public boolean onOptionsItemSelected(MenuItem item){
switch(item.getItemId()){
case R.id.ks_notice_menu_textsize:
final CharSequence[] items = {"normal", "big", "bigger"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("select textSize");
builder.setSingleChoiceItems(items, mSelect,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
mSelect = which;
}
});
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
int textSize = (int)Username.getTextSize();
switch(mSelect){
case 0:
//here I need to change textSize
break;
case 1:
//here I need to change textSize
break;
case 2:
//here I need to change textSize
break;
}
}
});
builder.setNegativeButton("cancel", null);
builder.show();
return true;
}
return false;
In your XML for the ListView
's row, you need to add IDs to the TextView
s in question. 在XML中,用于
ListView
的行,您需要将ID添加到相关的TextView
。 Then, you need to replace: 然后,您需要替换:
//here I need to change textSize
with (assuming you want a text size of 5): 与(假设您希望文本大小为5):
customAdapter.setTextSize(5);
And finally, in your customAdapter
you need to implement a setTextSize(int)
method that retrieves all the views and sets their text sizes to the value passed. 最后,在您的
customAdapter
您需要实现一个setTextSize(int)
方法,该方法检索所有视图并将其文本大小设置为传递的值。 It also needs to store that value and use it for any new views created when the user scrolls further down. 它还需要存储该值,并将其用于当用户向下滚动时创建的任何新视图。
Something like: 就像是:
public void setTextSize(final int textSize) {
fTextSize = textSize;
for (View view : fViews) {
((TextView) view.findViewById(R.id.list_view_text_1).setTextSize(textSize);
((TextView) view.findViewById(R.id.list_view_text_2).setTextSize(textSize);
((TextView) view.findViewById(R.id.list_view_text_3).setTextSize(textSize);
}
}
and: 和:
public View getView(final int position, final View convertView, final ViewGroup parent) {
View view = // retrieve your view from XML.
fViews.add(view);
((TextView) view.findViewById(R.id.list_view_text_1).setTextSize(textSize);
((TextView) view.findViewById(R.id.list_view_text_2).setTextSize(textSize);
((TextView) view.findViewById(R.id.list_view_text_3).setTextSize(textSize);
return (view);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.