3

これは、カスタマイズされたリストビューを設定しているアクティビティShowData.javaです..今、そのリストビューのビューをクリックする必要があり、別のアクティビティを表示する必要がありますが、強制終了をスローします..エラーをスローします listview.setAdapter(adapter);

public class ShowData extends Activity
{

    ListView listview;
    Intent intent;
    ArrayList<BeanClass> datalist;
    CustomAdapter adapter;


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


        listview = (ListView) findViewById(R.id.listView1);

        Intent intent = getIntent();
        datalist = (ArrayList<BeanClass>) intent.getSerializableExtra("list");
        Log.i("Size of ArrayList", "is " +datalist.size());

            adapter = new CustomAdapter(ShowData.this, R.layout.customrow , datalist);

            listview.setAdapter(adapter);
          listview.setOnItemClickListener(new OnItemClickListener() 
            {
        @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) 
            {
                Intent i = new Intent(ShowData.this,DetailActivity.class);
                i.putExtra("datalist", datalist);
                i.putExtra("position", arg2);
                startActivity(i);
            }               
}  
}

こちらがCustomAdapter.java

public class CustomAdapter extends ArrayAdapter<BeanClass>
{
    Context context;
    int layoutResourceId;
    BeanClass bc;
    ArrayList<BeanClass> vbc;

    public CustomAdapter(Context context, int layoutResourceId, ArrayList<BeanClass> vbc) 
    {
        super(context, layoutResourceId, vbc);
        this.context=context;
        this.layoutResourceId=layoutResourceId;
        this.vbc=vbc;
    }

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

        if(row == null)
        {
            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent,false);

            holder= new StringReaderHolder();


            holder.mytext1 = (TextView) row.findViewById(R.id.textView1);
            holder.mytext2 = (TextView) row.findViewById(R.id.textView2);
            holder.mytext3 = (TextView) row.findViewById(R.id.textView3);

            row.setTag(holder);
        }
        else
        {
            holder = (StringReaderHolder) row.getTag();
        }

        BeanClass bsObject = vbc.get(position);

        holder.mytext1.setText(bsObject.name);
        holder.mytext2.setText(bsObject.address);
        holder.mytext3.setText(bsObject.phone);


        return row;
    }

    static class StringReaderHolder
    {

        TextView mytext1,mytext2,mytext3;

    }

}

setOnItemClickListener をどのように使用すればよいですか...??? ありがとう...

4

1 に答える 1

4

あなたのgetViewメソッドで試してください:

row.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent i = new Intent(context,DetailActivity.class);
                i.putExtra("datalist", vbc);
                i.putExtra("position", position);
                startActivity(i);
            }
        });
于 2012-09-04T07:55:52.007 に答える