0
Android有點問題。 硅繼承人怎麼回事,我有一個自定義適配器的ListView,什麼IAM特林做的是動態地添加行,繼承人的代碼:Android將行添加到帶有自定義適配器的ListView
適配器:
public class ProductAdapter extends ArrayAdapter<Product>{
Context context;
int layoutResourceId;
String data[] = null;
public ProductAdapter(Context context, int layoutResourceId,String[] data) {
super(context, layoutResourceId);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data=data;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
ProductHolder holder = null;
if(row == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new ProductHolder();
holder.nameText = (TextView)row.findViewById(R.id.product_name);
holder.quantityText = (EditText)row.findViewById(R.id.quan_text);
row.setTag(holder);
}
else
{
holder = (ProductHolder)row.getTag();
}
Product product = DBAdaptor.getProductByName(data[position]);
holder.img=(ImageView)row.findViewById(R.id.imgIcon);
holder.nameText.setText(product.getName());
holder.quantityText.setText(" ");
return row;
}
static class ProductHolder
{
ImageView img;
TextView nameText;
EditText quantityText;
}
}
這裏是我的主要活動:
public class Main extends Activity
{
public ListView lstView;
ProductAdapter productListAdapter;
DBAdaptor mDb;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main_screen);
openDB();
productListAdapter = new ProductAdapter(this, R.layout.shoping_list_row,getAllProducts());
Bundle b = this.getIntent().getExtras();
if(b!=null)
{
Product p =(Product) b.getSerializable("Product");
productListAdapter.add(p);
productListAdapter.notifyDataSetChanged();
}
}
}
世界上沒有錯誤來了,但沒有什麼是被add'd到ListView
類Reggards,