Saturday, 11 July 2015

Today Date and Last day of Month

public class GetLastDayOfMonth {   
 
    public static void main(String[] args) {  
 
        Date today = new Date();  
 
        Calendar calendar = Calendar.getInstance();  
        calendar.setTime(today);  
 
        calendar.add(Calendar.MONTH, 1);  
        calendar.set(Calendar.DAY_OF_MONTH, 1);  
        calendar.add(Calendar.DATE, -1);  
 
        Date lastDayOfMonth = calendar.getTime();  
 
        DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");  
        System.out.println("Today            : " + sdf.format(today));  
        System.out.println("Last Day of Month: " + sdf.format(lastDayOfMonth));  
    }   
 
}  
Output:
Today            : 2010-08-03  
Last Day of Month: 2010-08-31 

Friday, 3 July 2015

Change Background image of child image item of listview When click on any listitem .

listview.setOnItemClickListener(new OnItemClickListener()
 {

@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id) 
{
ImageView img = 
           (ImageView) parent.getChildAt(position).findViewById(R.id.imgitem);
img.setImageResource(R.drawable.watchcolored);
}
});
}

Wednesday, 1 July 2015

Styling EditText in Android .

edit_text.xml


<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:state_window_focused="false"
        android:state_enabled="true"
        android:drawable="@drawable/textfield_default" />
 
    <item
        android:state_window_focused="false"
        android:state_enabled="false"
        android:drawable="@drawable/textfield_disabled" />
 
    <item
        android:state_pressed="true"
        android:drawable="@drawable/textfield_pressed" />
 
    <item
        android:state_enabled="true"
        android:state_focused="true"
        android:drawable="@drawable/textfield_selected" />
 
    <item
        android:state_enabled="true"
        android:drawable="@drawable/textfield_default" />
 
    <item
        android:state_focused="true"
        android:drawable="@drawable/textfield_disabled_selected" />
 
    <item
        android:drawable="@drawable/textfield_disabled" />
 
</selector>

Hear , Instead of Attach Drawable , you can give Color (solid ) , Border etc..