小编典典

类:

public class testActivity extends Activity {

private static final String[] COUNTRIES = new String[] { "Belgium",

"France", "Italy", "Germany", "Spain" };

private Spinner mySpinner;

private Typeface myFont;

@Override

protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

setContentView(R.layout.newlay);

mySpinner = (Spinner) findViewById(R.id.spinner1);

myFont = Typeface.createFromAsset(getAssets(), "gujarti.ttf");

MyArrayAdapter ma = new MyArrayAdapter(this);

mySpinner.setAdapter(ma);

}

private class MyArrayAdapter extends BaseAdapter {

private LayoutInflater mInflater;

public MyArrayAdapter(testActivity con) {

// TODO Auto-generated constructor stub

mInflater = LayoutInflater.from(con);

}

@Override

public int getCount() {

// TODO Auto-generated method stub

return COUNTRIES.length;

}

@Override

public Object getItem(int position) {

// TODO Auto-generated method stub

return position;

}

@Override

public long getItemId(int position) {

// TODO Auto-generated method stub

return position;

}

@Override

public View getView(int position, View convertView, ViewGroup parent) {

// TODO Auto-generated method stub

final ListContent holder;

View v = convertView;

if (v == null) {

v = mInflater.inflate(R.layout.my_spinner_style, null);

holder = new ListContent();

holder.name = (TextView) v.findViewById(R.id.textView1);

v.setTag(holder);

} else {

holder = (ListContent) v.getTag();

}

holder.name.setTypeface(myFont);

holder.name.setText("" + COUNTRIES[position]);

return v;

}

}

static class ListContent {

TextView name;

}

}

版面:

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical" >

android:id="@+id/spinner1"

android:layout_width="match_parent"

android:layout_height="wrap_content" />

my_spinner_style.xml

android:layout_width="fill_parent"

android:layout_height="fill_parent" >

android:id="@+id/textView1"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Large Text"

android:textAppearance="?android:attr/textAppearanceLarge" />

2020-09-26

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐