博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
根据不同需求跳转不同Activity的另外一种写法
阅读量:5874 次
发布时间:2019-06-19

本文共 4427 字,大约阅读时间需要 14 分钟。

代码如下:

 

/*    Android Asynchronous Http Client Sample    Copyright (c) 2014 Marek Sebera 
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
(this, android.R.layout.simple_list_item_1, getTitlesList())); } private List
getTitlesList() { List
titles = new ArrayList
(); 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; } }}

  

转载地址:http://udenx.baihongyu.com/

你可能感兴趣的文章
for循环实例
查看>>
N1试卷常考词汇总结
查看>>
构建之法阅读笔记(1)
查看>>
POJ 3663:Costume Party
查看>>
主机连接虚拟机 web服务
查看>>
ajaxSubmit的data属性
查看>>
NetStatusEvent info对象的状态或错误情况的属性
查看>>
linux命令学习
查看>>
Windows下第三方库安装Nuget与Vcpkg
查看>>
URL的截取问题
查看>>
My first post
查看>>
git分支
查看>>
Ehcache 缓存
查看>>
list删除重复元素
查看>>
绘制屏幕时给单选按钮分组
查看>>
TCP/IP协议、DoD模型、OSI模型
查看>>
java开发环境
查看>>
Can't create handler inside thread that has not called Looper.prepare()
查看>>
ADB命令详解
查看>>
urllib模块学习
查看>>