出力として test30 しか取得できません。
主な活動:
public class MainActivity extends Activity {
ListView listview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listview = (ListView) findViewById(R.id.listView);
Product[] items = {
new Product("test1",07,07,2013),
new Product("test2",07,07,2013),
new Product("test3",07,07,2013),
};
ArrayAdapter<Product> adapter = new ArrayAdapter<Product>(this,
android.R.layout.simple_list_item_1, items);
listview.setAdapter(adapter);
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
String item = ((TextView)view).getText().toString();
Toast.makeText(getBaseContext(), item, Toast.LENGTH_LONG).show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
製品.java
public class Product {
static String name;
static int day;
static int month;
static int year;
static String res;
public Product(){
super();
}
public Product(String name, int day, int month, int year) {
super();
this.name = name;
this.day = day;
this.month = month;
this.year = year;
Calendar thatDay = Calendar.getInstance();
thatDay.set(Calendar.DAY_OF_MONTH,this.day);
thatDay.set(Calendar.MONTH,this.month-1); // 0-11 so 1 less
thatDay.set(Calendar.YEAR, this.year);
Calendar today = Calendar.getInstance();
long diff =thatDay.getTimeInMillis()- today.getTimeInMillis(); //result in millis
long days = diff / (24 * 60 * 60 * 1000);
res=String.valueOf(days);
}
@Override
public String toString() {
return this.name+this.res ;
}
}