根据不同需求跳转不同Activity的另外一种写法

简介: 代码如下:   /* Android Asynchronous Http Client Sample Copyright (c) 2014 Marek Sebera http://loopj.

代码如下:

 

/*
    Android Asynchronous Http Client Sample
    Copyright (c) 2014 Marek Sebera <marek.sebera@gmail.com>
    http://loopj.com

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/

package com.loopj.android.http.sample;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

public class WaypointsActivity extends ListActivity {

    private static final SampleConfig[] samplesConfig = new SampleConfig[]{
            new SampleConfig(R.string.title_get_sample, GetSample.class),
            new SampleConfig(R.string.title_post_sample, PostSample.class),
            new SampleConfig(R.string.title_delete_sample, DeleteSample.class),
            new SampleConfig(R.string.title_put_sample, PutSample.class),
            new SampleConfig(R.string.title_patch_sample, PatchSample.class),
            new SampleConfig(R.string.title_json_sample, JsonSample.class),
            new SampleConfig(R.string.title_json_streamer_sample, JsonStreamerSample.class),
            new SampleConfig(R.string.title_sax_example, SaxSample.class),
            new SampleConfig(R.string.title_file_sample, FileSample.class),
            new SampleConfig(R.string.title_binary_sample, BinarySample.class),
            new SampleConfig(R.string.title_gzip_sample, GzipSample.class),
            new SampleConfig(R.string.title_redirect_302, Redirect302Sample.class),
            new SampleConfig(R.string.title_threading_timeout, ThreadingTimeoutSample.class),
            new SampleConfig(R.string.title_cancel_all, CancelAllRequestsSample.class),
            new SampleConfig(R.string.title_cancel_handle, CancelRequestHandleSample.class),
            new SampleConfig(R.string.title_synchronous, SynchronousClientSample.class),
            new SampleConfig(R.string.title_intent_service_sample, IntentServiceSample.class),
            new SampleConfig(R.string.title_post_files, FilesSample.class),
            new SampleConfig(R.string.title_persistent_cookies, PersistentCookiesSample.class),
            new SampleConfig(R.string.title_custom_ca, CustomCASample.class),
            new SampleConfig(R.string.title_retry_handler, RetryRequestSample.class),
            new SampleConfig(R.string.title_range_sample, RangeResponseSample.class),
            new SampleConfig(R.string.title_401_unauth, Http401AuthSample.class),
            new SampleConfig(R.string.title_pre_post_processing, PrePostProcessingSample.class),
            new SampleConfig(R.string.title_content_type_http_entity, ContentTypeForHttpEntitySample.class),
            new SampleConfig(R.string.title_resume_download, ResumeDownloadSample.class),
            new SampleConfig(R.string.title_digest_auth, DigestAuthSample.class),
            new SampleConfig(R.string.title_use_pool_thread, UsePoolThreadSample.class)
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, getTitlesList()));
    }

    private List<String> getTitlesList() {
        List<String> titles = new ArrayList<String>();
        for (SampleConfig config : samplesConfig) {
            titles.add(getString(config.titleId));
        }
        return titles;
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        if (position >= 0 && position < samplesConfig.length)
            startActivity(new Intent(this, samplesConfig[position].targetClass));
    }

    private static class SampleConfig {

        final int titleId;
        final Class targetClass;

        SampleConfig(int titleId, Class targetClass) {
            this.titleId = titleId;
            this.targetClass = targetClass;
        }

    }

}

  

目录
相关文章
|
10月前
|
小程序
小程序wx.switchTab的跳转传参问题
小程序wx.switchTab的跳转传参问题
150 0
|
容器
使用Fragmentation,start跳转到嵌套viewpager页面出现返回键重写失效原因。
最近在写项目时,采用的是单Activity+多Fragment的架构,用的Fragmentation的库。我的主页面是一个BootomFragment的抽象类(当然它还有一个管理类),其又继承自最大的LatteDelegate,LatteDelegate又继承自Fragment并实现Fragmentation库的接口,当然,当然这只是其中一部分,所以简略的讲了一下,大概知道层次就行。
97 0
使用Fragmentation,start跳转到嵌套viewpager页面出现返回键重写失效原因。
|
存储 Android开发 索引
带着需求看源码《如何判断 Activity 上是否有弹窗》
带着需求看源码《如何判断 Activity 上是否有弹窗》
498 0
带着需求看源码《如何判断 Activity 上是否有弹窗》
使用NavHostFragment、navigation--- avtivity向fragment传值,fragment之间传值
使用NavHostFragment、navigation--- avtivity向fragment传值,fragment之间传值
232 0
页面跳转的几种用法区别
一. my.navigateTo: 保留当前页面,跳转到应用内的某个页面,路径后可带参数;使用 abridge.navigateBack 可以返回到原页面; 示例代码:  my.navigateTo({ url: 'test?id=1' })  二.
733 12
|
XML Android开发 iOS开发
Android开发之Activity的创建跳转及传值
在Android系统的江湖中有四大组件:活动(Activity), 服务(Service), 广播接收器(Broadcast Reciver)和内容提供者(Content Provider)。
1134 0
|
Android开发 存储 开发工具
|
容器
Fragment 代码怎么写
public class Voice extends Fragment implements OnClickListener { public View onCreateView(LayoutInflater inflater, ViewGroup container, ...
784 0