本文介绍了安卓:添加两个TextViews到动作条微调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
反正有添加两个文本观点或串动作条微调里面?
Is there anyway to add two text views or strings inside of the Actionbar Spinner?
类似于如何Android的Gmail应用程序做的。
Similar to how the Android GMAIL app does it.
推荐答案
您可以使用自定义ArrayAdapter:
You could use a custom ArrayAdapter:
public class spinnerAdapter extends ArrayAdapter {
private LayoutInflater inflater;
public spinnerAdapter(Context context, int textViewResourceId) {
super(context, textViewResourceId);
inflater = LayoutInflater.from(context);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if(convertView == null){
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.spinner_text_layout, null);
holder.text1 = (TextView)convertView.findViewById(R.id.spinnerText1);
holder.text2 = (TextView)convertView.findViewById(R.id.spinnerText2);
convertView.setTag(R.layout.spinner_text_layout, holder);
} else{
holder = (ViewHolder)convertView.getTag(R.layout.spinner_text_layout);
}
holder.text1.setText("Position: " );
holder.text2.setText(position);
return convertView;
}
public View getDropDownView(int position, View convertView, ViewGroup parent) {
ViewHolder2 holder;
if(convertView == null){
holder = new ViewHolder2();
convertView = inflater.inflate(R.layout.spinner_text_layout, null);
holder.text1 = (TextView)convertView.findViewById(R.id.spinnerText1);
holder.text2 = (TextView)convertView.findViewById(R.id.spinnerText2);
convertView.setTag(R.layout.spinner_text_layout, holder);
} else{
holder = (ViewHolder2)convertView.getTag(R.layout.spinner_text_layout);
}
holder.text1.setText("Position: " );
holder.text2.setText(position);
return convertView;
}
static class ViewHolder{
TextView text1;
TextView text2;
}
static class ViewHolder2{
TextView text1;
TextView text2;
}
}
spinner_text_layout.xml:
spinner_text_layout.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/spinnerText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="18dp"
android:layout_marginTop="16dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/spinnerText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView1"
android:layout_alignParentRight="true"
android:layout_marginRight="23dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
这篇关于安卓:添加两个TextViews到动作条微调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!