رفتن به مطلب
انجمن اندروید ایران | آموزش برنامه نویسی اندروید و موبایل
  • android.png.1fab383bc8500cd93127cebc65b1dcab.png

نامرتب بودن فهرست مطالب


پست های پیشنهاد شده

سلام دوستان  کسی میدونه مشکل من کجاست فهرست مطالبم پشت سرهم نمیاد  ودوتیکه میشه مثل زیر:

فصل اول

فصل دوم

فصل چهارم

فصل سوم

 فصل اول

فصل پنجم

فصل دوم

چیکار کنم مرتب بشن وپشت سرهم باشن وهرکدام دوتا نباشه.من مطالبم رو داخل دیتابیس ذخیره کردم وفراخوانی کردم ممنون میشم کمک کنید

لینک ارسال
به اشتراک گذاری در سایت های دیگر

این کد دیتابیسم:

[shcode=java]  package com.example.dynacord;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.io.OutputStream;

import android.R.string;

import android.content.ContentValues;

import android.content.Context;

import android.database.Cursor;

import android.database.SQLException;

import android.database.sqlite.SQLiteDatabase;

import android.database.sqlite.SQLiteOpenHelper;

public class database extends SQLiteOpenHelper {

   

    public final String path="data/data/com.example.dynacord/databases/";

    public final String Name="database";

    public SQLiteDatabase mydb;

   

    private final Context mycontext;

   

   

    public database(Context context) {

        super(context, "database", null, 1);

        mycontext=context;

       

    }

   

    @Override

    public void onCreate(SQLiteDatabase arg0) {

        // TODO Auto-generated method stub

       

    }

    @Override

    public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {

        // TODO Auto-generated method stub

       

    }

   

   

    public void useable(){

       

        boolean checkdb=checkdb();

       

        if(checkdb){

        }else{

           

            this.getReadableDatabase();

           

            try{

            copydatabase();

            }catch(IOException e){

            }

           

        }

       

       

       

    }

   

    public void open(){

       

        mydb=SQLiteDatabase.openDatabase(path+Name, null, SQLiteDatabase.OPEN_READWRITE);

       

    }

   

    public void close(){

        mydb.close();

    }

   

    public boolean checkdb(){

       

        SQLiteDatabase db=null;

        try{   

        db=SQLiteDatabase.openDatabase(path+Name, null, SQLiteDatabase.OPEN_READONLY);

        }

        catch(SQLException e)

        {

        }

        //mydb.close();

        return db !=null ? true:false ;

       

    }

   

    public void copydatabase() throws IOException{

        OutputStream myOutput = new FileOutputStream(path+Name);

        byte[] buffer = new byte[1024];

        int length;

        InputStream myInput = mycontext.getAssets().open(Name);

        while ((length = myInput.read(buffer)) > 0) {

        myOutput.write(buffer, 0, length);

        }

        myInput.close();

        myOutput.flush();

        myOutput.close();

    }

   

   

    public byte[] getpic(String table,String sea,String name,String page){

       

         Cursor cu=mydb.rawQuery("select * from "+table+" where Seasone='"+sea+"' and Name='"+name+"' and Page="+page, null);

         cu.moveToFirst();

         byte[] s;

         s=cu.getBlob(6);

         return s;

          

         }

   

   

    public String Display(int row,int field,String table){

       

        Cursor cu=mydb.rawQuery("select * from "+table, null);

        cu.moveToPosition(row);

        String s=cu.getString(field);

        return s;

    }

   

    public Integer count(String table,String field){

       

        Cursor cu=mydb.rawQuery("select * from "+table+" group by "+field, null);

        int s=cu.getCount();

        return s;

    }

   

    public String Season_display(String table,int row){

       

        Cursor cu=mydb.rawQuery("select * from "+table+" group by Seasone", null);

        cu.moveToPosition(row);

        String s=cu.getString(4);

        return s;

    }

   

    public Integer Story_count(String table,String sea){

       

        Cursor cu=mydb.rawQuery("select * from "+table+" where Seasone='"+sea+"' group by Name", null);

        int s=cu.getCount();

        return s;

    }

   

    public String Story_display(String table,int row,String sea){

       

        Cursor cu=mydb.rawQuery("select * from "+table+" where Seasone='"+sea+"' group by Name", null);

        cu.moveToPosition(row);

        String s=cu.getString(1);

        return s;

    }

   

   

    public Integer Story_page_count(String table,String sea,String story){

       

        Cursor cu=mydb.rawQuery("select * from "+table+" where Seasone='"+sea+"' and Name='"+story+"'", null);

        int s=cu.getCount();

        return s;

    }

   

    public String main_display(String table,String sea,String name,String page){

       

        Cursor cu=mydb.rawQuery("select * from "+table+" where Seasone='"+sea+"' and Name='"+name+"' and Page="+page, null);

        cu.moveToFirst();

        String s=cu.getString(2);

        return s;

    }

   

   

    public void fav_update(String table,String sea, String name,String v){

        ContentValues cv=new ContentValues();

        cv.put("Fav", v);

        mydb.update(table, cv, "Seasone='"+sea+"' and Name='"+name+"'", null);

       

    }

   

    public Integer fav_count(String table){

       

        Cursor cu=mydb.rawQuery("select * from "+table+" where Fav=1 group by Name", null);

        int s=cu.getCount();

        return s;

    }

   

   

    public String fav_display(String table,int row,int field){

       

        Cursor cu=mydb.rawQuery("select * from "+table+" where Fav=1 group by Name", null);

        cu.moveToPosition(row);

        String s=cu.getString(field);

        return s;

    }

   

   

    public Integer count_serach(String word,String field){

       

        Cursor cu;

        if(field.equals("Name")){

            cu=mydb.rawQuery("select * from content where "+field+" Like '%"+word+"%' group by Name", null);

        }else{

            cu=mydb.rawQuery("select * from content where "+field+" Like '%"+word+"%'", null);

        }

       

        int s=cu.getCount();

        return s;

    }

   

   

    public String serach(int row,int col,String word,String field){

       

        Cursor cu;

        if(field.equals("Name")){

            cu=mydb.rawQuery("select * from content where "+field+" Like '%"+word+"%' group by Name", null);

        }else{

            cu=mydb.rawQuery("select * from content where "+field+" Like '%"+word+"%'", null);

        }

       

       

        cu.moveToPosition(row);

        String s=cu.getString(col);

        return s;

    }

   

   

public Integer count_search(String word,string field){

       

    Cursor cu;

    if(field.equals("Name")){

     cu=mydb.rawQuery("select * from content where "+field+" Like '%"+word+"%' group by Name", null);

    }else{

        cu=mydb.rawQuery("select * from content where "+field+" Like '%"+word+"%'", null);

    }

     

        int s=cu.getCount();

        return s;

    }

   

   

    public String search(int row,int col,String word,string field){

        Cursor cu;

        if(field.equals("Name")){

         cu=mydb.rawQuery("select * from content where "+field+" Like '%"+word+"%' group by Name", null);

        }else{

            cu=mydb.rawQuery("select * from content where "+field+" Like '%"+word+"%'", null);

        }

         

         

        cu.moveToPosition(row);

        String s=cu.getString(col);

        return s;

    }

   

public Integer all_story_count(String table){

       

        Cursor cu=mydb.rawQuery("select * from "+table+" group by Name", null);

        int s=cu.getCount();

        return s;

    }

   

    public String all_story_display(String table,int row,int field){

       

        Cursor cu=mydb.rawQuery("select * from "+table+" group by Name order by ID", null);

        cu.moveToPosition(row);

        String s=cu.getString(field);

        return s;

    }

   

}

[/shcode]

اینم کد لیست فراخوانی:

[shcode=java] package com.example.dynacord;

import com.example.dynacord.list_season;

import com.example.dynacord.list_story;

import android.app.ListActivity;

import android.content.Intent;

import android.os.Bundle;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;

import android.widget.ArrayAdapter;

import android.widget.ListView;

import android.widget.TextView;

public class list_season extends ListActivity {

   

   

   

    private database db;

    private String[] Name;

    private String[] ID;

   

   

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.list_season);

   

        db=new database(this);

       

        refresh();

        setListAdapter(new AA());

    }

    @Override

    public void onBackPressed() {

        super.onBackPressed();

       

        finish();

        overridePendingTransition(R.anim.instart, R.anim.outback);

       

       

    }

    @Override

    protected void onListItemClick(ListView l, View v, int position, long id) {

       

       

        Intent i=new Intent(list_season.this,list_story.class);

        i.putExtra("sea", Name[position]);

        startActivity(i);

       

       

       

       

       

    }

   

   

    class AA extends ArrayAdapter{

       

       

        public AA(){

            super(list_season.this,R.layout.row_season,Name);

        }

       

       

       

        @Override

        public View getView(int position, View convertView, ViewGroup parent) {

           

           

            LayoutInflater in=getLayoutInflater();

            View row=in.inflate(R.layout.row_season, parent,false);

           

            TextView name=(TextView) row.findViewById(R.id.row_season_name);

           

           

            name.setText("فصل : "+Name[position]);

           

            name.setTypeface(Main.font);

            return (row);

        }

       

       

    }

   

    private void refresh(){

       

        db.open();

       

        int s=db.count("content", "Seasone");

        Name=new String;

   

       

        for(int i=0;i

            Name=db.Season_display("content", i);

           

        }

        db.close();

       

       

       

       

    }

   

}

[/shcode]


اینم عکس دیتابیس

http://p30droid.com/attachment.php?aid=344

لینک ارسال
به اشتراک گذاری در سایت های دیگر

به گفتگو بپیوندید

هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .

مهمان
ارسال پاسخ به این موضوع...

×   شما در حال چسباندن محتوایی با قالب بندی هستید.   حذف قالب بندی

  تنها استفاده از 75 اموجی مجاز می باشد.

×   لینک شما به صورت اتوماتیک جای گذاری شد.   نمایش به صورت لینک

×   محتوای قبلی شما بازگردانی شد.   پاک کردن محتوای ویرایشگر

×   شما مستقیما نمی توانید تصویر خود را قرار دهید. یا آن را اینجا بارگذاری کنید یا از یک URL قرار دهید.

×
×
  • اضافه کردن...