mercredi 23 septembre 2015

how to change data field scripture in my db into telugu?

//MainActivity.java
public class MainActivity extends AppCompatActivity {

    SqlLiteDbHelper dbHelper;
    Bible contacts;
    private SimpleCursorAdapter dataAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        dbHelper = new SqlLiteDbHelper(this);
        try {
            dbHelper.openDataBase();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        contacts = new Bible();
        displayListView();
    }

    private void displayListView() {


        Cursor cursor = dbHelper.Get_BibleDetails();

        String[] columns = new String[]{
                SqlLiteDbHelper.KEY_BOOK,
                SqlLiteDbHelper.KEY_CHAPTER,
                SqlLiteDbHelper.KEY_VERSES,
                SqlLiteDbHelper.KEY_SCRIPTURE
        };

        int[] to = new int[]{
                R.id.bookno,
                R.id.chapterno,
                R.id.verseno,
                R.id.scriptureview,
        };

        dataAdapter = new SimpleCursorAdapter(
                this, R.layout.simple_cursor_adapter,
                cursor,
                columns,
                to,
                0);
        ListView listView = (ListView) findViewById(R.id.listview);
        listView.setAdapter(dataAdapter);


    }
}
//SQLiteDbHelper
public class SqlLiteDbHelper extends SQLiteOpenHelper {

    private static final int DATABASE_VERSION = 1;
    private static final String DATABASE_NAME = "Telugu.sqlite";
    private static final String DB_PATH_SUFFIX = "/databases/";

    public static final String KEY_ROWID = "_id";
    public static final String KEY_BOOK = "Book";
    public static final String KEY_CHAPTER = "Chapter";
    public static final String KEY_VERSES = "Verse";
    public static final String KEY_SCRIPTURE = "Scripture";
    static Context ctx;

    public SqlLiteDbHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        ctx = context;
    }


    public Cursor Get_BibleDetails() {
        SQLiteDatabase db = this.getReadableDatabase();
        Cursor cursor = db.rawQuery("select rowid _id,* from Bible", null);
        if (cursor != null) {
            cursor.moveToFirst();
        }
        return cursor;
    }

    public void CopyDataBaseFromAsset() throws IOException {

        InputStream myInput = ctx.getAssets().open(DATABASE_NAME);

        String outFileName = getDatabasePath();

        File f = new File(ctx.getApplicationInfo().dataDir + DB_PATH_SUFFIX);
        if (!f.exists())
            f.mkdir();

        OutputStream myOutput = new FileOutputStream(outFileName);

        byte[] buffer = new byte[1024];
        int length;
        while ((length = myInput.read(buffer)) > 0) {
            myOutput.write(buffer, 0, length);
        }

        myOutput.flush();
        myOutput.close();
        myInput.close();

    }

    private static String getDatabasePath() {
        return ctx.getApplicationInfo().dataDir + DB_PATH_SUFFIX
                + DATABASE_NAME;
    }

    public SQLiteDatabase openDataBase() throws SQLException {
        File dbFile = ctx.getDatabasePath(DATABASE_NAME);

        if (!dbFile.exists()) {
            try {
                CopyDataBaseFromAsset();
                System.out.println("Copying sucess from Assets folder");
            } catch (IOException e) {
                throw new RuntimeException("Error creating source database", e);
            }
        }

        return SQLiteDatabase.openDatabase(dbFile.getPath(), null, SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.CREATE_IF_NECESSARY);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
//DTO
public class Bible {
   // int rowid;
    int Book;
    int Chapter;
    int Verse;
    String Scripture="";


    public Bible(int rowid, int book, int chapter, int verse, String scripture) {
        //this.rowid=rowid;
        this.Book = book;
        this.Chapter = chapter;
        this.Verse = verse;
        this.Scripture = scripture;

    }

    public Bible() {
    }



    public int getBook() {
        return Book;
    }

    public void setBook(int book) {
        Book = book;
    }

    public int getChapter() {
        return Chapter;
    }

    public void setChapter(int chapter) {
        Chapter = chapter;
    }

    public int getVerse() {
        return Verse;
    }

    public void setVerse(int verse) {
        Verse = verse;
    }

    public String getScripture() {
        return Scripture;
    }

    public void setScripture(String scripture) {
        Scripture = scripture;
    }

    @Override
    public String toString() {
        return "Bible{" +
                ", Book=" + Book +
                ", Chapter=" + Chapter +
                ", Verse=" + Verse +
                ", Scripture='" + Scripture + '\'' +
                '}';
    }

}

    enter code here
    //activity_main.xml
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
                xmlns:tools="http://ift.tt/LrGmb4"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                tools:context=".MainActivity">

    <ListView
        android:id="@+id/listview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</LinearLayout>


enter code here
//simple_cursor_adapter.xml

    <TextView
        android:textSize="50sp"
        android:textStyle="bold"
        android:textColor="#FF0000"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/bookno"/>
    <TextView
        android:textSize="40sp"
        android:textStyle="bold"
        android:textColor="#21610B"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/chapterno"/>
    <TextView
        android:textSize="30sp"
        android:textStyle="bold"
        android:textColor="#2E64FE"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/verseno"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/scriptureview"/>
[![This is my database file][1]][1]


  [1]: http://ift.tt/1j9siG8

I retreived data from database file I have a field called scripture which is display in \u3117?\u3138? this format how to display it into its respective language telugu. can any one help me out to solve this problem.

Aucun commentaire:

Enregistrer un commentaire