0

私はニュースアプリケーションを構築しています。URL からのデータを使用して ListView にニュースを表示したいと考えています。しかし、最初の行にデータを入れて ListView ヘッダーを表示するのではなく、最初の行をスキップする必要があります。これは別のレイアウトで膨らんでいますが、このアダプター クラスを変更することはできません。誰でも私を助けることができますか?

public class LazyAdapter extends BaseAdapter {

    private Activity activity;
    private ArrayList<HashMap<String, String>> data;
    private static LayoutInflater inflater=null;
    public ImageLoader imageLoader; 

    public LazyAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
        activity = a;
        data=d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader=new ImageLoader(activity.getApplicationContext());
    }

    public int getCount() {
        return data.size();
    }

    public Object getItem(int position) {
        return position;
    }

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

    public View getView(int position, View convertView, ViewGroup parent) {

        View vi=convertView;
        if(position==0){
            vi = inflater.inflate(R.layout.list_row_main, null);
        }else{
            vi = inflater.inflate(R.layout.list_row, null);
        }

        TextView title = (TextView)vi.findViewById(R.id.title); // title
        TextView big_img = (TextView)vi.findViewById(R.id.einfo3); // artist name
        TextView author = (TextView)vi.findViewById(R.id.einfo1); // duration
        TextView datetimev = (TextView)vi.findViewById(R.id.tVdatetime);
        TextView story = (TextView)vi.findViewById(R.id.einfo2);
        ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); // thumb image

        HashMap<String, String> n = new HashMap<String, String>();
        n = data.get(position);

        // Setting all values in listview
        title.setText(n.get(Home.TAG_TITLE));
        author.setText(n.get(Home.TAG_AUTHOR));
        datetimev.setText(n.get(Home.TAG_DATETIME));
        story.setText(n.get(Home.TAG_STORY));
        thumb_image.setTag(n.get(Home.TAG_BIG_IMG));
        imageLoader.DisplayImage(n.get(Home.TAG_BIG_IMG), thumb_image);
        return vi;
    }
}
4

1 に答える 1

0

ListView.addHeaderView()を使用することをお勧めします。

listView.addHeaderView(getLayoutInflater().inflate(R.layout.list_row_main, null));
于 2012-09-03T18:45:20.300 に答える