0
當我試圖在列表視圖中實現顯示數組值和圖像時,它顯示了紅線錯誤刪除覆蓋令牌的oncreate和在listview公共標識符也顯示紅線錯誤。Android onCreate - 令牌「覆蓋」的語法錯誤,刪除此令牌
這裏是我的代碼:
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
public class ScanNow extends Activity{
ListView listView;
public Integer[] imgid = {R.drawable.image1,R.drawable.image2,R.drawable.image3,R.drawable.image4,
R.drawable.image6,R.drawable.image7,R.drawable.image8,R.drawable.image9,
R.drawable.image10,R.drawable.image11,R.drawable.image12,R.drawable.image13};
SampleAdapter sAdapter;
public String[] imageNames ={"Deli Purchase of $5 or more","20-oz. or Large Market Pantry frozen chicken item","64-oz. Market Pantry juice or juice cocktails","With Purchase of any two Betty Crocker items","4.2-lb. or larger Kingsford charcoal","Engergizer batteries","$10 or higher Energizer flashlight","With purchase of any two axe items","Fresh fruit purchase of $5 or more","Fresh meat purchase of $5 orr more","Fresh vegetable purchase of $5 or more","With purchase of two 5-oz. or larger Market Pantry cheeses"};
public String[] imagePrice ={"$2 off","$1 off","$1 off","75ç off","1$ off","1$ off","2$ off","1$ off","$1 off","$1 off","$1 off","$1 off"};
Context ct;
Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.scannow);
ct=this;
listView=(ListView)findViewById(R.id.listView1);
sAdapter=new SampleAdapter(ct);
listView.setAdapter(sAdapter);
}
class SampleAdapter extends BaseAdapter{
LayoutInflater li;
Context c;
ImageView img;
TextView price,desc;
Override
public SampleAdapter(Context ct1) {
c=ct1;
}
public int getCount() {
// TODO Auto-generated method stub
return imgid.length;
}
Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
Override
public View getView(int arg0, View arg1, ViewGroup arg2) {
li=(LayoutInflater)c.getSystemService(LAYOUT_INFLATER_SERVICE);
arg1=li.inflate(R.layout.barcode_products_freeitemcell, null);
img=(ImageView)arg1.findViewById(R.id.priceimage);
price=(TextView)arg1.findViewById(R.id.priceoff);
desc=(TextView)arg1.findViewById(R.id.pricedesc);
img.setImageResource(imgid[arg0]);
price.setText(imagePrice[arg0]);
desc.setText(imageNames[arg0]);
return arg1;
}
}
}