Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何获取有关数据库的信息并在AppWidgetProvider上显示_Android_Database_Eclipse - Fatal编程技术网

Android 如何获取有关数据库的信息并在AppWidgetProvider上显示

Android 如何获取有关数据库的信息并在AppWidgetProvider上显示,android,database,eclipse,Android,Database,Eclipse,我有一个活动和一个应用程序小部件提供商活动。我有一些字符串可以从网上的数据库中获取信息并显示出来。(它们是两个文本视图) 但我不知道如何将它们包含到我的小部件中。 我在我的活动上复制了这两个文本视图并粘贴到我的小部件活动上,但它们并没有显示来自数据库的任何信息。 当然,我有很多文本视图可以获取一些信息,但我只需要“index\u payam\u t”和“index\u txt2\u t”! 我的活动代码是: package com.irprogram.ted; import java.util

我有一个活动和一个应用程序小部件提供商活动。我有一些字符串可以从网上的数据库中获取信息并显示出来。(它们是两个文本视图) 但我不知道如何将它们包含到我的小部件中。 我在我的活动上复制了这两个文本视图并粘贴到我的小部件活动上,但它们并没有显示来自数据库的任何信息。 当然,我有很多文本视图可以获取一些信息,但我只需要“index\u payam\u t”和“index\u txt2\u t”! 我的活动代码是:

package com.irprogram.ted;

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);





    }



}

在Android中实现应用程序小部件时,您必须使用
remoteview
而不是
View
s,并且您应该使用该方法设置
TextView
的文本, 您可以查看教程,其中提供了大量关于处理应用程序小部件及其
远程视图的信息