我不明白以下代码:
public class EventAdapter extends ArrayAdapter<Event>
{
public EventAdapter(Context context, int textViewResourceId,
List<Event> objects)
{
super(context, textViewResourceId, objects);
this.resource = textViewResourceId;
}
}
Run Code Online (Sandbox Code Playgroud)
我对<Event>两种情况下的部分感到困惑.我知道它与泛型有关,但我不明白.我阅读http://docs.oracle.com/javase/tutorial/java/generics/,但仍然不明白.
我确实理解这objects是一种ArrayList类型的对象Event.
我不明白的部分是使用Type扩展ArrayAdapter <Event>.这意味着什么?
如何从用户输入项目(名称,成本,优先级)中将3个项目放入一个对象项目中,并将该对象项目放入其他对象的数组中?
public class Main {
public static void main(String[] args) {
//here are my variables.
//I'm pretty sure a few of these should be defined
// in their own item class.
int i=0;
String name1;
int priority1;
double cost1;
//String[] shoppingList = new String[7];
String[] item = new String[7];
// I am able to grab input from the user for all 3 elements of
// an item object (name, cost, priority)
// I am missing how to save these 3 …Run Code Online (Sandbox Code Playgroud) 我已经学会了如何创建对象的Arraylist,这样的数组本质上是动态的.例如,要创建一个包含3个字段的对象数组(类Matrices的实例),代码如下所示:
ArrayList<Matrices> list = new ArrayList<Matrices>();
list.add( new Matrices(1,1,10) );
list.add( new Matrices(1,2,20) );
Run Code Online (Sandbox Code Playgroud)
此外,Matrices课程如下:
public class Matrices{
int x;
int y;
int z;
Matrices(int x,int y, int z){
this.x = x;
this.y = y;
this.z = z;
}
}
Run Code Online (Sandbox Code Playgroud)
现在,如何从该数组名称访问任何元素的每个字段list?特别是,如何20从该数组的第二个元素访问该字段,其值为(1,2,20)?