1

I m new to Android.I had many items in listview. I want to compare the date in list item with the current date and to deactivate the list items whose date has expired. I tried many things but could not find right answer.

The code which I tried is

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;
                }                       
            }                           
        }           
    }); 

please help to sort out the problem.

Veaceslav Gaidarji
  • 4,103
  • 3
  • 30
  • 60
Saba Sayed
  • 163
  • 2
  • 4
  • 10

1 Answers1

0

A Java representation of the SQL TIMESTAMP type. It provides the capability of representing the SQL TIMESTAMP nanosecond value, in addition to the regular date/time value which has millisecond resolution.

The Timestamp class consists of a regular date/time value, where only the integral seconds value is stored, plus a nanoseconds value where the fractional seconds are stored.

The addition of the nanosecond value field to the Timestamp object makes it significantly different from the java.util.Date object which it extends. Users should be aware that Timestamp objects are not interchangable with java.util.Date objects when used outside the confines of the java.sql package.

may this will help you

Community
  • 1
  • 1
Basbous
  • 3,874
  • 4
  • 31
  • 60