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

روش گرفتن اطلاعات از دیتابیس و گذاشتن اون توی ویجت


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

سلام به همگی :)

آقایون من چندتا (5-6 تا) تکس ویو توی اکتیویتی index ام دارم که 2 تا از اونارو گذاشتم توی ویجتم ! ولی متاسفانه اصلاً اطلاعات رو از روی دیتابیس (که روی اینترنت هست) نمیگیره که در اکتیویتی index ام میگیره !

کلا جاوای اون دوتا تکس ویو رو نمیشه از جاوای index بگیره ؟

اگه نمیشه چطوری با RemoteViews یا هر چیزه دیگه این جاوا رو در جاوای ویجتم قرار بدم ؟

توجه داشته باشید که اون چند تا تکس ویو ی دیگه هم اطلاعات میگیره ولی نمیخوام اونارو توی ویجتم قرار بدم.

اگر ممکنه پاسخ بدید کارم گیره ممنون.

کدم اینه :

package com.salam.salam;import java.util.Timer;import java.util.TimerTask;import android.app.Activity;import android.app.ProgressDialog;import android.content.DialogInterface;import android.content.Intent;import android.content.SharedPreferences;import android.content.SharedPreferences.Editor;import android.graphics.Typeface;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.ImageView;import android.widget.TextView;import android.widget.Toast;public class index extends Activity {   private SharedPreferences sp;   private ImageView update,share,New,edit,setting,exit;   private TextView welcome,name,txt1,tedad,txt2,payam;   private database db;   private Typeface times;   private Typeface homa;   private Typeface nazanin;   public static String res="";   private int count=0;   public static int count2=0;   public static String countS="";   public static String news="";   private int countL=0;   @Override   protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.index);       db=new database(this);       tarif();       times=Typeface.createFromAsset(getAssets(), "Font/times.ttf");       homa=Typeface.createFromAsset(getAssets(), "Font/homa.ttf");       nazanin=Typeface.createFromAsset(getAssets(), "Font/nazanin.ttf");       welcome.setTypeface(homa);       txt1.setTypeface(homa);       name.setTypeface(times);       txt2.setTypeface(homa);       payam.setTypeface(nazanin);       getcount();       sp=getApplicationContext().getSharedPreferences("userP", 0);       final String s= sp.getString("username", "");       name.setText(s);       tedad.setText("0");       payam.setText("-");       update.setOnClickListener(new OnClickListener() {           @Override           public void onClick(View arg0) {           if(tedad.getText().toString().equals("0")){               Toast.makeText(getApplicationContext(), "no new update!!!", Toast.LENGTH_LONG).show();           }else{               update(tedad.getText().toString());           }           }       });       share.setOnClickListener(new OnClickListener() {           @Override           public void onClick(View arg0) {               Intent ed=new Intent(index.this,sharedlist.class);               startActivity(ed);           }       });       New.setOnClickListener(new OnClickListener() {           @Override           public void onClick(View arg0) {               Intent ed=new Intent(index.this,newshare.class);               ed.putExtra("username", s);               startActivity(ed);           }       });       edit.setOnClickListener(new OnClickListener() {           @Override           public void onClick(View arg0) {               Intent ed=new Intent(index.this,editprofile.class);               ed.putExtra("username", s);               startActivity(ed);           }       });       setting.setOnClickListener(new OnClickListener() {           @Override           public void onClick(View arg0) {               Intent ed=new Intent(index.this,setting.class);               startActivity(ed);           }       });       exit.setOnClickListener(new OnClickListener() {           @Override           public void onClick(View arg0) {               sp=getApplicationContext().getSharedPreferences("userP", 0);               Editor edit=sp.edit();               edit.putString("username", "");               edit.putInt("status", 0);               edit.commit();               finish();           }       });   }   private void tarif(){       update=(ImageView) findViewById(R.id.index_update);       share=(ImageView) findViewById(R.id.index_share);       New=(ImageView) findViewById(R.id.index_new);       edit=(ImageView) findViewById(R.id.index_edit);       setting=(ImageView) findViewById(R.id.index_setting);       exit=(ImageView) findViewById(R.id.index_exit);       welcome=(TextView) findViewById(R.id.index_welcome1_t);       name=(TextView) findViewById(R.id.index_name_t);       txt1=(TextView) findViewById(R.id.index_txt1_t);       tedad=(TextView) findViewById(R.id.index_tedad_t);       txt2=(TextView) findViewById(R.id.index_txt2_t);       payam=(TextView) findViewById(R.id.index_payam_t);   }   private void getcount(){       new getcount("http://example.com/app/count.php").execute();       new gfn("http://example.com/app/gfn.php").execute();       final Timer tm=new Timer();       final ProgressDialog pd=new ProgressDialog(index.this);       pd.setMessage("در حال دریافت تعداد جملات اماده دریافت"+"\n"+"برای استفاده از برنامه در حالت آفلاین کلید بازگشت را بزنید");       pd.show();       pd.setOnCancelListener(new ProgressDialog.OnCancelListener() {                    @Override           public void onCancel(DialogInterface arg0) {               new getcount("http://example.com/app/update.php").cancel(true);               new gfn("http://example.com/app/update.php").cancel(true);               count=0;               tm.cancel();           }       });       tm.scheduleAtFixedRate(new TimerTask(){           public void run() {               runOnUiThread(new Runnable(){                   public void run() {                       count++;                       if(count==30){                           pd.cancel();                           tm.cancel();                           new getcount("http://example.com/app/update.php").cancel(true);                           new gfn("http://example.com/app/update.php").cancel(true);                           Toast.makeText(getApplicationContext(), "خطا در برقراری ارتباط", Toast.LENGTH_LONG).show();                           tedad.setText("0");                       }                       if(!countS.equals("")){                           pd.setMessage("در حال دریافت اخبار آنلاین"+"\n"+"برای استفاده از برنامه در حالت آفلاین کلید بازگشت را بزنید");                       }                       if(!countS.equals("") && !news.equals("")){                           pd.cancel();                           db.open();                           int countL=db.count("content");                           db.close();                           int s=Integer.parseInt(countS)-countL;                           tedad.setText(s+"");                           payam.setText(news);                           countS="";                           news="";                           tm.cancel();                       }                   }               });           }       }, 1, 1000);   }   private void update(String count){       final String te=count;       new gfc("http://example.com/app/gfc.php",count,this).execute();       final Timer tm=new Timer();       final ProgressDialog pd=new ProgressDialog(index.this);       //pd.setMessage("در حال دریافت اطلاعات");       pd.setCancelable(false);       pd.show();       pd.setOnCancelListener(new ProgressDialog.OnCancelListener() {                    @Override           public void onCancel(DialogInterface arg0) {               new gfc("http://example.com/app/gfc.php",te,index.this).cancel(true);               tm.cancel();           }       });       tm.scheduleAtFixedRate(new TimerTask(){           public void run() {               runOnUiThread(new Runnable(){                   public void run() {                       int s=Integer.parseInt(tedad.getText().toString())-count2;                       pd.setMessage(" در حال دریافت اطلاعات"+"\n"+"جملات باقی مانده "+s+"\n"+"بریا لغو عملیات بر روی کلید بازگشت کلیک کنید");                       if(!res.equals("")){                           pd.cancel();                           count2=0;                           Toast.makeText(getApplicationContext(), "update comleted!!!", Toast.LENGTH_LONG).show();                           getcount();                           tm.cancel();                       }                   }               });           }       }, 1, 1000);   }}
لینک ارسال
به اشتراک گذاری در سایت های دیگر

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

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

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

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

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

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

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

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

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