我正在尝试显示产品列表,但是当我运行应用程序时,它确实在设备上显示任何内容。我无法弄清楚我的问题在哪里。我想在MainActivity.java上填充数据。
MainActivity.java
TwoDimensionalShape* ptr_shape = dynamic_cast<TwoDimensionShape*>(object);
if(ptr_shape)
{
ptr_shape->getPerimeter(/*arguments here if you have them...*/)
}
ProductListAdapater.java
public class MainActivity extends AppCompatActivity {
// ProductsListAdapter productsListAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView productlistview = (ListView) findViewById(R.id.productlistview);
// productsListAdapter = new ProductsListAdapter()
// productlistview.setAdapter(productsListAdapter);
}
private List<Product> createListofProducts(){
ArrayList<Product> productArrayList = new ArrayList<Product>();
productArrayList.add(new Product("Kimbo", 50.0, 0, " "));
productArrayList.add(new Product("Sugar", 60.0, 0, " "));
productArrayList.add(new Product("Oil", 70.0, 0, " "));
productArrayList.add(new Product("Bread", 40.0, 0, " "));
productArrayList.add(new Product("water", 30.0, 0, " "));
return productArrayList;
}
}
答案 0 :(得分:1)
这样的事情怎么样?
ListView productlistview = (ListView) findViewById(R.id.productlistview);
productsListAdapter = new ProductsListAdapter(this, createListofProducts())
productlistview.setAdapter(productsListAdapter);