Create SimpleDateFormat for specified Locale

Create SimpleDateFormat for specified Locale - Hello Friend GENERAL INFO FOR ANDROID DEVELOPMENT, In the article you read this time with the title Create SimpleDateFormat for specified Locale, We have prepared this article for you to read and retrieve information there in. Hopefully the contents of postings Artikel Android code sample: Date Time, Artikel Android code sample: Locale, We write this you can understand. Alright, good read.

The Title : Create SimpleDateFormat for specified Locale
link : Create SimpleDateFormat for specified Locale

Read also


Create SimpleDateFormat for specified Locale

Example of creating SimpleDateFormat with specified Locale from previous exercise "Get default Locale and available Locales".

Create SimpleDateFormat with specified Locale


package com.example.androidlocale;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.app.Activity;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

TextView textViewDefaultLocale = (TextView)findViewById(R.id.defaultlocale);
TextView textViewNoOfLocale = (TextView)findViewById(R.id.numberoflocale);
ListView listViewAvailableLocale = (ListView)findViewById(R.id.listviewlocale);

Locale defaultLocale = Locale.getDefault();
textViewDefaultLocale.setText("Default Locale: " + defaultLocale.toString());

final Locale[] availableLocales = Locale.getAvailableLocales();
textViewNoOfLocale.setText("Number of available Locale: " + availableLocales.length);
String[] availableLocalesString = new String[availableLocales.length];

for (int i=0; i<availableLocales.length; i++){
availableLocalesString[i] = availableLocales[i].toString();
}

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, availableLocalesString);
listViewAvailableLocale.setAdapter(adapter);

listViewAvailableLocale.setOnItemClickListener(
new OnItemClickListener(){

@Override
public void onItemClick(AdapterView<?> parent,
View view, int position, long id) {
Locale item = availableLocales[position];

String format = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format, item);
Date now = new Date();
Toast.makeText(getApplicationContext(),
"Locale: " + item.toString() + "\n"
+ simpleDateFormat.format(now),
Toast.LENGTH_LONG).show();

}});

}

}



Thus Article Create SimpleDateFormat for specified Locale

The End Article Create SimpleDateFormat for specified Locale This time, hopefully can give benefits to all of you. well, see you in posting other articles.

You are now reading the article Create SimpleDateFormat for specified Locale with the link address http://xorislogo.blogspot.com/2013/09/create-simpledateformat-for-specified.html

0 Response to "Create SimpleDateFormat for specified Locale"

Post a Comment