我正在使用微调器,我的微调器运行良好,但微调器项目没有保存,例如当我为我的文本选择 font2 时,我的文本字体已更改,我的更改已保存为下一个但在关闭我的程序后微调器显示 font1 我的代码是:在这段代码中,我将项目添加到微调器
package com.testfont.test;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Spinner;
public class font extends Activity {
public static String font="tahoma.ttf";
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.font);
final List<String> list = new ArrayList<String>();
String item1 = "font1";
String item2 = "font2";
//String item3 = "فونت سه";
list.add(item1);
list.add(item2);
//list.add(item3);
Arrayadapt ad = new Arrayadapt(getApplicationContext(), 0, list);
Spinner sp = (Spinner)findViewById(R.id.spinner1);
sp.setAdapter(ad);
sp.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View selectedItemView,
int position, long id) {
// TODO Auto-generated method stub
//boolean selected = false;
if(position == 0){
font="tahoma.ttf";
}else if(position == 1){
font="QuranTaha.ttf";
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}
// TODO Auto-generated method stub
public String getFont() {
// TODO Auto-generated method stub
return font;
}
}
在这段代码中,我添加到微调器
package com.testfont.test;
import java.util.List;
import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
public class Arrayadapt extends ArrayAdapter{
Typeface tf;
List<String> _list;
Context context;
LayoutInflater mInflater;
public Arrayadapt(Context _context, int _resource,
List<String> _items) {
super(_context, _resource, _items);
// TODO Auto-generated constructor stub
this.context = _context;
this.tf = Typeface.createFromAsset(_context.getAssets(),"font/Yekan.ttf");
this._list = _items;
this.mInflater = LayoutInflater.from(context);
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = mInflater;
View row = inflater.inflate(R.layout.tspinner, parent,
false);
TextView v = (TextView) row.findViewById(R.id.textView1);
v.setTypeface(tf);
v.setText(Farsi.Convert(_list.get(position)));
return row;
}
public View getDropDownView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = mInflater;
View row = inflater.inflate(R.layout.tspinner, parent,
false);
TextView v = (TextView) row.findViewById(R.id.textView1);
v.setTypeface(tf);
v.setText(Farsi.Convert(_list.get(position)));
return row;
}
}