大数据云计算-假数据学生管理系统
程序员文章站
2022-07-28 19:58:01
懂得l:
布局方式
泛型类。
实体类的使用 getter and setter 作用
使用MyAdapter extend BaseAdapter的各种细节使用。
mainac...
懂得l:
布局方式
泛型类。
实体类的使用 getter and setter 作用
使用MyAdapter extend BaseAdapter的各种细节使用。
mainac
import com.example.a49854.studentxuexi.domain.StudentInfo; import java.util.ArrayList; public class MainActivity extends AppCompatActivity { private EditText et_id; private EditText et_name; private EditText et_phone; private ListView lv; private ArrayList list; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); initView(); // 1.找到控件 // 2.模拟操作,添加假数据进行显示 // 3.去除假数据,添加真实数据 // 4.将真实数据写入到数据库中 // 5.将数据库上传到服务器 } /* 初始化界面 */ private void initView() { setContentView(R.layout.activity_main); et_id = (EditText) findViewById(R.id.et_id); et_name = (EditText) findViewById(R.id.et_name); et_phone = (EditText) findViewById(R.id.et_phone); lv = (ListView) findViewById(R.id.lv); list = new ArrayList<>(); for (int i = 0; i < 10; i++) { StudentInfo info = new StudentInfo(); info.setId(i); info.setName("student" + i); info.setPhone("1234567891" + i); list.add(info); } lv.setAdapter(new MyAdapter()); } private class MyAdapter extends BaseAdapter { @Override public int getCount() { return list.size(); } @Override public View getView(final int position, View convertView, ViewGroup parent) { View view = View.inflate(MainActivity.this, R.layout.item, null); TextView tv_item_id = (TextView) view.findViewById(R.id.tv_item_id); TextView tv_item_name = (TextView) view.findViewById(R.id.tv_item_name); TextView tv_item_phone = (TextView) view.findViewById(R.id.tv_item_phone); ImageView iv_delete = (ImageView) view.findViewById(R.id.iv_delete); iv_delete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { list.remove(position); // boolean result = dao.delete(map.get("studentid")); // if (result) { // Toast.makeText(MainActivity.this,"删除成功", Toast.LENGTH_SHORT).show(); // lv.setAdapter(new MyAdapter()); // } lv.setAdapter(new MyAdapter());//这种方法其实不好 } }); tv_item_id.setText(String.valueOf(list.get(position).getId())); tv_item_name.setText(list.get(position).getName()); tv_item_phone.setText(list.get(position).getPhone()); return view; } @Override public Object getItem(int position) { return list.get(position); } @Override public long getItemId(int position) { return position; } } }
StudentInfo
package com.example.a49854.studentxuexi.domain; /** * 学生信息的实体类 * @author Admin * @version $Rev$ * @des ${TODO} * @updateAuthor $Author$ * @updateDes ${TODO} */ public class StudentInfo { private Integer id;// private String name; private String phone; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPhone() { return phone; } public void setPhone(String phone) { this.phone = phone; } @Override public String toString() { return "StudentInfo{" + "id=" + id + ", name='" + name + '\'' + ", phone='" + phone + '\'' + '}'; } }
activity_main.xml
系统" android:textcolor="#ff0000" android:textsize="20dp">
item.xml