0

I have defined the function showMeTable() for getting data from sqlite database in DbHelper.java class. Then i call it from WeekDbShow.java class. After getting the table in the form of string , i am setting it to a textView .Here is the part of my DbHelper.java class .

public String showMeTable()
    {
        String mStr="";

        mStr=mStr.concat("<body >");
        mStr=mStr.concat("<tr><td align='center'><b>period</b></td><td align='center'><b>Monday</b></td>" +
                "<td align='center'><b>Tuesday</b></td><td align='center'><b>Wednesday</b></td><td align='center'><b>Thrusday</b></td>" +
                "<td align='center'><b>Friday</b></td></tr>");

        String[] columns=new String[]{KEY_ROWID,KEY_PERIOD,KEY_MON,KEY_TUES,KEY_WED,KEY_THRUS,KEY_FRI};//KEY_MON may be instead of weekDay
        Cursor cursor=OurDb.query(DATABASE_TABLE,columns,null,null,null,null,null);
        cursor.moveToFirst();
        while(!cursor.isAfterLast())
                    {
        mStr=mStr.concat("<tr><td>"+(cursor.getString(cursor.getColumnIndex(KEY_PERIOD)))+"</td>" +
                "<td>"+(cursor.getString(cursor.getColumnIndex(KEY_MON)))+"</td><td>"+
                (cursor.getString(cursor.getColumnIndex(KEY_TUES)))+"</td><td>"+(cursor.getString(cursor.getColumnIndex(KEY_WED)))+"</td>" +
                "<td>"+(cursor.getString(cursor.getColumnIndex(KEY_THRUS)))+"</td><td>"+(cursor.getString(cursor.getColumnIndex(KEY_FRI)))+"</td></tr>");


          cursor.moveToNext();
        }

           mStr.concat("</table></body>");
           return mStr;
    }

And this is the part of my WeekDbShow.java class from where i am calling the showMeTable.

 String data=myDbHelper.showMeTable();

    //showMe.setText("<b>data</b>");
    showMe.setText(Html.fromHtml(data));
    myDbHelper.close();

here is my xml file.

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent" 
android:layout_height="fill_parent"
android:orientation="vertical" 
xmlns:android="http://schemas.android.com/apk/res/android">    
<TextView
    android:id="@+id/tvTT"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Medium Text"
    android:maxLines = "200"
    android:scrollbars = "vertical"
    />

please give me some good solution ,i have all ready tried scrollView in xml.

kumar kundan
  • 2,027
  • 1
  • 27
  • 41
  • Please provide layout file. refer http://stackoverflow.com/questions/1748977/making-textview-scrollable-in-android or http://stackoverflow.com/questions/10904234/android-how-to-make-a-textview-scroll – Tulsiram Rathod Feb 07 '15 at 05:06
  • Here are my notes about this: android:maxLines = "AN_INTEGER" android:scrollbars = "vertical" TextView tv = ((TextView) findViewById(R.id. info)); tv.setMovementMethod( new ScrollingMovementMethod()); – X-Ray Feb 07 '15 at 05:07
  • now i have added my xml file – kumar kundan Feb 07 '15 at 05:39
  • possible duplicate of http://stackoverflow.com/questions/1748977/making-textview-scrollable-in-android – Apurva Feb 07 '15 at 08:27

4 Answers4

3

In properties of your TextView in your layout's xml file set:

android:scrollbars = "vertical"
2

Try adding scrollable = true and scrollbar = vertical in your text view properties in the layout xml..

Saurabh Rajpal
  • 1,537
  • 9
  • 14
2

If you r using AS then above fix may not work ....try this...... In properties of your TextView in your layout's xml file set:

android:scrollbars = "vertical"
0

You can also do this in programatically(.class) by adding this lines

yourtextView.setVerticalScrollBarEnabled(true);
yourtextView.setMovementMethod(new ScrollingMovementMethod());

Refer this link for more details.

Community
  • 1
  • 1
SaravanaRaja
  • 3,228
  • 2
  • 21
  • 29