I am making a NEWS Android application. All the data I am fetching from NewaApi using JSON parsing. I am also collecting the date information from the API in 'YYYY-MM-DD' format. I want to convert the format into DD-MM-YYYY. Here is my code for the Adapter class.
public class NewsAdapter extends ArrayAdapter<NewsData> {
public NewsAdapter(Context context, List<NewsData> news) {
super(context, 0, news);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View listItemView = convertView;
if (listItemView == null) {
listItemView = LayoutInflater.from(getContext()).inflate(
R.layout.news_list, parent, false);
}
NewsData currentNews = getItem(position);
TextView headlineView = listItemView.findViewById(R.id.headline);
headlineView.setText(currentNews.getmHeadline());
String originalTime = currentNews.getmDate_time();
String date;
if (originalTime.contains("T")) {
String[] parts = originalTime.split("T");
date = parts[0];
} else {
date = getContext().getString(R.string.not_avilalble);
}
TextView dateView = listItemView.findViewById(R.id.date);
dateView.setText(date);
String imageUri=currentNews.getmImageUrl();
ImageView newsImage = listItemView.findViewById(R.id.news_image);
Picasso.with(getContext()).load(imageUri).into(newsImage);
return listItemView;
}
}
A am also adding the image of how the format looks in JSON.