我是 Android 新手。我在列表视图中有很多项目。我想将列表项中的日期与当前日期进行比较,并停用日期已过期的列表项。我尝试了很多东西,但找不到正确的答案。
我试过的代码是
public class TestApp extends Activity
{
Activity context;
ListView lv = null;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.testlist);
lv = (ListView) findViewById(R.id.testAppList);
Log.v("finished dateslist", "true");
String dateFormat="dd-MMM-yyyy";
DateFormat formatter = null;
Calendar calendar = null;
formatter = new SimpleDateFormat(dateFormat);
// Date date = new Date(0);
long date = System.currentTimeMillis();
final String current_date = formatter.format(date);
//Calendar cal = Calendar.getInstance();
//String current_date = dateFormat.format(cal.getTime());
Log.d("Current date", current_date);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long arg3) {
int i;
/*arg1.setEnabled(false);
if(!arg1.isEnabled())
{
lv.setSelector(android.R.color.transparent);
lv.setActivated(false);
}*/
for(i=0;i<Constants.test_endDate.size();i++)
{
if((current_date.compareTo(Constants.test_endDate.get(i)))>0)
{
Constants.selected_test_id = Integer.parseInt(Constants.test_ID.get(position));
Constants.selected_testName = Constants.test_name.get(position);
Constants.selected_test_total_questions = Constants.test_totalQuestions.get(position);
Constants.selected_testTimeleft = Constants.test_duration.get(position);
Constants.selected_testcmid = Constants.test_cmid.get(position);
displayInstructionsPage();
break;
}
else
{
arg1.setClickable(true);
arg1.setFocusable(true);
arg1.setEnabled(false);
Toast.makeText(getApplicationContext(), "Date Expired", Toast.LENGTH_SHORT).show();
if(!arg1.isEnabled())
{
lv.setSelector(android.R.color.transparent);
lv.setActivated(false);
}
break;
}
}
}
});
请帮助解决问题。