007 android开源项目个性化控件

此部分的内容主要参考github上的开源项目,

有兴趣的朋友也可以阅读那部分内容

https://github.com/Trinea/android-open-project

博客只是用不同的形式展现,也加上自己在实现的过程中碰到的问题,对于app层的开始只是停留在最基础的接口调用之上,欢迎交流,欢迎讨论。


本部分主要包括五部分的内容,循序渐进,希望对写app的朋友有帮助。

Android 开源项目第一篇:个性化控件(View)篇

包括ListView, ActionBar, Menu, ViewPager, Gallery, GridView, ImageView, ProgressBar, TextView, ScrollView, TimeView, TipView, FlipView, ColorPickView, GraphView, Ui Style等等。

Android开源项目第二篇:工具库篇

包括依赖注入,图片缓存,网络请求,数据库 ORM 工具包 Android公共库 高版本向低版本兼容库,多媒体,事件总线,传感器,安全,插件化,文件,等等。

Android 开源项目第三篇——优秀项目

比较有意思的完整的 Android 项目

Android 开源项目第四篇——开发及测试工具篇

包括开发效率工具、开发自测相关、测试工具、开发及编译环境、其他

Android 开源项目第五篇——优秀个人和团体篇

乐于分享并且有一些很不错的开源项目的个人和组织,包括 JakeWharton、Chris Banes、Koushik Dutta 等大牛


直接开始写程序,Android Studio新建一个项目,命名为PullToRefresh,

程序入口类LauncherActivity

package com.example.wang.pulltorefresh;

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

public class LauncherActivity extends ListActivity {
    public static final String[] options = { "ListView", "ExpandableListView", "GridView", "WebView", "ScrollView",
            "Horizontal ScrollView", "ViewPager", "ListView Fragment", "WebView Advanced", "ListView in ViewPager" };

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

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        Intent intent;
        switch (position) {
            default:
            case 0:
                intent = new Intent(this, PullToRefreshListActivity.class);
                break;
        }
        startActivity(intent);
    }
}

新建另外一个类PullToRefreshListActivity

package com.example.wang.pulltorefresh;

import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
import android.support.annotation.Nullable;

/**
 * Created by wang on 17-6-22.
 */

class PullToRefreshListActivity extends Activity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ptr_list);
    }
}

xml文件activity_ptr_list

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    android:id="@+id/pull_refresh_list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:cacheColorHint="#00000000"
        android:divider="#19000000"
        android:dividerHeight="4dp"
        android:fadingEdge="none"
        android:fastScrollEnabled="false"
        android:footerDividersEnabled="false"
        android:headerDividersEnabled="false"
        android:smoothScrollbar="true"

</LinearLayout>

运行模拟图



随便点进去一个item都会跳到一个空白的界面中。

注意

10-22 23:20:01.826  32331-32331/com.example.news.andoridnewsapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.example.news.andoridnewsapp, PID: 32331
    android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.news.andoridnewsapp/com.example.news.andoridnewsapp.PullToRefreshListFragmentActivity}; have you declared this activity in your AndroidManifest.xml?
            at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
            at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
            at android.app.Activity.startActivityForResult(Activity.java:3442)
            at android.app.Activity.startActivityForResult(Activity.java:3403)
            at android.support.v4.app.FragmentActivity.startActivityFromFragment(FragmentActivity.java:813)
            at android.support.v4.app.FragmentActivity$HostCallbacks.onStartActivityFromFragment(FragmentActivity.java:871)
            at android.support.v4.app.Fragment.startActivity(Fragment.java:916)
            at com.example.news.andoridnewsapp.NavigationDrawerFragment$1.onItemClick(NavigationDrawerFragment.java:137)
            at android.widget.AdapterView.performItemClick(AdapterView.java:299)
            at android.widget.AbsListView.performItemClick(AbsListView.java:1115)
            at android.widget.AbsListView$PerformClick.run(AbsListView.java:2913)
            at android.widget.AbsListView$3.run(AbsListView.java:3680)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5047)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
            at dalvik.system.NativeStart.main(Native Method)
复制代码

  解决办法:

  在主工程的AndroidManifest.xml中添加声明

<activity android:name=".PullToRefreshListFragmentActivity"></activity>

对现在的自己太难,果断放弃,先学习标准的怎么写程序。

现在要扩展库,搞不来。





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值