Android studioプロジェクトにサードパーティlibを導入
4174 ワード
本論文では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”と名付けます)
を作成しますプロジェクトのPullToRefreshクラスライブラリの導入を開始 キーボードの「F 12」またはFile->new->import moduleを押すと、次の になります.
Android-pulltorefreshディレクトリのlibrary、extrasPullToRefreshListFragment、extrasPullToRefreshListFragmentの順にインポート
完了後のディレクトリは次のとおりです.
b.demoの下のapp modulesにクラスライブラリ依存性を追加します.
完成後の結果は上記の通りです.「OK」をクリックして完了します.
3.コンパイルエラーの解決
「F 12」を押し直し、app以外の3つのmodulesのmin sdkとtarget sdkバージョンをappと同じに変更します.
OK、コンパイルは正常に通過できます.
4、テスト例を追加します.
変更:layout/activity_main.xmlファイル
変更:MainActivity.JAvaファイル
はい.展示効果は以下の通りです
参考:http://www.apkbus.com/android-125663-1-1.html
本人のパソコンのandroid studioは1.2です.1.1 ,sdk api22.



Android-pulltorefreshディレクトリのlibrary、extrasPullToRefreshListFragment、extrasPullToRefreshListFragmentの順にインポート
完了後のディレクトリは次のとおりです.

b.demoの下のapp modulesにクラスライブラリ依存性を追加します.

完成後の結果は上記の通りです.「OK」をクリックして完了します.
3.コンパイルエラーの解決

「F 12」を押し直し、app以外の3つのmodulesのmin sdkとtarget sdkバージョンをappと同じに変更します.

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();
}
});
はい.展示効果は以下の通りです

