0

I am using the Holoeverywhere compatibility library along with the sherlockActionbar library. The problem i am having is that when i inflate the view in the DialogFragment class, it doesnt display corrrectly on pre 3.0 devices

 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();
    }


}

the link to how the display looks like on pre 3.0 devices is below http://i49.tinypic.com/2j9yeh.png

on post 3.0 devices it displays properly http://i46.tinypic.com/egy8tt.png

I cant figure out what is causing the wrong display. The layout file is shown below

    <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>

Any help would be really appreciated.

gbozee
  • 4,366
  • 1
  • 23
  • 23

3 Answers3

0

you set "android: layout_weight =" 1 "/>" as weights for the listview. What is the value of "weightSum" to the parent view to the listview? the problem may be here.

julien dumortier
  • 1,303
  • 1
  • 13
  • 28
  • I didnt set the value of weightsum for the parentview – gbozee Feb 22 '13 at 00:49
  • I do not know why the 3 buttons appear in each row of the listview on pre 3.0 devices. – gbozee Feb 22 '13 at 01:11
  • maybe equipment with a version <3.0 has a different screen size. I do not know if it is a good idea, but if you use this code: this means that "button1" is doubly space "button2". I do not know how it reacts by not "layout_weight" in "button2" – julien dumortier Feb 22 '13 at 18:31
  • So, we should try to write as follows: I'm not sure what I say. But trying is easy :). Again forgiveness for my english – julien dumortier Feb 22 '13 at 18:32
0

AlertDialog.

You are use Dialog instead AlertDialog, you are use ?android:attr/buttonBarStyle instead ?buttonBarStyle, you are use ?android:attr/buttonBarButtonStyle instead ?buttonBarButtonStyle. Just use AlertDialog - it's already contains all needed styles for list with bottom button bar, see demo.

Prototik
  • 935
  • 4
  • 7
  • I av tried using AlertDialog in creating the view without the special buttons and it still results in the same issue. In my alertdialog, i am using a layout file to inflate the view. – gbozee Feb 22 '13 at 17:49
0

I found the problem. Changing the line

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

to

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

or

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);

got the solution from https://github.com/ChristopheVersieux/HoloEverywhere/issues/225

gbozee
  • 4,366
  • 1
  • 23
  • 23