1

我试图在我的 MainActivity 中实现“毕加索框架”,但它一直给我一个错误。就是在“Picasso.with(MainActivity.this)”这一行,“Picasso”下面有一条红线。有人可以帮帮我吗。我已经导入了 jar.file。

请看我的代码:

package com.chrfugl.xxxx;

import java.util.List;
import java.util.Vector;

import com.chrfugl.studenterhuset.R;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.net.ParseException;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class MainActivity extends ListActivity {
private LayoutInflater mInflater;
private Vector<RowData> data;
RowData rd;

public static final String[] title = new String[] {
        "1", 
        "2",
        "3",
        "4",
        "5, 
        "6",
        };

public static final String[] detail = new String[] {
    "Text",
    "Text",
    "Text",
    "Text",
    "Text",
    "Text",
    };

public static Integer[] imgid = { 
    R.drawable.1, R.drawable.2, 
    R.drawable.3, R.drawable.4, 
    R.drawable.5, R.drawable.6, 

};

public static final String[] footer = new String[] {
    "Text", 
    "Text",
    "\Text",
    "\Text",
    "\Text",
    "\Text",
    }; 

@Override
public void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mInflater = (LayoutInflater)     getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    data = new Vector<RowData>();
    for (int i = 0; i < title.length; i++) {

        try {
            rd = new RowData(i, title[i], detail[i]);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        data.add(rd);
    }
    CustomAdapter adapter = new CustomAdapter(this, R.layout.list_item, R.id.title, data);
    setListAdapter(adapter);
    getListView().setTextFilterEnabled(true);
}

public void onListItemClick(ListView parent, View v, int position, long id) {
    Intent intent = new Intent(this, NewActivity.class);
    intent.putExtra("position", position);
    startActivity(intent);
}

private class RowData {
    protected int mId;
    protected String mTitle;
    protected String mDetail;

    RowData(int id, String title, String detail) {
        mId = id;
        mTitle = title;
        mDetail = detail;
    }

    @Override
    public String toString() {
        return mId + " " + mTitle + " " + mDetail;
    }
}

private class CustomAdapter extends ArrayAdapter<RowData> {

    public CustomAdapter(Context context, int resource,
            int textViewResourceId, List<RowData> objects) {

        super(context, resource, textViewResourceId, objects);
    }

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

        ViewHolder holder = null;
        TextView title = null;
        TextView detail = null;
        ImageView i11 = null;
        RowData rowData = getItem(position);
        if (null == convertView) {
            convertView = mInflater.inflate(R.layout.list_item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        holder = (ViewHolder) convertView.getTag();
        title = holder.gettitle();
        title.setText(rowData.mTitle);
        detail = holder.getdetail();
        detail.setText(rowData.mDetail);

        i11 = holder.getImage();
        Picasso.with(MainActivity.this)
        .load(imgid[rowData.mId])
        .placeholder(android.R.color.black)
        .error(android.R.color.black)
        .resize(100, 100)
        .centerCrop()
        .into(i11);
        return convertView;
    }

    private class ViewHolder {
        private View mRow;
        private TextView title = null;
        private TextView detail = null;
        private ImageView i11 = null;

        public ViewHolder(View row) {
            mRow = row;
        }

        public TextView gettitle() {
            if (null == title) {
                title = (TextView) mRow.findViewById(R.id.title);
            }
            return title;
        }

        public TextView getdetail() {
            if (null == detail) {
                detail = (TextView) mRow.findViewById(R.id.detail);
            }
            return detail;
        }

        public ImageView getImage() {
            if (null == i11) {
                i11 = (ImageView) mRow.findViewById(R.id.img);
            }
            return i11;
        }
    }
}
}
4

1 回答 1

1

尝试这个-

CustomAdapter通过添加private Context变量来编辑您的类。然后,在 的构造函数中CustomAdapter,初始化该变量。

Context然后,您每次需要拨打电话时都会有参考资料Picasso

因此,自定义适配器应如下所示:

private class CustomAdapter extends ArrayAdapter<RowData> {

    private Context mContext;

    public CustomAdapter(Context context, int resource,
        int textViewResourceId, List<RowData> objects) {

        super(context, resource, textViewResourceId, objects);
        mContext = context;

    }...

然后像这样让毕加索打来电话getView()

Picasso.with(mContext)...并添加您需要的任何其他内容。

希望这可以帮助!

于 2013-06-26T15:25:15.403 回答