I am working in an android application where I want to display all rows of table in a textview with a "Read more" link at the end of each row.
I need the output as :
Part_Of_row1 ...Read more
Part_Of_row2 ...Read more
When Read more link is clicked,the respective complete row should be displayed. It works fine when only one row is displayed. When I use loop to display all rows , "Read more" link is not working.
This is the piece of code in my textview,
TextView txt = (TextView) findViewById(R.id.tv);
db = openOrCreateDatabase("DB", MODE_PRIVATE, null);
Cursor cur = db.rawQuery("select * from TABLE", null);
cur.moveToFirst()
String show = "";
do {
String pt = "//data retrieved from table(row-wise)";
SpannableStringBuilder sb = new SpannableStringBuilder();
String sub1 = pt.substring(0, 40);
String sub2 = "...";
String sub3 = "Read more";
sb.append(sub1);
sb.append(sub2);
sb.append(sub3);
final String finalPt = pt;
sb.setSpan(new ClickableSpan() {
@Override
public void onClick (View view){
txt.setText(finalPt);
}
},sb.length()-sub3.length(),sb.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
show = show + sb+"\n\n";
} while (cur.moveToNext());
txt.setText(show);
txt.setMovementMethod(LinkMovementMethod.getInstance());
Thanks in advance.
0 comments:
Post a Comment