Androidのリストに少し問題があります。たとえば、Android アプリケーションを作成しました。このアプリケーションでは、リストの要素を照会しますが、System.out.println で表示すると、常に最後の要素を取得します。
私の主なアクティビティ:
package djukic.tests.list;
import java.util.ArrayList;
import java.util.List;
import djukic.tests.list.TagData;
import android.os.Bundle;
import android.app.Activity;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
returnTG();
}
public List<TagData> returnTG ()
{
List<TagData> list =new ArrayList<TagData>();
TagData t1 = new TagData();
TagData test = new TagData();
for(int i=0; i <= 2 ; i++)
{
t1.setName("Motor" + i);
list.add(t1);
}
System.out.println("list size = " + list.size());
test = list.get(0);
System.out.println("test.getName 2 = " + test.getName());
test = list.get(1);
System.out.println("test.getName 2 = " + test.getName());
test = list.get(2);
System.out.println("test.getName 2 = " + test.getName());
return list;
}
}
そして私のTAGDATA.JAVA:
package djukic.tests.list;
public class TagData
{
String name, last, tagID;
int repetition, sollAmount, lastAmount;
public TagData()
{
}
public TagData(String name, int repetition, int sollAmount, int lastAmount, String last, String tagID)
{
this.name = name;
this.repetition = repetition;
this.sollAmount = sollAmount;
this.lastAmount = lastAmount;
this.last = last;
this.tagID = tagID;
}
//get Methods
public String getName()
{
return name;
}
public int getRepetition()
{
return repetition;
}
public int getsollAmount()
{
return sollAmount;
}
public int getlastAmount()
{
return lastAmount;
}
public String getlastDate()
{
return last;
}
public String getTagID()
{
return tagID;
}
//set Methods
public void setName(String name)
{
this.name = name;
}
public void setRepetition(int repetition)
{
this.repetition = repetition;
}
public void setsollAmount(int sollAmount)
{
this.sollAmount = sollAmount;
}
public void setlastAmount(int letzteAmount)
{
this.lastAmount = letzteAmount;
}
public void setlastDate(String last)
{
this.last = last;
}
public void setTagID(String tagID)
{
this.tagID = tagID;
}
}