0

I'm trying to make my list views render some simple tags in a list view, here is my code:

package net.mikepearce.theagileguide.fragment;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.text.Html;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import net.mikepearce.theagileguide.R;
import net.mikepearce.theagileguide.ValueActivity;

public class ListManifestoFragment extends ListFragment {

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Set the adapter based on the string-array
        String[] principles = getResources().getStringArray(R.array.manifesto_values);
        ArrayAdapter adapter = new ArrayAdapter<String>(getActivity(), R.layout.list_values, principles )
        {
            @Override
            public View getView(int position, View convertView, ViewGroup parent)
            {
                View row;

                if (null == convertView) {
                    row = mInflater.inflate(R.layout.list_values, null);
                } else {
                    row = convertView;
                }

                TextView tv = (TextView) row.findViewById(android.R.id.text1);
                tv.setText(Html.fromHtml(getItem(position)));

                return row;
            }

        };

        setListAdapter(adapter);

        // Get the list view
        final ListView listView = getListView();
        listView.setTextFilterEnabled(true);

        // When clicked, pass to new Activity with the position as a parameter
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Activity a = getActivity();
                Intent intent = new Intent(view.getContext(), ValueActivity.class);
                intent.putExtra("value_id", position);
                startActivity(intent);
                a.overridePendingTransition(0,0);
            }
        });

    }

}

Which I got, in part, from here: https://stackoverflow.com/a/9695159/155227

I'm very new to Android Dev, so I'm not sure whether this is what I should be doing and, if so, where the mInflater is coming from, as I get an error.

Can someone help?

Thanks,

Mike

2 Answers 2

1

mInflater should be a LayoutInflater. You should be able to replace mInflater with getActivity().getLayoutInflater().

Sign up to request clarification or add additional context in comments.

Comments

0

use this code under View row;

LayoutInflater mInflater= ((Activity)context).getLayoutInflater();

2 Comments

That will not work, as this code is in a fragment, not an activity, and there is nothing in the code there that I can see that is named context.
for that context u use ur Activityname.this or For fragment ((Activity)context).getLayoutInflater() use getActivity().getLayoutInflater();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.