android studio 项目中引入第三方lib

发布时间:2020-05-18 11:41:25 作者:xuyongjun84
来源:网络 阅读:2304

本文以引入https://github.com/chrisbanes/Android-PullToRefresh为例


借鉴参考:http://www.apkbus.com/android-125663-1-1.html


本人电脑上的android studio是1.2.1.1 ,sdk api22.


  1. 正常创建一个project(本例中project为名"demo")

    android studio 项目中引入第三方lib

  2. 开始为项目引入PullToRefresh类库

    1. 按下键盘上“F12”或File->new->import module,如下

android studio 项目中引入第三方lib


android studio 项目中引入第三方lib



依次导入android-pulltorefresh目录下的library、extras\PullToRefreshListFragment、extras\PullToRefreshListFragment

完成后目录如下

android studio 项目中引入第三方lib


b.为demo下的app modules添加类库依赖。

android studio 项目中引入第三方lib

完成后结果如上。点击“OK”完成。

3.解决编译错误

android studio 项目中引入第三方lib

重新按"F12",修改除app外的其他三个modules中的min sdk和target sdk版本,与app相同

android studio 项目中引入第三方lib

ok,编译可以正常通过了。

4、添加一个测试示例。

 修改:layout/activity_main.xml文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="demo.zhezi.MainActivity"
    android:orientation="vertical" >
    <com.handmark.pulltorefresh.library.PullToRefreshListView
        android:id="@+id/listview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    </com.handmark.pulltorefresh.library.PullToRefreshListView>

</LinearLayout>

修改:MainActivity.java文件

private PullToRefreshListView listView ;
	private ArrayAdapter<String> arrayAdapter;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		listView = (PullToRefreshListView) findViewById(R.id.listview);
		arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
		arrayAdapter.add("welcome");
		arrayAdapter.add("welcome1");
		arrayAdapter.add("welcome2");
		arrayAdapter.add("welcome3");
		listView.setAdapter(arrayAdapter);
		listView.setOnRefreshListener(new OnRefreshListener<ListView>() {
			@Override
			public void onRefresh(PullToRefreshBase<ListView> refreshView) {		
				new AsyncTask<Void, Void, Void>() {

					@Override
					protected Void doInBackground(Void... params) {
						
						try {
							Thread.sleep(3000);
						} catch (InterruptedException e) {
							e.printStackTrace();
						}
						
						return null;
					}	
					protected void onPostExecute(Void result) {
						
						arrayAdapter.addAll("Hello","大家好");
						
						listView.onRefreshComplete();
					};
				}.execute();
			}
		});



好了。展示效果如下

android studio 项目中引入第三方lib

android studio 项目中引入第三方lib


推荐阅读:
  1. Android Studio -- Installation and useage
  2. Android Studio 合并module到统一文件夹的方法

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

android_studio pullt 第三 roi

上一篇:python里的str是什么函数

下一篇:MySQL中的索引有哪些类型或者种类

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》