Date Calendar Java Android Example
Calendar cal = new GregorianCalendar(), int year = cal.get(Calendar.YEAR),
ERA, MONTH, DAY_OF_MONTH, DAY_OF_WEEK, Android example code.
ERA, MONTH, DAY_OF_MONTH, DAY_OF_WEEK, Android example code.
public class MainActivity extends Activity {
TextView txtV;
Context cntx;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txtV = (TextView)findViewById(R.id.idLabel);
cntx = this;
Calendar cal = new GregorianCalendar();
int era = cal.get(Calendar.ERA); // 0 B.C. before Christ, 1 Anno Domini
txtV.setText(txtV.getText() +"
" + era);
int year = cal.get(Calendar.YEAR); // 2011
txtV.setText(txtV.getText() +"
" + year);
int month = cal.get(Calendar.MONTH); // 0 is Januar
txtV.setText(txtV.getText() +"
" + month);
int day = cal.get(Calendar.DAY_OF_MONTH); // 1 to 31
txtV.setText(txtV.getText() +"
" + day);
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); // 1=Sunday, 2=Monday ...
txtV.setText(txtV.getText() +"
" + dayOfWeek);
}
}
396LW NO topic_id
AD
Další témata ....(Topics)
FLAG_KEEP_SCREEN_ON saving energy. Protects the battery if a user closing applications using the Return button on device. The device will returned to user screen mode settings.
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
//..........
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
Try some solution - each individually or all
- Check AndroidManifest.xml activity declaration
<activity android:name=".EnableProfileActivity" android:label="@string/app_name" />
- Delete BUILD folder in module tree and Clean / Rebuild project
- Restart Android Studio
Unable to resolve target android-7
Try this solution:
Select project from tree (project explorer)
- right click on project
- properties
- select Android from tree
- change Project Build Target to higher (or change project build target)
- selct from menu: Project-Clean ( select your project - OK)
Try this solution:
Select project from tree (project explorer)
- right click on project
- properties
- select Android from tree
- change Project Build Target to higher (or change project build target)
- selct from menu: Project-Clean ( select your project - OK)
BufferedReader , FileReader, StringBuilder , readLine, close Java example
Android example
Java example
Android example
String MYFILE = "my_file";
FileInputStream fis = openFileInput(MYFILE);
int c; String sText = "";
while((c=fis.read())!=-1)
{
sText += (char)c; // convert int to char
}
fis.close();
Java example
try {
BufferedReader in = new BufferedReader(new FileReader("myfile.txt"));
StringBuilder strBuilder = new StringBuilder();
String str;
while ((str = in.readLine()) != null) {
strBuilder.append(str);
}
in.close();
} catch (IOException e) {
e.toString();
}
Editace: 2011-09-29 13:32:10
Počet článků v kategorii: 396
Url:date-calendar-java-android-example