TodoList application android - java

Please I need your help .I'am trying to take the date from an activity and then put it in an array list then print it in an ListView .
The problem is the data that I should take it from "Adding Todo" is not showing in the ListView . it do take me to the List Activity but without showing the data .
This is How the app going to be "Adding todo"
And this is the ListView where the data should be in it
My code :-
MainActivity
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = findViewById(R.id.list_view);
arrayList = new ArrayList<>();
todoAdapter = new TodoAdapter(this , arrayList);
listView.setAdapter(todoAdapter);
}
public void onClick(View view) {
Intent intent = new Intent();
intent.setClass(MainActivity.this, AddTodo.class);
startActivityForResult(intent, Intent_Constants.INTENT_REQUEST_CODE);
}
protected void onActivityResult(int reqCode ,int resultCode , Intent data ){
// here Iam trying to get the data from ADDING TO DO class
if(resultCode == Intent_Constants.INTENT_REQUEST_CODE){
titleText = data.getStringExtra(Intent_Constants.INTENT_TITLE);
priorityText = data.getStringExtra(Intent_Constants.INTENT_PRIORITY);
statusText = data.getStringExtra(Intent_Constants.INTENT_STATUES);
dateText = data.getStringExtra(Intent_Constants.INTENT_DATE);
timeText = data.getStringExtra(Intent_Constants.INTENT_TIME);
todoAdapter.todo.add(new Todo (titleText , statusText ,priorityText ,dateText ,timeText));
}
}
Intent_Constants
public class Intent_Constants {
public final static int INTENT_REQUEST_CODE = 1;
public final static int INTENT_RESULT_CODE = 1 ;
public final static String INTENT_TITLE = "Title";
public final static String INTENT_PRIORITY = "Priority";
public final static String INTENT_TIME = "Time";
public final static String INTENT_DATE = "Date";
public final static String INTENT_STATUES = "Statues";
}
AddTodo class
In this class I find the id then I converted to String
public void saveButton (View view){
Intent intent = new Intent();
intent.putExtra(Intent_Constants.INTENT_TITLE , title);
intent.putExtra(Intent_Constants.INTENT_DATE , date);
intent.putExtra(Intent_Constants.INTENT_TIME , time);
intent.putExtra(Intent_Constants.INTENT_PRIORITY , priority);
intent.putExtra(Intent_Constants.INTENT_STATUES , completed);
setResult(INTENT_RESULT_CODE, intent);
finish();
}
TodoAdapter class
ArrayList<Todo> todo ;
public TodoAdapter(#NonNull Context context, ArrayList<Todo> todo) {
super(context, R.layout.todo_list,todo);
this.todo = todo;
}
public static class ViewHolder {
TextView titleText;
TextView priorityText;
TextView dateText;
TextView timeText;
CheckBox statusBox;
ImageButton edit_image;
ImageButton open_image;
ImageButton delet_image;
}
#NonNull
#Override
public View getView(int position, #Nullable View convertView, #NonNull ViewGroup parent) {
ViewHolder holder = null;
LayoutInflater inflater = LayoutInflater.from(getContext()) ;
View customeView =inflater.inflate(R.layout.todo_list,parent ,false);
holder.titleText.setText(getItem(position).getTitle());
holder.priorityText.setText(getItem(position).getPriority());
holder.dateText.setText(getItem(position).getDate());
holder.timeText.setText(getItem(position).getTime());
holder.statusBox.setChecked(false);
holder.edit_image = customeView.findViewById(R.id.edit_imageView);
holder.open_image = customeView.findViewById(R.id.open_imageButton);
holder.delet_image = customeView.findViewById(R.id.delete_imageView);
holder.edit_image.setImageResource(R.drawable.ic_edit_black_24dp);
holder.open_image.setImageResource(R.drawable.ic_refresh_black_24dp);
holder.delet_image.setImageResource(R.drawable.ic_delete_black_24dp);
return customeView;
}
Todo class
public class Todo {
private String title ;
private String status ;
private String priority ;
private String date ;
private String time ;
public Todo() {
}
public Todo(String title, String status, String priority, String date, String time) {
this.title = title;
this.status = status;
this.priority = priority;
this.date = date;
this.time = time;
}
public String getTitle() {
return title;
}
public String getStatus() {
return status;
}
public String getPriority() {
return priority;
}
public String getDate() {
return date;
}
public String getTime() {
return time;
}
public void setTitle(String title) {
this.title = title;
}
public void setStatus(String status) {
this.status = status;
}
public void setPriority(String priority) {
this.priority = priority;
}
public void setDate(String date) {
this.date = date;
}
public void setTime(String time) {
this.time = time;
}
}

You can just set a new adapter, I know it isn't best way, but should do the work. Don't create new one, but nulify yours, and initialize it with new data.

#Noura change this
arrayList.add(new Todo(titleText , statusText ,priorityText ,dateText ,timeText));
to
todoAdapter.todo.add(new Todo(titleText , statusText ,priorityText ,dateText ,timeText));
todoAdapter.notifyDataSetChanged();
and at the constructor u need to update your code like below
ArrayList<Todo> todo ;
public TodoAdapter(#NonNull Context context, ArrayList<Todo> todo) {
this.todo = todo
super(context, R.layout.todo_list,todo);
}

Related

The date of audio file is same for all audio file

When I run this code I get all the list of image give below audio files but, the date of all the audio files are same like 20 Jan 1970 . below the code of AudioActivity.java. I don't know how I can do it if is possible .
public class AudioActivity extends AppCompatActivity {
Adapter adapter;
RecyclerView recyclerView;
private SlideAdapter slideAdapter;
public static final int PERMIT = 1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_audio);
Toolbar toolbar = findViewById(R.id.aa_toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(true);
getSupportActionBar().setTitle("Call Tank");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
recyclerView = findViewById(R.id.recyclerview);
fetchSongs();
}
private void fetchSongs() {
//define list to carry songs
List<ModelClass> songs = new ArrayList<>();
Uri songLibraryUri;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
songLibraryUri = MediaStore.Audio.Media.getContentUri(MediaStore.VOLUME_EXTERNAL);
} else {
songLibraryUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
}
//projection
String[] projection = new String[]{
MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.DISPLAY_NAME,
MediaStore.Audio.Media.DATE_MODIFIED,
MediaStore.Audio.Media.DATA
};
//sort order
String sortOrder = MediaStore.Audio.Media.DATE_ADDED + " DESC";
//Querying
try (Cursor cursor = getContentResolver().query(songLibraryUri, projection, null, null, sortOrder)) {
// cache the cursor indices
int idColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media._ID);
int nameColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME);
int dateColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATE_MODIFIED);
int pathColimn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);
//getting the values
while (cursor.moveToNext()) {
// get values of colums for a give audio files
long id = cursor.getLong(idColumn);
String name = cursor.getString(nameColumn);
long date = cursor.getLong(dateColumn);
String path = cursor.getString(pathColimn);
//song uri
Uri uri = ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, id);
//remove .mp3 extension on song's name
name = name.substring(0, name.lastIndexOf("."));
// song item
ModelClass song = new ModelClass(path, name, uri, date);
// add song to songs list
songs.add(song);
}
Intent i = new Intent(AudioActivity.this,Onboarding.class);
Bundle bundle = new Bundle();
bundle.putSerializable("songs", (Serializable) songs);
i.putExtras(bundle);
startActivity(i);
//Intent intent = new Intent(AudioActivity.this,Onboarding.class);
// intent.putExtra("songs", (Serializable) songs);
//show songs on rv
showSongs(songs);
Toast.makeText(this, "Number of Songs:" + songs.size(), Toast.LENGTH_SHORT).show();
}
}
private void showSongs(List<ModelClass> songs) {
// songs.clear();
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setOrientation(RecyclerView.VERTICAL);
recyclerView.setLayoutManager(layoutManager);
adapter = new Adapter(songs);
recyclerView.setAdapter(adapter);
}
#Override
public boolean onOptionsItemSelected(#NonNull MenuItem item) {
item.getItemId();
return super.onOptionsItemSelected(item);
}
}
Below the code of Adapter.java
public class Adapter extends RecyclerView.Adapter<Adapter.ViewHolder> {
List<ModelClass> songs;
public Adapter(List<ModelClass> songs) {
this.songs = songs;
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
// View view = LayoutInflater.from(parent).inflate(R.layout.item_layout,parent,false);
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View view = inflater.inflate(R.layout.item_layout,parent,false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
ModelClass modelClass = songs.get(position);
String file = modelClass.getFilename();
holder.fileName.setText(file);
Long dateTime = modelClass.getDate();
String currentDate = DateFormat.getDateInstance().format(dateTime);
holder.date.setText(currentDate);
MediaPlayer mediaPlayer = new MediaPlayer();
String audioPath = modelClass.getPath();
try {
mediaPlayer.setDataSource(audioPath);
} catch (IOException e) {
e.printStackTrace();
}
holder.play.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
try {
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mP) {
mP.start();
holder.play.setVisibility(View.INVISIBLE);
holder.pause.setVisibility(View.VISIBLE);
}
});
mediaPlayer.prepare();
} catch (IOException e) {
e.printStackTrace();
}
}
});
holder.pause.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mediaPlayer.stop();
holder.play.setVisibility(View.VISIBLE);
holder.pause.setVisibility(View.INVISIBLE);
}
});
}
#Override
public int getItemCount() {
return songs.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
ImageView play , pause;
TextView fileName, date;
public ViewHolder(#NonNull View itemView) {
super(itemView);
play = itemView.findViewById(R.id.play);
pause= itemView.findViewById(R.id.pause);
fileName = itemView.findViewById(R.id.fileName);
pause.setVisibility(View.INVISIBLE);
date = itemView.findViewById(R.id.date);
}
}
} // the code end
Date of all the audio files are same in the list
This is ModalClass.java
public class ModelClass {
String path,filename;
Uri uri;
Long date;
public ModelClass(String path, String filename, Uri uri, Long date) {
this.path = path;
this.filename = filename;
this.date = date;
this.uri = uri;
}
public ModelClass() {
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public String getFilename() {
return filename;
}
public void setFilename(String filename) {
this.filename = filename;
}
public Uri getUri() {
return uri;
}
public void setUri(Uri uri) {
this.uri = uri;
}
public Long getDate() {
return date;
}
public void setDate(Long date) {
this.date = date;
}
}
Long dateTime = modelClass.getDate()
You did not post the code for getDate() while there starts your problem.
It problably returns 0 for all files.
And 0 equals 20 Jan 1970.

I have problem in transferring data from activity to another activity

public class Memo extends AppCompatActivity {
DBHandler dbh;
Notes items;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_memo);
getSupportActionBar().hide();
try{
dbh = new DBHandler(this);
}
catch (Exception ex){
ex.printStackTrace();
}
display();
}
public void display( ){ //method to display all items in the database
List<Notes> books_list = dbh.getNotes(); ////here i get the list fromm the database
///// i used a custom adapter because i needed it
final myAdapter adapter = new myAdapter(this, books_list); ///creating adapter from
myadapter to link it with the list
ListView _note_ = findViewById(R.id.list_txt);
_note_.setAdapter(adapter);
_note_.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
items = (Notes) adapter.getItem(position);
String Note_content = items.getNote();
String title = items.getTitle();
String Date = items.getDate();
Intent i = new Intent(getApplicationContext() ,Note_content.class);
i.putExtra("Note ", Note_content);
i.putExtra("title", title);
i.putExtra("Date", Date);
startActivity(i);
}
});
i have a problem when I try to to get data( only Note) from this activity to another activity, other values(Date and Title) are working, I tried to use toString method in Notes class but it gives null for note
public class Note_content extends AppCompatActivity {
Notes item;
TextView txt_note ,txt_date , txt_title;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_note_content);
txt_title = findViewById(R.id.txt_ntitle);
txt_note = findViewById(R.id.txt_Nnote);
txt_date = findViewById(R.id.txt_Ndate);
Intent i = getIntent();
String note = i.getStringExtra("Note");
String title = i.getStringExtra("title");
String date = i.getStringExtra("Date");
item = new Notes(title,note,date);
txt_note.setText(item.getNote());
//txt_note.setText(note)
txt_date.setText(date);
txt_title.setText(title);
}
this is the second activit, it is not giving any errors but null instead of the note
and this Notes class
public class Notes {
private int id;
private String title;
private String note ;
private String date;
public Notes() {
}
public Notes(String title, String note, String date) {
this.title = title;
this.note = note;
this.date = date;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
#Override
public String toString() {
return this.note+"\n"+title+"\n"+date;
}
}
i.putExtra("Note ", Note_content);
In the above code line, "Note " has an extra space at the end.

Resource Not Found while converting int value of id to String using Retrofit

I am using Retrofit to fetch and display data to the screen. I want to search users by their id's. I made interface like this :
#GET("/posts/{id}")
Call<postmodel> getUsersModel(#Path("id") int id);
The problem is with DetailActivity line 52:
EndPointAccess access = APIClient.getRetrofit().create(EndPointAccess.class);
Call<postmodel> modelCall = access.getUsersModel(Integer.parseInt(_userinput));
Here is the Logcat report:
android.content.res.Resources$NotFoundException:
String resource ID #0x1
at
android.content.res.Resources.getText(Resources.java:351)
at
android.content.res.MiuiResources.getText(MiuiResources.java:97)
at
android.widget.TextView.setText(TextView.java:4562)
at com.example.sahil.typicode1.Activity.DetailActivity$2.onResponse(DetailActivity.java:60)
APIClient.java
public static final String BASE_URL = "https://jsonplaceholder.typicode.com";
private static Retrofit retrofit = null;
public static Retrofit getRetrofit()
{
if (retrofit == null)
{
retrofit = new Retrofit.Builder().baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory
.create()).build();
}
return retrofit;
}
EndPointAccess.java (Interface)
#GET("/posts/{id}")
Call<postmodel> getUsersModel(#Path("id") int id);
MainActivity.java
EditText userid;
Button search;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
userid = (EditText) findViewById(R.id.etuserid);
search = (Button) findViewById(R.id.btnsearch);
search.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this,DetailActivity.class);
intent.putExtra("STRING_I_NEED",userid.getText().toString());
startActivity(intent);
}
});
}
DetailActivity.java
TextView userid,usertitle,userbody;
Button viewall;
String _userinput;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
Intent intent = getIntent();
_userinput = intent.getStringExtra("STRING_I_NEED");
userid = (TextView) findViewById(R.id.textViewid);
usertitle = (TextView) findViewById(R.id.textViewtitle);
userbody = (TextView) findViewById(R.id.textViewbody);
viewall = (Button) findViewById(R.id.btnviewall);
viewall.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(DetailActivity.this, "Done!", Toast.LENGTH_SHORT).show();
}
});
getinfo();
}
private void getinfo()
{
EndPointAccess access = APIClient.getRetrofit().create(EndPointAccess.class);
Call<postmodel> modelCall = access.getUsersModel(Integer.parseInt(_userinput));
modelCall.enqueue(new Callback<postmodel>() {
#Override
public void onResponse(Call<postmodel> call, Response<postmodel> response)
{
userid.setText(response.body().getId());
usertitle.setText(response.body().getTitle());
userbody.setText(response.body().getBody());
}
#Override
public void onFailure(Call<postmodel> call, Throwable t) {
Toast.makeText(DetailActivity.this, "Error!", Toast.LENGTH_SHORT).show();
}
});
}
postmodel.java (pojo class)
private int id;
private String title;
private String body;
public postmodel(int id, String title, String body) {
this.id = id;
this.title = title;
this.body = body;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
You are trying to set an integer in the setText function which only accepts String values. Therefore it is giving this error.
Hence you need to convert it into a string using String.valueOf() function.
remove userid.setText(response.body().getId());
add userid.setText(String.valueOf(response.body().getId()));
SetText with integer parameter looks resource with that id : reference
So you should pass an string value to setText()
userid.setText(String.valueOf(response.body().getId()));
So, replacing this line in DetailActivity.java might help you fix the exception :)

java.lang.NullPointerException: Attempt to invoke interface method 'java.util.Iterator java.util.List.iterator()' on a null object reference Retrofit

I'm trying to use blog id to get JSON object from server. At the moment I'm getting this error
java.lang.NullPointerException: Attempt to invoke interface method 'java.util.Iterator java.util.List.iterator()
on a null object reference`.How do I use the post Id to get the full content what am I doing wrong. Please help!!!
MyBlog Adapter:
public class MyBlogAdapter extends RecyclerView.Adapter<BlogViewHolder> {
List<BlogResponse> postsList;
Context context;
public static String blog_Id, blogID;
private LayoutInflater inflater;
public MyBlogAdapter(Context context, List<BlogResponse> postsList){
this.context = context;
this.inflater = LayoutInflater.from(context);
this.postsList = postsList;
}
#Override
public BlogViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = inflater.inflate(R.layout.custom_view,parent, false);
return new BlogViewHolder(view);
}
#Override
public void onBindViewHolder(BlogViewHolder holder, int position) {
final BlogResponse posts= postsList.get(position);
holder.summary.setText(posts.getBlogExcerpt().trim().toString());
holder.title.setText(posts.getBlogTitle().trim().toString());
// Glide.with(context).load(posts.getBlogThumbnail()).into(holder.cover);
holder.blogHolder.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(context, AnotherSingleView.class);
blog_Id = posts.getBlogId();
intent.putExtra(blogID,blog_Id);
Log.d("MyblogAdapter","Please check blog Id: "+blog_Id);
context.startActivity(intent);
}
});
}
#Override
public int getItemCount() {
Log.d("MyBlogAdapter,","getItemCount"+postsList.size());
return postsList == null ? (0) : postsList.size();
}
}
SecondActivity:
public class AnotherSingleView extends AppCompatActivity {
String postID;
int position;
public TextView blogTitle,blogSub,blogContent;
public ImageView blogPic;
List<SingleBlogPost> singleBlogPosts;
SingleBlogPost singleBlogPost;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_another_single_view);
Intent intent = getIntent();
Bundle showBlogId = intent.getExtras();
postID = showBlogId.getString(blogID);
Log.d("AnotherSingleView","Please check blog Id: "+postID);
singleBlogPosts = new ArrayList<>();
blogContent = (TextView)findViewById(R.id.blog_content);
blogSub = (TextView) findViewById(R.id.blog_subtitle);
blogTitle =(TextView) findViewById(R.id.blog_title);
blogPic =(ImageView) findViewById(R.id.blog_pix);
singlePostDisplay();
}
private void singlePostDisplay() {
BlogaPI api = ApiClient.getBlogInterface();
Call<List<SingleBlogPost>> call = api.postResponse(postID);
call.enqueue(new Callback<List<SingleBlogPost>>() {
#Override
public void onResponse(Call<List<SingleBlogPost>> call, Response<List<SingleBlogPost>> response) {
singleBlogPosts = response.body();
if (singleBlogPosts != null && !singleBlogPosts.isEmpty() ){
for (SingleBlogPost posts : singleBlogPosts){
Log.d("AnotherSingleView","Please check RESPONSE: "+response.body().toString());
blogTitle.setText(posts.getBlogTitle());
blogSub.setText(posts.getBlogSubtitle());
blogContent.setText(posts.getBlogContent());
// Glide.with(AnotherSingleView.this).load(singlepost.getBlogMedimg()).into(blogPic);
}
}
else{
Toast.makeText(AnotherSingleView.this, "Something is empty", Toast.LENGTH_SHORT).show();
} }
#Override
public void onFailure(Call<List<SingleBlogPost>> call, Throwable t) {
Toast.makeText(AnotherSingleView.this, "check again: "+t.toString(), Toast.LENGTH_SHORT).show();
}
});
}
}
Interface:
public interface BlogaPI {
#GET("blog")
Call<BlogList> response();
#GET("post/{blog_id}")
Call<List<SingleBlogPost>> postResponse(#Path("blog_id") String blog_id);
//Call<List<SingleBlogPost>> postResponse();
}
SingleBlogPost:
public class SingleBlogPost {
#SerializedName("blog_id")
#Expose
private String blogId;
#SerializedName("blog_title")
#Expose
private String blogTitle;
#SerializedName("blog_subtitle")
#Expose
private String blogSubtitle;
#SerializedName("blog_excerpt")
#Expose
private String blogExcerpt;
#SerializedName("blog_content")
#Expose
private String blogContent;
#SerializedName("blog_thumbnail")
#Expose
private String blogThumbnail;
#SerializedName("blog_medimg")
#Expose
private String blogMedimg;
#SerializedName("category_title")
#Expose
private String categoryTitle;
public SingleBlogPost(String blogId,String blogTitle, String blogSubtitle, String blogExcerpt,
String blogContent, String blogThumbnail, String blogMedimg, String categoryTitle){
this.blogId = blogId;
this.blogTitle = blogTitle;
this.blogSubtitle = blogSubtitle;
this.blogExcerpt = blogExcerpt;
this.blogContent = blogContent;
this.blogThumbnail = blogThumbnail;
this.blogMedimg = blogMedimg;
this.categoryTitle = categoryTitle;
}
public String getBlogId() {
return blogId;
}
public void setBlogId(String blogId) {
this.blogId = blogId;
}
public String getBlogTitle() {
return blogTitle;
}
public void setBlogTitle(String blogTitle) {
this.blogTitle = blogTitle;
}
public String getBlogSubtitle() {
return blogSubtitle;
}
public void setBlogSubtitle(String blogSubtitle) {
this.blogSubtitle = blogSubtitle;
}
public String getBlogExcerpt() {
return blogExcerpt;
}
public void setBlogExcerpt(String blogExcerpt) {
this.blogExcerpt = blogExcerpt;
}
public String getBlogContent() {
return blogContent;
}
public void setBlogContent(String blogContent) {
this.blogContent = blogContent;
}
public String getBlogThumbnail() {
return blogThumbnail;
}
public void setBlogThumbnail(String blogThumbnail) {
this.blogThumbnail = blogThumbnail;
}
public String getBlogMedimg() {
return blogMedimg;
}
public void setBlogMedimg(String blogMedimg) {
this.blogMedimg = blogMedimg;
}
public String getCategoryTitle() {
return categoryTitle;
}
public void setCategoryTitle(String categoryTitle) {
this.categoryTitle = categoryTitle;
}
}
Check if the server response is different then null before you do a enhanced for like this:
if(singleBlogPosts!= null) {
for (SingleBlogPosts posts : singleBlogPosts){
Log.d("AnotherSingleView","Please check RESPONSE: "+response.body().toString());
blogTitle.setText(posts.getBlogTitle());
blogSub.setText(posts.getBlogSubtitle());
blogContent.setText(posts.getBlogContent());
// Glide.with(AnotherSingleView.this).load(singlepost.getBlogMedimg()).into(blogPic);
}
}
you question was list iterator,but we can`t see you list use on anywhere,i guess you may be use recyclerView on you data has not get,because get data was asynchronous.try to use data if you can sure it is existing.

Android intent bundle pass string

i have json to serializable claas then i use it to populate listview, and everything works fine but i want to populate textview on another xml page with one of the serializable object and i read to best way to do it is bundle intent, but i did code something wrong.
public class FeedItem implements Serializable {
private String title;
private String date;
private String attachmentUrl;
private String id;
private String content;
private String url;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getAttachmentUrl() {
return attachmentUrl;
}
public void setAttachmentUrl(String attachmentUrl) {
this.attachmentUrl = attachmentUrl;
}
#Override
public String toString() {
return "[ title=" + title + ", date=" + date + "]";
}
ArrayList<FeedItem> all_thumbs = new ArrayList<FeedItem>();
all_thumbs.add(new FeedItem(title);
Intent intent = new Intent(title);
Bundle extras = new Bundle();
extras.putSerializable("title",title);
intent.putExtras(extras);
}
and in the class where i want to use it
public void updateList() {
TextView infoz = (TextView) getView().findViewById(R.id.infoz);
Bundle args;
getArguments().getSerializable(title);
Instead use:
public void updateList() {
TextView infoz = (TextView) getView().findViewById(R.id.infoz);
Intent intent = getIntent();
Bundle extras = intent.getExtras();
String title = (String) extras.getSerializable("title");
IF you want to pass any primitive datatyped values (String,int,long,float etc.) then do not need to use Bundle.putExtra(KEY,Serialized Object) and Bundle.getSerializable(KEY). You can use Bundle.putExtra(KEY,primitive data);
If you want to pass class object to intent/bundle then you need to implement Serializable/Parsable in that class like:
public class Test implements Serializable
{
private static final long serialVersionUID = 1L;
int test1;
}
and then you can pass that object instance to intent like:
myIntent.putExtra( KEY, new Test() );
For more clarification check pass seriable object in intent example

Categories