如果你是要传入到另一个Activity界面,同理将取得位置的 文件名和内容 一并用 putExtra 传过去,或者你再另一个Activity定义同类的静态变量 ,直接赋值,或其他方法 。
重写一下Adapter,然后自己对Adapter每个Item布局,在布局里面设置一下点击效果就行了。如:public class MainActivity extends Activity {
private Spinner mSpinner
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
initView()
}
private void initView(){
mSpinner = (Spinner)findViewById(R.id.spinner)
MyAdapter adapter = new MyAdapter(getResources().getStringArray(R.array.girl_names))
mSpinner.setAdapter(adapter)
}
private class MyAdapter extends BaseAdapter{
private String[] idInt
public MyAdapter(String[] idInt){
this.idInt = idInt
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return idInt.length
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return idInt[arg0]
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0
}
@Override
public View getView(int arg0, View arg1, ViewGroup arg2) {
// TODO Auto-generated method stub
if(arg1 == null){
arg1 = getLayoutInflater().inflate(R.layout.spinner_item, null)
}
TextView text = (TextView)arg1.findViewById(R.id.spinner_item_id)
text.setText(idInt[arg0])
return arg1
}
}
spinner_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/text_selector"
android:orientation="vertical" >
<TextView
android:layout_margin="10dip"
android:id="@+id/spinner_item_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="true" >
</TextView>
</LinearLayout>
然后:text_selector.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:drawable="@android:color/black"></item>
<item android:state_pressed="false" android:drawable="@android:color/transparent"></item>
</selector>
spinner添加监听setOnItemSelectedListener当一个item被selcted后
改变activity的背景可以通过获取其父布局
如其父是一个LinearLayout,那就LinearLayout l =(LinearLayout)findViewById(xxxx这是layout的id)l.setBackgroundColor(xx)或者setBackgroundResource方法设置背景
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)