public class CustomSpinnerAdapter extends BaseAdapter{ private Context context; private ArrayList<String> arr;
public CustomSpinnerAdapter(Context context, int textViewResourceId,
ArrayList<String> objects) {
// TODO Auto-generated constructor stub
this.context = context;
arr = objects;
}
@Override
public View getDropDownView(int position, View convertView,
ViewGroup parent) {
// TODO Auto-generated method stub
return getCustomView(position, convertView, parent);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
return getCustomView(position, convertView, parent);
}
public View getCustomView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
//return super.getView(position, convertView, parent);
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row=mInflater.inflate(R.layout.spinner_item, parent, false);
TextView accountNumber = (TextView) row
.findViewById(R.id.accountNumber);
TextView accountType = (TextView) row
.findViewById(R.id.accountType);
TextView balance = (TextView) row
.findViewById(R.id.balance);
accountNumber.setText("accountType");
balance.setText("balance");
accountType.setText("accountNumber");
return row;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return arr.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return arr.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
}
当我打电话给这个班级的时候,我的旋转器的高度非常长......
spinner_item
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:orientation="vertical" android:layout_height="wrap_content" > <TextView android:id="@+id/accountNumber" style="@style/listViewPrimaryDetail" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ellipsize="marquee" android:singleLine="true" android:paddingLeft="10dp" android:paddingTop="10dp" /> <TextView android:id="@+id/accountType" style="@style/listViewSecondaryDetail" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@id/accountNumber" android:ellipsize="marquee" android:paddingBottom="10dp" android:paddingLeft="10dp" /> <TextView android:id="@+id/balance" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_centerInParent="true" android:layout_alignParentRight="true" android:ellipsize="marquee" /> </RelativeLayout>
那会发生什么?怎么了?
Spinner spinner = (Spinner) rootView .findViewById(R.id.planets_spinnerqw); CustomSpinnerAdapter adapter = new CustomSpinnerAdapter( container.getContext(),R.layout.spinner_item, values); // Apply the adapter to the spinner spinner.setAdapter(adapter);
那为什么这段代码不起作用?在活动中我读取了微调器..分配给它自定义适配器..在自定义适配器我指定布局spinner_item ..它采取整个高度而不是我想要的设计。 如果我在spinner_item中指定相对布局而不是wrap_content layout_height =&#34; 100dp&#34;它效果更好......为什么会发生这种情况?