bao
程序员文章站
2024-03-23 21:23:04
...
登录 注册展示逻辑判断
private Handler handler= new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
int arg1 = msg.arg1;
if(arg1 == 1){
//post 接口的逻辑
s=(String)msg.obj;
if (s.contains("成功")){
callBack.onSuccess(s);
}
}else {
// get 接口逻辑
bean=(Bean)msg.obj;
if (bean==null) {
backCall.onShowError("bean类为空");
}else if (bean!=null){
backCall.onShowSuccess(bean);
}
}
}
};
this.cakkbackInterface=cakkbackInterface;
OkHttpUtil.getInstance().doGet(handler,1);
OkHttpUtil.getInstance().doGet2(handler,2);
点击分类
public void setOnclickListenr(onclickListenr onclickListenr) {
this.onclickListenr = onclickListenr;
}
public interface onclickListenr{
void click(String sd);
}
继承适配器
yejm
Handler handler =new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (msg.what==3){
String o =(String) msg.obj;
Log.e("Tag",o+"");
Gson gson = new Gson();
RightBean rightBean = gson.fromJson(o, RightBean.class);
rightAdapter = new RightAdapter(rightBean.getResult(), MainActivity.this);
rightrecyclerView.setAdapter(rightAdapter);
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iPresenterInterface=new PresenterClass(this);
iPresenterInterface.onPresenterInterface();
initView();
}
private void initView() {
rightrecyclerView = findViewById(R.id.right_recycleview);
leftrecyclerView = findViewById(R.id.left_recycleview);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
leftrecyclerView.setLayoutManager(linearLayoutManager);
GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 3);
gridLayoutManager.setOrientation(GridLayoutManager.VERTICAL);
rightrecyclerView.setLayoutManager(gridLayoutManager);
rightrecyclerView.addItemDecoration(new DividerItemDecoration(this,LinearLayout.VERTICAL));
iPresenterInterface =new PresenterClass(this);
iPresenterInterface.onPresenterInterface();
}
@Override
public void onshow(Object object) {
LeftBean leftBeanbean =(LeftBean) object;
leftAdapter = new LeftAdapter(leftBeanbean.getResult(), this);
leftAdapter.setOnclickListenr(this);
leftrecyclerView.setAdapter(leftAdapter);
}
@Override
public void onRight(Object object) {
RightBean rightBean=(RightBean) object;
rightAdapter = new RightAdapter(rightBean.getResult(), this);
rightrecyclerView.setAdapter(rightAdapter);
}
@Override
public void click(String sd) {
getLeft(sd);
OkHttpUtil.do2Get3(handler,2,sd);
Log.e("SD",sd+"");
}
private void getLeft(String sd) {
iPresenterInterface.onPresenterInterface();
}
}
// adapter
public class LeftAdapter extends RecyclerView.Adapter<LeftAdapter.ViewHolder>{
private List<LeftBean.ResultBean> list;
private Context context;
private ceshi ceshi=null;
public void setCeShi(ceshi ceshi) {
this.ceshi = ceshi;
}
public LeftAdapter(List<LeftBean.ResultBean> list, Context context) {
this.list = list;
this.context = context;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view=LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.left_item,null);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull ViewHolder viewHolder, final int i) {
viewHolder.textView.setText(list.get(i).name);
final String id = list.get(i).getName();
viewHolder.textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(onclickListenr!=null){
onclickListenr.click(list.get(i).name.substring(0,2));
}
}
});
}
@Override
public int getItemCount() {
if (list!=null){
return list.size();
}else{
return 0;
}
}
public class ViewHolder extends RecyclerView.ViewHolder{
private final TextView textView;
public ViewHolder(@NonNull View itemView) {
super(itemView);
textView = itemView.findViewById(R.id.left_titlea);
}
}
public onclickListenr onclickListenr;
public void setOnclickListenr(onclickListenr onclickListenr) {
this.onclickListenr = onclickListenr;
}
public interface onclickListenr{
void click(String sd);
}
}
上一篇: do……while错题记录
下一篇: Vue面试知识点整理