SwipeStack icon indicating copy to clipboard operation
SwipeStack copied to clipboard

getLayoutInflater() does not exist

Open voghDev opened this issue 8 years ago • 2 comments

Hi, thanks for the awesome lib. I've tried to reproduce your code, and just noticed that getLayoutInflater() is not a method from BaseAdapter nor CardStackAdapter.

Instead, I had to obtain the LayoutInflater from the Context, so another parameter of type Context is needed in the constructor. If you want, I can provide you a pull request updating the documentation, and also the code if you're interested.

Keep up the good work!

voghDev avatar Aug 30 '17 06:08 voghDev

Have found the exact problem that you are writing about but I've not been able to solve it. I would, therefore, appreciate if you could describe your solution a bit more. Thanks in before!

Sanjot01 avatar Oct 26 '17 15:10 Sanjot01

Yes sorry, my explaination was lacking details. I tried to copy this code you provide in the README file

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    convertView = getLayoutInflater().inflate(R.layout.card, parent, false);
    TextView textViewCard = (TextView) convertView.findViewById(R.id.textViewCard);
    textViewCard.setText(mData.get(position));

    return convertView;
}

Then found that compiler marked me getLayoutInflater() in red. This method does not exist in my CardStackAdapter class. I solved it by passing a Context argument:

class CardStackAdapter(val context: Context, val otherArgs : SomeOtherArguments....) : BaseAdapter() {

and obtain the LayoutInflater like this

val inflater = context.getSystemService(LAYOUT_INFLATER_SERVICE) as LayoutInflater

So my issue was that there is no way of obtaining the LayoutInflater in the example code

voghDev avatar Oct 27 '17 13:10 voghDev