【发布时间】:2016-01-11 13:33:01
【问题描述】:
我有一个 ListView,每个项目都有两张图片,希望你点击其中一张我用 zxing 读取 QR 码。
我在调用 startActivityForResult 方法时遇到错误,并且不知道哪个方法可以替换它或如何替换它。 我留下一些代码: 我的持有人班
public class ObrasHolder {
public ImageView foto;
public TextView num, iden, ubi,hombres,material,equipo;
public RelativeLayout fondo;
public TextView eq1, eq2, eq3, eq4;
public TextView g1,g2,g3,g4;
public ImageView cam,qr;
}
我的自定义适配器:
public class ObrasAdapter extends ArrayAdapter<Obra> {
public Context context;
private ArrayList<Obra> datos;
public void DisplayProjectListAdapter(Context c) {
context = c;
}
public ObrasAdapter(Context context, ArrayList<Obra> datos) {
super(context, R.layout.listview_item, datos);
this.context = context;
this.datos = datos;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View item = convertView;
ObrasHolder holder;
if (item == null) {
item = LayoutInflater.from(context).inflate(R.layout.listview_item,
null);
holder = new ObrasHolder();
holder.foto = (ImageView) item.findViewById(R.id.imgAnimal);
holder.num = (TextView) item.findViewById(R.id.numC);
holder.iden = (TextView) item.findViewById(R.id.idenC);
holder.ubi = (TextView) item.findViewById(R.id.ubiC);
holder.hombres = (TextView) item.findViewById(R.id.homC);
holder.material = (TextView) item.findViewById(R.id.matC);
holder.eq1 = (TextView) item.findViewById(R.id.eq1);
holder.eq2 = (TextView) item.findViewById(R.id.eq2);
holder.eq3 = (TextView) item.findViewById(R.id.eq3);
holder.eq4 = (TextView) item.findViewById(R.id.eq4);
holder.g1 = (TextView) item.findViewById(R.id.g1);
holder.g2 = (TextView) item.findViewById(R.id.g2);
holder.g3 = (TextView) item.findViewById(R.id.g3);
holder.g4 = (TextView) item.findViewById(R.id.g4);
holder.fondo = (RelativeLayout) item.findViewById(R.id.fondobra);
holder.cam = (ImageView) item.findViewById(R.id.cam);
holder.qr = (ImageView) item.findViewById(R.id.qr);
item.setTag(holder);
}
holder = (ObrasHolder) item.getTag();
holder.qr.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0); //Error because is undefined for the type new View.OnClickListener(){}
}
});
return item;
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
}
有办法解决吗?
我也给出了另一个错误。在方法 onActivityResult。 谢谢!!
【问题讨论】:
标签: android android-intent android-listview