且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Actionbar微调器定制

更新时间:2023-12-02 21:04:34

我解决了这个问题。

我的适配器类列表:

public class AdapterBaseMaps extends BaseAdapter {

Context context;
int layoutResourceId;
ArrayList<ObjectLayers> data;
LayoutInflater inflater;

public AdapterBaseMaps(Context context, int textViewResourceId,
        ArrayList<ObjectLayers> data) {
    // super(a, textViewResourceId, data);
    this.data = data;
    inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    this.context = context;
    this.layoutResourceId = textViewResourceId;

}

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

    View actionBarView = inflater.inflate(R.layout.ab_main_view, null);
    TextView title = (TextView) actionBarView
            .findViewById(R.id.ab_basemaps_title);
    TextView subtitle = (TextView) actionBarView
            .findViewById(R.id.ab_basemaps_subtitle);
    title.setText(context.getResources()
            .getString(R.string.label_cartravel));
    subtitle.setText(data.get(position).getLayerName());
    return actionBarView;

}

@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
    View actionBarDropDownView = inflater.inflate(
            R.layout.ab_dropdown_view, null);
    TextView dropDownTitle = (TextView) actionBarDropDownView
            .findViewById(R.id.ab_basemaps_dropdown_title);

    dropDownTitle.setText(data.get(position).getLayerName());

    return actionBarDropDownView;

}

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return data.size();
}

@Override
public Object getItem(int position) {
    // TODO Auto-generated method stub
    return null;
}

@Override
public long getItemId(int position) {
    // TODO Auto-generated method stub
    return 0;
}

}

ab_main_view.xml的列表: / p>

Listing of ab_main_view.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<TextView
    android:id="@+id/ab_basemaps_title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView"
    android:textSize="20sp"
    android:textColor="@color/White" />

<TextView
    android:id="@+id/ab_basemaps_subtitle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/ab_basemaps_title"
    android:text="TextView"
    android:textColor="@color/White"
    android:textSize="13sp" />

</RelativeLayout>

ab_dropdown_view.xml的列表:

Listing of ab_dropdown_view.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<TextView
    android:id="@+id/ab_basemaps_dropdown_title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:textSize="20sp"
    android:padding="5dp"
    android:textColor="@color/White" />

</RelativeLayout>