arabian 0 ارسال شده در ۶ بهمن ۱۳۹۳ گزارش اشتراک گذاری ارسال شده در ۶ بهمن ۱۳۹۳ سلام دوستان خسته نباشین: دوستان این کد رو نگاه کنید ببنید مشکلش کجاست من عکسام رو توی دیتابیس ریختم حالا میخوام فراخوانی کنم همه متن هام فقط یه عکس میاد میخواستم هر متن که باز میشه عکس خودش بیاد اینم کد جاوا: [shcode=java] img=(ImageView) findViewById(R.id.main_matn_img); db=new database(this); db.useable(); db.open(); byte[] p=db.getpic(1); if(p!=null){ Bitmap bm=BitmapFactory.decodeByteArray(p, 0, p.length); img.setImageBitmap(bm); }else{ } db.close();[/shcode] اینک کد دیتابیسم: [shcode=java] public byte[] getpic(int id){ Cursor cu=mydb.rawQuery("select * from content where ID="+id, null); cu.moveToFirst(); byte[] s; s=cu.getBlob(6); return s; }[/shcode] ممنون میشم کمک کنید بنظرم مشکلم روی همین کد هستش کسی میدونه به جای آیدی (1) چه کدی بنویسم که عکس های هرمتن بیاد [shcode=java] byte[] p=db.getpic(1);[/shcode] نقل قول لینک ارسال به اشتراک گذاری در سایت های دیگر
arabian 0 ارسال شده در ۷ بهمن ۱۳۹۳ مالک گزارش اشتراک گذاری ارسال شده در ۷ بهمن ۱۳۹۳ کسی نیست کمک کنه ؟ نقل قول لینک ارسال به اشتراک گذاری در سایت های دیگر
mahdieh_R 6 ارسال شده در ۷ بهمن ۱۳۹۳ گزارش اشتراک گذاری ارسال شده در ۷ بهمن ۱۳۹۳ خب شما دارین هر دفعه عکس با id=1 رو بر میگردونید اگر متنتون هم توی دیتابیس قرار داره با کلید خارجی idمتن رو تو جدول تصاویرتون ذخیره کنید و ازش استفاده کنید اگرم همه توی یک جدول هستن که کاری نداره همه رو با هم بخونین از بانک اگر جز اینه بگین چطور ذخیره کردین و دیتابیستون چجوریه نقل قول لینک ارسال به اشتراک گذاری در سایت های دیگر
arabian 0 ارسال شده در ۸ بهمن ۱۳۹۳ مالک گزارش اشتراک گذاری ارسال شده در ۸ بهمن ۱۳۹۳ نقل قول لینک ارسال به اشتراک گذاری در سایت های دیگر
mahdieh_R 6 ارسال شده در ۸ بهمن ۱۳۹۳ گزارش اشتراک گذاری ارسال شده در ۸ بهمن ۱۳۹۳ [align=right]فرض می کنیم شما بر اساس شماره صفحه می خواین فراخونی روانجام بدین :[/align] [align=right]توی پیج مربوط به دیتا بیس ی تابع مثل این تعریف می کنین [/align] [shcode=java] Public Cursor GetData(int pageNumber) { private SQLiteDatabase myDataBase; Cursor cur=myDataBase.query(name table, new String[]{name columns }, "page=?",new String[]{ pageNumber}, null,null,null); return cur; } //حالا توی اکتیویتی ک قراره فراخونی کنی داده هات رو اینجوری بنویس Cursor cur=dbh.GetData("شماره صفحه "); if(cur.getCount((>0) { while(cur.moveToNext()) { //این قسمت فرضا می خوای توی یک تکست ویو متنت رو نشون بدی می نویسی: Txt.settext(cur.getString(cur.getColumnIndex(”اسم ستونت”)); //واسه عکس Byte []b=cur.getBlob(cur.getColumnIndex("اسم ستونت" )); //نمایش عکس if(b!=null) { //img اسم کنترل ByteArrayInputStream bImage=new ByteArrayInputStream(b); Bitmap bimatPic=BitmapFactory.decodeStream(bImage); img.setImageBitmap(bimatPic); } } } curWord.close(); [/shcode] امیدوارم منظورمو درس رسونده باشم نقل قول لینک ارسال به اشتراک گذاری در سایت های دیگر
arabian 0 ارسال شده در ۸ بهمن ۱۳۹۳ مالک گزارش اشتراک گذاری ارسال شده در ۸ بهمن ۱۳۹۳ ممنون که پاسخ دادین ولی متن من فراخوانی میشه فقط عکسهای هر متن نمیاد کد شمارو نوشتم خطا زیاد میده لطفا به عکس بالا وکد من نگاه کنید فکر کنم متوجه میشین نقل قول لینک ارسال به اشتراک گذاری در سایت های دیگر
mahdieh_R 6 ارسال شده در ۸ بهمن ۱۳۹۳ گزارش اشتراک گذاری ارسال شده در ۸ بهمن ۱۳۹۳ ممنون که پاسخ دادین ولی متن من فراخوانی میشه فقط عکسهای هر متن نمیاد کد شمارو نوشتم خطا زیاد میده لطفا به عکس بالا وکد من نگاه کنید فکر کنم متوجه میشین این روشی بود ک خودم ازش استفاده می کنم خب شما همونجایی ک متن رو فراخونی می کنی به همین روش خودت عکس رو هم فراخونی کن اگ میتونی کدت رو پیوست کن شاید بتونم کمکت کنم نقل قول لینک ارسال به اشتراک گذاری در سایت های دیگر
arabian 0 ارسال شده در ۸ بهمن ۱۳۹۳ مالک گزارش اشتراک گذاری ارسال شده در ۸ بهمن ۱۳۹۳ خدا خیرت بده ممنون این کد کامل دیتابیسم: [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(int id){ Cursor cu=mydb.rawQuery("select * from content where ID="+id, 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 android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.TextView; public class main_matn extends Activity{ private ImageView share,img; private TextView titr,matn; private String sea; private String name; private int Page1; private database db; private SharedPreferences sp; @SuppressWarnings("deprecation") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_matn); img=(ImageView) findViewById(R.id.main_matn_img); db=new database(this); db.useable(); db.open(); byte[] p=db.getpic(1); if(p!=null){ Bitmap bm=BitmapFactory.decodeByteArray(p, 0, p.length); img.setImageBitmap(bm); }else{ } db.close(); share=(ImageView) findViewById(R.id.main_matn_share); titr=(TextView) findViewById(R.id.main_matn_titr); matn=(TextView) findViewById(R.id.main_matn_matn); Bundle ex=getIntent().getExtras(); sea=ex.getString("sea"); name=ex.getString("name"); Page1=Integer.parseInt(ex.getString("page")); matn.setTypeface(Main.font); matn.setTextSize(Main.size); matn.setLineSpacing(Main.space, 1); Typeface titrf=Typeface.createFromAsset(getAssets(), "font/titr.ttf"); titr.setTypeface(titrf); RelativeLayout rl=(RelativeLayout) findViewById(R.id.main_matn_layout); if(Main.mode.equals("day")){ Resources res = getResources(); Drawable dr = res.getDrawable(R.drawable.matn_back_light); rl.setBackgroundDrawable(dr); matn.setTextColor(Color.BLACK); titr.setTextColor(Color.BLACK); }else{ Resources res = getResources(); Drawable dr = res.getDrawable(R.drawable.matn_back_dark); rl.setBackgroundDrawable(dr); matn.setTextColor(Color.WHITE); titr.setTextColor(Color.WHITE); } load(sea, name, Page1); share.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent sharing = new Intent(android.content.Intent.ACTION_SEND); sharing.setType("text/plain"); sharing.putExtra(android.content.Intent.EXTRA_SUBJECT, titr.getText().toString()+": myapp"); sharing.putExtra(android.content.Intent.EXTRA_TEXT, matn.getText().toString()); startActivity(Intent.createChooser(sharing, "اشتراک گذاری با")); } }); } private void load(String sea,String Name,int page3){ db.open(); titr.setText(name); matn.setText(db.main_display("content", sea, Name, page3+"")); db.close(); } @Override public void onBackPressed() { sp=getApplicationContext().getSharedPreferences("user", 0); Editor ed=sp.edit(); ed.putString("name", name); ed.putString("sea", sea); ed.putInt("page", Page1); ed.commit(); finish(); } @Override protected void onPause() { sp=getApplicationContext().getSharedPreferences("user", 0); Editor ed=sp.edit(); ed.putString("name", name); ed.putString("sea", sea); ed.putInt("page", Page1); ed.commit(); super.onPause(); } } [/shcode] اینم عکس متن عکس دیتابیسم هم بالا هست نقل قول لینک ارسال به اشتراک گذاری در سایت های دیگر
mahdieh_R 6 ارسال شده در ۹ بهمن ۱۳۹۳ گزارش اشتراک گذاری ارسال شده در ۹ بهمن ۱۳۹۳ [rtl]اگ درست فهمیده باشم شما تو تابع load شما متن رو لود می کنین [/rtl] [rtl]اگ اینجوری عوض کنین فک کنم درس بشه[/rtl] [shcode=java] private void load(String sea,String Name,int page3){ db.open(); titr.setText(name); matn.setText(db.main_display("content", sea, Name, page3+"")); byte[] p=db.getpic(sea, Name, page3+""); if(p!=null){ Bitmap bm=BitmapFactory.decodeByteArray(p, 0, p.length); img.setImageBitmap(bm); } db.close(); } public byte[] getpic(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; } [/shcode] [rtl]قسمت بالا ک عکس رو میگیری هم پاک کن[/rtl] نقل قول لینک ارسال به اشتراک گذاری در سایت های دیگر
arabian 0 ارسال شده در ۱۲ بهمن ۱۳۹۳ مالک گزارش اشتراک گذاری ارسال شده در ۱۲ بهمن ۱۳۹۳ سلام شرمنده دیر جواب دادم نت نداشتم ممنون که جواب دادین به این کلمه خطا میگیره هرکار کردم نشد [shcode=java] [/shcode] " [shcode=java] [/shcode] +table+ [shcode=java] [/shcode] " [shcode=java] [/shcode] باالاخره درست شد مشکل از این کد ها بود این کدها رو اینجوری تغییر دادم درست شد. [shcode=java] byte[] p=(db.getpic("content",sea, Name, page3+""));[/shcode] [shcode=java] public byte[] getpic(String table,String sea,String name,String page){[/shcode] ممنون که کمک کردین mahdieh_R انشاالله همیشه موفق باشین نقل قول لینک ارسال به اشتراک گذاری در سایت های دیگر
jam95 0 ارسال شده در ۱۲ خرداد ۱۳۹۵ گزارش اشتراک گذاری ارسال شده در ۱۲ خرداد ۱۳۹۵ سلام من میخوام از دیتابیس عکس مربوط به هر متن رو لود کنم، از کدهای بالا هم چیزی سر در نیاوردم اصلا نمیدونم ب چ زبانی هست! ممکنه بیشتر توضیح بدین مثلا اینکه آدرس عکس رو باید در دیتا ذخیره کنیم ینی چی؟ من با php و js سایت طراحی میکنم! ممنون نقل قول لینک ارسال به اشتراک گذاری در سایت های دیگر
پست های پیشنهاد شده
به گفتگو بپیوندید
هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .