片段或查看寻呼机

时间:2014-03-18 21:37:06

标签: java android android-intent android-fragments

我是Android编程的新手,我有一个概念问题。我试图开发的应用程序非常简单。它基本上是一个从网站收集信息并在不同幻灯片中的View Pager中显示信息的应用程序。

到目前为止,我所调查的是,我将使用意向服务从远程网站/ db获取信息,但我遇到的问题是尝试更新广播中的视图接收器。

我一直在寻找,我在想,也许我会以错误的方式去做。该应用程序的要求如下

  • 能够通过滑动操作显示多张幻灯片(相同的格式/布局)。
  • 定期从网站获取信息(我相信警报管理员的意向服务)

所以我在这里寻找的可能是关于如何去做的一些指示。到目前为止,我一直在尝试使用View Pager创建多个幻灯片和Intent Service来获取信息。但是,我无法更新幻灯片,我正在寻找onReceive(我不知道如何引用它)。

这里有一些与我的查询相关的示例代码。

主要活动和查看寻呼机声明

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //Load main layout
    setContentView(R.layout.main);

    //Show loading view while network loads content
    mContentView = findViewById(R.id.pager);
    mLoadingView = findViewById(R.id.loading_spinner);

    // Initially hide the content view.
    mContentView.setVisibility(View.GONE);

    // Retrieve and cache the system's default "short" animation time.
    mShortAnimationDuration = getResources().getInteger(android.R.integer.config_shortAnimTime);

    //Set clubs to display
    //TODO - Get this info from API
    //TODO - Remove HardCode
    ArrayList<Club> clubs = new ArrayList<Club>();
    //rep   -   REPUBLIKA MOVIL
    Club temp = new Club();
    temp.setId(0);
    temp.setClubCode("rep");
    temp.setHost("http://control.outech.com.mx");
    clubs.add(temp);
    /*
     * Creates a new Intent to start the ClubPullService
     * IntentService. Passes a URI in the
     * Intent's "data" field.
     */
    for(int i = 0; i < clubs.size(); i++){
        //Define intent service
        mServiceIntent = new Intent(this, ClubPullService.class);
        mServiceIntent.putExtra("club", clubs.get(i));

        // Starts the IntentService
        this.startService(mServiceIntent);          
    }

    /*
     * Setup receivers to get club information 
     */
    IntentFilter mStatusIntentFilter = new IntentFilter(Constants.BROADCAST_ACTION);

    // Instantiates a new PullReceiver
    PullReceiver mPullReceiver = new PullReceiver();
    // Registers the PullReceiver and its intent filters
    LocalBroadcastManager.getInstance(this).registerReceiver(mPullReceiver, mStatusIntentFilter);

    // Instantiate a ViewPager and a PagerAdapter.
    mPagerAdapter = new SlideAdapter();
    mPager = (ViewPager) mContentView;
    mPager.setAdapter(mPagerAdapter);

    //Creates the views in the pager
    for(int i = 0; i < clubs.size(); i++){
        RelativeLayout v0 = (RelativeLayout) getLayoutInflater().inflate (R.layout.slide, null);
        mPagerAdapter.addView (v0);
        mPagerAdapter.notifyDataSetChanged();
    }       
}

单独的班级广播接收器

public void onReceive(Context context, Intent intent) {
    // Gets data from the incoming Intent    
    Club club = intent.getParcelableExtra(Constants.CLUB_INFORMATION);
    Log.v(LOG, "Received: "+club.getClubName());

    /*
    //Time of sync
    Time today = new Time(Time.getCurrentTimezone());
    today.setToNow();   
    TextView sync = (TextView) ctx.findViewById(R.id.textViewSyncValue);
    sync.setText(String.format(context.getResources().getString(R.string.lbl_sync), String.valueOf(today.format("%d/%m/%Y %k:%M:%S"))));        
    */

}

0 个答案:

没有答案