Search code examples
androidandroid-adapterandroid-resources

Getting different integer value from resource folder in Android


I have a listView in my screen. I want its adapter populate 3 items if the device is small screen (320*480) while 4 items for the rest.

The way I'm doing that in adapter:

public class MyAdapter extends BindableArrayAdapter<SOMETHING>
{
    private static int MAX_DISPLAYED_ITEMS;

    public MyAdapter(Context context)
    {
        super(context);

        MyAdapter.MAX_DISPLAYED_ITEMS = context.getResources().getInteger(R.integer.list_size);
        Log.e("Test", "" + MAX_DISPLAYED_ITEMS);
    }

    @Override
    public int getCount()
    {
        return Math.min(MAX_DISPLAYED_ITEMS, super.getCount());
    }

and I have 2 files under res/values-small and res/values-normal one has 3 and the other 4 as value of list_size like this

<resources>
    <integer name="list_size">3</integer>
</resources>

I expect to see 3 items on Galaxy Y (320*480) while I see 4 items.

How can I fix this issue?


Solution

  • The device density is 165dpi thats make it mdpi device. The resolution is 320px x 480px and because its mdpi thats mean. The device is 320dp x 480dp.

    And from Google doc you can see this device is Normal.

    xlarge screens are at least 960dp x 720dp
    large screens are at least 640dp x 480dp
    normal screens are at least 470dp x 320dp
    small screens are at least 426dp x 320dp

    For me I would prefer to use sw-xxx for example (you need to check the values):

    res/values => 3  
    res/values-sw330 => 4