0

我正在使用 Holoeverywhere 兼容性库和 sherlockActionbar 库。我遇到的问题是,当我在 DialogFragment 类中膨胀视图时,它不会在 3.0 之前的设备上正确显示

 public static class PointSystemDialogFragment extends DialogFragment implements View.OnClickListener, DialogInterface.OnClickListener {
    static final private int GET_CODE = 0;

    static PointSystemDialogFragment newInstance() {
        return new PointSystemDialogFragment();
    }

    Context app;
    Cursor pointSystem;
    DatabaseManager db;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        setStyle(STYLE_NORMAL, 0); //Used for theme switching in samples
        super.onCreate(savedInstanceState);
        app = getSupportActivity();
        db = DatabaseManager.getInstance();
    }

    @Override
    public void onClick(DialogInterface dialog, int which) {
        switch (which) {
            case Dialog.BUTTON_POSITIVE:
                break;
            case Dialog.BUTTON_NEGATIVE:
                break;
            case Dialog.BUTTON_NEUTRAL:
                Intent intent = new Intent(getSupportActivity(), AddPointSystem.class);
                startActivity(intent);
                break;
        }
    }

    @Override
    **public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.pointsystemlist2, container, false);
        String pName = PointSystemDao.Properties.Name.columnName;
        pointSystem = db.getPointSystemCursor();
        String pValue = PointSystemDao.Properties.PointValue.columnName;
        String[] from = {pName, pValue};
        int[] to = {android.R.id.text1, android.R.id.text2};
        SimpleCursorAdapter adapter = new SimpleCursorAdapter(app, android.R.layout.simple_list_item_activated_1, pointSystem, from, to);
        ListView listView = (ListView) view.findViewById(R.id.pointsystem);
        listView.setTextFilterEnabled(true);
        listView.setAdapter(adapter);
        db.getPointSystemCursor().requery();
        // Tell the list view to show one checked/activated item at a time.
        listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        listView.setItemChecked(0, true);
        mListener = (onPointSystemChanged)app;
        listView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(android.widget.AdapterView<?> parent, View view, int position, long id) {
                Long i = (long) position + 1;
                PointSystem pointSystem1 = db.getPointSystemDao().load(i);
                mListener.onSelectedPointSystem(pointSystem1.getName());
                //mListener.onPointSystemChanged(i);
                mListener.onChangedPointSystem(pointSystem1);
            }
        });
        Button Ok = (Button) view.findViewById(R.id.btnOk);
        Ok.setOnClickListener(this);
        Ok.requestFocus();
        Button Add = (Button) view.findViewById(R.id.btnAdd);
        Add.setOnClickListener(this);
        Button Cancel = (Button) view.findViewById(R.id.btnCancel);
        Cancel.setOnClickListener(this);
        Dialog dialog = getDialog();
        if (dialog != null) {
            dialog.setTitle("Select Point System");
            dialog.setCanceledOnTouchOutside(false);
        }
        return view;
    }**

    @Override
    public void onClick(View v) {
        int viewId = v.getId();
        switch (viewId) {
            case R.id.btnOk:
                break;
            case R.id.btnAdd:
                Intent intent = new Intent(getSupportActivity(), AddPointSystem.class);
                startActivity(intent);
                break;
            case R.id.btnCancel:
                break;
        }
        dismiss();
    }


}

在 3.0 之前的设备上显示的链接如下 http://i49.tinypic.com/2j9yeh.png

在 3.0 后的设备上,它可以正确显示 http://i46.tinypic.com/egy8tt.png

我无法弄清楚是什么导致了错误的显示。布局文件如下所示

    <ListView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:id="@+id/pointsystem"
        android:layout_weight="1"/>

    <LinearLayout style="?android:attr/buttonBarStyle"
              android:layout_width="match_parent" android:layout_height="wrap_content"
              android:measureWithLargestChild="true">
        <Button style="?android:attr/buttonBarButtonStyle" android:id="@+id/btnCancel"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Cancel" />

        <Button style="?android:attr/buttonBarButtonStyle" android:id="@+id/btnAdd"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Add" />
        <Button style="?android:attr/buttonBarButtonStyle" android:id="@+id/btnOk"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="OK" />

    </LinearLayout>


</LinearLayout>

任何帮助将非常感激。

4

3 回答 3

0

您将 "android: layout_weight =" 1 "/>" 设置为列表视图的权重。listview的父视图的“weightSum”值是多少?问题可能就在这里。

于 2013-02-21T23:58:18.813 回答
0

警报对话框。

您使用 Dialog 代替 AlertDialog,您使用 ?android:attr/buttonBarStyle 代替 ?buttonBarStyle,您使用 ?android:attr/buttonBarButtonStyle 代替 ?buttonBarButtonStyle。只需使用 AlertDialog - 它已经包含底部按钮栏列表所需的所有样式,请参阅演示。

于 2013-02-22T08:40:29.350 回答
0

我发现了问题。换行

SimpleCursorAdapter adapter = new SimpleCursorAdapter(app, android.R.layout.simple_list_item_activated_1, pointSystem, from, to);

SimpleCursorAdapter adapter = new SimpleCursorAdapter(app, org.holoeverywhere.R.layout.simple_list_item_activated_1, pointSystem, from, to);

或者

int layout  =  int layout = (Build.VERSION.SDK_INT  >= 11) ? org.holoeverywhere.R.layout.simple_list_item_activated_1 : android.R.layout.simple_list_item_1;
SimpleCursorAdapter adapter = new SimpleCursorAdapter(app, layout, pointSystem, from, to);

https://github.com/ChristopheVersieux/HoloEverywhere/issues/225获得解决方案

于 2013-02-23T10:41:31.010 回答