其他分享
首页 > 其他分享> > 直播系统代码,登录时常用验证方式

直播系统代码,登录时常用验证方式

作者:互联网

直播系统代码,登录时常用验证方式实现的相关代码

引用:

 

dependencies {
...
    compile 'com.android.support:recyclerview-v7:25.3.1'
}

 

代码:

1、item布局

 


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <TextView
        android:id="@+id/id_num"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:background="#ff5500"
        android:gravity="center"
        android:text="hello" />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorPrimary" />
</LinearLayout>

 

 

2、适配器代码

 

 

package com.example.lihui.testrecycleview;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.List;
/**
 * Created by lihui on 2017/8/22.
 */
public class MyRecyclerAdapter extends RecyclerView.Adapter<MyRecyclerAdapter.MyViewHolder> {
    private static final String TAG = "MyRecyclerAdapter";
    private List<String> mData;
    private Context mContext;
    private LayoutInflater inflater;
    public MyRecyclerAdapter(Context context, List<String> data) {
        this.mContext = context;
        this.mData = data;
        inflater = LayoutInflater.from(mContext);
    }
    @Override
    public int getItemCount() {
        return mData.size();
    }
    @Override
    public void onViewRecycled(MyViewHolder holder) {
        super.onViewRecycled(holder);
        Log.d(TAG, "onViewRecycled: " + holder.tv.getText().toString() + ", position: " + holder.getAdapterPosition());
    }
    //填充onCreateViewHolder方法返回的holder中的控件
    @Override
    public void onBindViewHolder(final MyViewHolder holder, final int position) {
        Log.d(TAG, "onBindViewHolder: 验证是否重用了");
        Log.d(TAG, "onBindViewHolder: 重用了" + holder.tv.getTag());
        Log.d(TAG, "onBindViewHolder: 放到了" + mData.get(position));
        holder.tv.setText(mData.get(position));
        holder.tv.setTag(mData.get(position));
    }
    //重写onCreateViewHolder方法,返回一个自定义的ViewHolder
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        Log.d(TAG, "onCreateViewHolder");
        View view = inflater.inflate(R.layout.item_layout, parent, false);
        return new MyViewHolder(view);
    }
    static class MyViewHolder extends RecyclerView.ViewHolder {
        TextView tv;
        public MyViewHolder(View view) {
            super(view);
            tv = (TextView) view.findViewById(R.id.id_num);
        }
    }
}

 

 

3、activity代码

 

 

package com.example.lihui.testrecycleview;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private List<String> mData;
    private MyRecyclerAdapter recycleAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        recyclerView = (RecyclerView) findViewById(R.id.id_recyclerView);
        initData();
        recycleAdapter = new MyRecyclerAdapter(MainActivity.this, mData);
        //设置布局管理器 , 将布局设置成纵向
        LinearLayoutManager linerLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
        recyclerView.setLayoutManager(linerLayoutManager);        // ...
        recyclerView.setAdapter(recycleAdapter);
        // ...
    }
    private void initData() {
        mData = new ArrayList<>();
        mData.add("test1"); //0
        mData.add("test2"); //0
        mData.add("test3"); //0
        mData.add("test4"); //0
        mData.add("test5"); //0
        mData.add("test6"); //0
        mData.add("test7"); //0
        mData.add("test8"); //0
        mData.add("test9"); //0
        mData.add("test10"); //0
        mData.add("test11"); //0
        mData.add("test12"); //0
        mData.add("test13"); //0
        mData.add("test14"); //0
    }
}

 

 

4、recycleview 布局

 


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.lihui.testrecycleview.MainActivity">
    <android.support.v7.widget.RecyclerView
        android:id="@+id/id_recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

 

以上就是直播系统代码,登录时常用验证方式实现的相关代码, 更多内容欢迎关注之后的文章

 

标签:mData,layout,登录,验证,add,直播,import,android,id
来源: https://www.cnblogs.com/yunbaomengnan/p/15465593.html