今天做了什么:

完成了社区界面

同时设置好了listview

package com.hui.testend.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.hui.testend.R;
import com.hui.testend.community.displayActivity;
import com.hui.testend.list.ItemBean;
import com.hui.testend.list.MyAdapter;
import com.hui.testend.mytool.Dao;
import com.hui.testend.recongnize.MyObject;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
* A simple {@link Fragment} subclass.
* Use the {@link Fragment_community#newInstance} factory method to
* create an instance of this fragment.
*/
public class Fragment_community extends Fragment implements AdapterView.OnItemClickListener {
ListView list_comm;
MyAdapter myAdapter;
Dao dao=new Dao();
List<ItemBean> mBeanList;
Handler mainhandler;

// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";

// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;

public Fragment_community() {
// Required empty public constructor
}

/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment Fragment_community.
*/
// TODO: Rename and change types and number of parameters
public static Fragment_community newInstance(String param1, String param2) {
Fragment_community fragment = new Fragment_community();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_community, container, false);
}

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
init(view);
initData();
}
public void init(View v){
list_comm=v.findViewById(R.id.list_comm);
list_comm.setOnItemClickListener(this);
mainhandler=new Handler(Looper.getMainLooper());
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
System.out.println(77777);
// ((displayActivity)getActivity()).getid(mBeanList.get(position).getId());
Intent intent=new Intent(getActivity(), displayActivity.class);
int id1=mBeanList.get(position).getId();
intent.putExtra("id",id1);
startActivity(intent);
}
public void initData(){
mBeanList=new ArrayList<>();
new Thread(new Runnable() {
@Override
public void run() {
List<ItemBean> list=dao.getmain_data();
for (ItemBean data:list) {
ItemBean itemBean=new ItemBean();
itemBean.setId(data.getId());
itemBean.setTitle(data.getTitle());
itemBean.setContent(data.getContent());
itemBean.setImg(data.getImg());
//System.out.println(Arrays.toString(data.getImg()));
mBeanList.add(itemBean);
System.out.println(mBeanList.size());
}
mainhandler.post(new Runnable() {
@Override
public void run() {
Context context = getActivity();
if (context != null) {
myAdapter=new MyAdapter(context,mBeanList);
}
list_comm.setAdapter(myAdapter);
}
});
}
}).start();
}
}
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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=".fragment.Fragment_community">
<ListView
android:id="@+id/list_comm"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</FrameLayout>

遇到了什么困难:

 

明天准备做什么:

继续完成作业

代码量 200行

时间 1小时