I am passing some data from one activity to another. All the data are passing alright but there one with data type Spanned which isnt working at all. When I display it in the first Activity,it works but when I display it in the other activity,it doest even appear.
I took the data from json like this
public void parseJsonData(final String jsonString) {
try {
jArray = new JSONArray(jsonString);
for(int i=0; i < jArray.length(); i++) {
JSONObject jObject = jArray.getJSONObject(i);
news news1 = new news();
news1.setCategory("Spor");
news1.setTitle(jObject.getString("title"));
news1.setDate(jObject.getString("date"));
news1.setContent(Html.fromHtml(jObject.getString("content")));//Here the data type of Content is Spanned
news1.setShort_content(jObject.getString("short_content"));
Sdatalist.add(news1);
}
if (dialog.isShowing()){
dialog.dismiss();
}
} catch (JSONException e) {
e.printStackTrace();
dialog.dismiss();
}
}
From my Adapter I sent the data like this
myholder.myimageview1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent myIntent = new Intent(mycontext, Detailews.class);
myIntent.putExtra("category", mydatalist.get(position).getCategory());
myIntent.putExtra("title", mydatalist.get(position).getTitle());
myIntent.putExtra("date", mydatalist.get(position).getDate());
myIntent.putExtra("cont", mydatalist.get(position).getContent());
myIntent.putExtra("image", mydatalist.get(position).getImage());
mycontext.startActivity(myIntent);
}
});
And in the other activity I recieved the data like this
cat = (TextView)findViewById(R.id.Dtextcategory);
dat = (TextView)findViewById(R.id.Ddatetext);
tit = (TextView)findViewById(R.id.Dtitletext);
con = (TextView)findViewById(R.id.textView4);
Intent in = getIntent();
final String image_url = in.getStringExtra("image");
final String title = in.getStringExtra("title");
final String date = in.getStringExtra("date");
final String co = in.getStringExtra("cont");//If I try making the datatype here spanned,it wont understand :)
final String category = in.getStringExtra("category");
cat.setText(category);
dat.setText(date);
tit.setText(title);
con.setText(co); //Here is where it does not show.
imageView = (ImageView)findViewById(R.id.Dimage);
new CustomAdapter.DownloadImageTask(imageView).execute(image_url);
I need some one to find the bug. :) help me out
getContent()
would need to return a CharSequence
. Then, use getCharSequenceExtra()
, not getStringExtra()
, saving it to a CharSequence
variable.
IOW, strings do not have spans. CharSequence
objects have spans. When you convert a CharSequence
to a string via toString()
, you lose the spans.