安卓1

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

image.png

创建4个文件
Activity、presenter、module、constract
image.png

在接口类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里声明

image.png

示例

<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>
image.png

AndroidManifest.xml

image.png

image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容