Android Studio安装使用参考
https://www.bilibili.com/video/BV1kQ4y1P7zv?from=search&seid=11422664080662393489
https://jingyan.baidu.com/article/3f16e0031e3c522591c10387.html
https://www.runoob.com/android/android-studio-install.html
https://www.runoob.com/w3cnote/android-tutorial-android-studio.html
创建4个文件
Activity、presenter、module、constract
在接口类constract中创建两个内部接口类:View和Presenter。暴露需要的接口方法
Contract
public interface TestContract {
interface View extends BaseView<Presenter> {
void onSuccess(Object obj);
}
interface Presenter extends BasePresenter<View> {
void getList(Object obj);
}
}
Activity继承BaseActivity并实现刚刚的内部接口View
通过注解注入presenter对象
在onCreate中调用presenter.takeView(this)
在onDestory中调用presenter.dropView
package jay.com.example.firstapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
//定义MainActivity继承Activity类
public class MainActivity extends AppCompatActivity {
@Override
//实现onCreate方法
protected void onCreate(Bundle savedInstanceState) {
//调用父类
super.onCreate(savedInstanceState);
//加载R.layout.activity_main布局文件
setContentView(R.layout.activity_main);
}
}
需要在AndroidManifest.xml里声明
示例
<RelativeLayout 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=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>