0

を介して入力onItemClickListenerされた単純なものを設定しようとしていますListViewArrayAdapter

package it.polito.mad.task2;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.ListFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

public class listFragment extends ListFragment {

public View onCreateView(LayoutInflater li, ViewGroup vg, Bundle b){

        View v = li.inflate(R.layout.fraglist , vg, false); //inflate populates a view with desired content

        //use an adapter to load the imageviews in the fragment
        ListView listView = (ListView)v.findViewById(R.id.listViewListFrag); //get the resource id for the view to fill with data from adapter

        ArrayList<opera> pics = JsonLoad("list.json"); 
        operaAdapter adapter = new operaAdapter(this.getActivity(), R.layout.opera, R.id.element, pics);//create the adapter passing the parameter needed to load content to elements in the opera layout
        listView.setAdapter(adapter); //set the adapter for the view in the fragment

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int position,
                    long arg3) {
                AppObj app = (AppObj) getActivity().getApplication();
            Intent goToDet = new Intent(getActivity(),ActivityDetails.class);

            app.setItem(position);

            startActivity(goToDet);

            }
        });


        return v; 
    }
//more methods 
}

これがアダプタークラスです

package it.polito.mad.task2;

import java.io.IOException;
import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class operaAdapter extends ArrayAdapter<opera> {
    private Activity act;
    ArrayList<opera> list;
    private static LayoutInflater inflater=null;

    public operaAdapter(Activity a, int layout, int element, ArrayList<opera> res){//save in local variables content of parameters

        super(a, layout, res);
        act = a;
        list = res;

    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public opera getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TextView holder;

        if(convertView==null){
           inflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
           convertView = inflater.inflate(R.layout.opera, null);

            holder = (TextView) convertView.findViewById(R.id.element);
            convertView.setTag(holder);
        }
        else{
            holder = (TextView) convertView.getTag();
        }

        holder.setText(list.get(position).getTitle());

        Drawable d;
        try {
            d = Drawable.createFromStream(act.getAssets().open(list.get(position).getImage()), null);
            d.setBounds(0, 0, 200, 200); //set size of the drawable on the left of the text 
            holder.setCompoundDrawables(d, null, null, null);

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


        return convertView;
    }

}

いくつかのことを試しましたが、リスナーはイベントを取得していないようです。何か不足していますか?

4

1 に答える 1