public class Student { long id; String number; String name; String status; public long getId() { return id; } public void setId(long id) { this.id = id; } public String getNumber() { return number; } public void setNumber(String number) { this.number = number; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getStatus() { return status; } public void setStatus(String tweet) { this.status = tweet; }
package com.example.honka_1; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView; import java.util.ArrayList; public class CustomAdapter extends BaseAdapter{ Context context; LayoutInflater layoutInflater = null; ArrayListstudentList; public CustomAdapter(Context context) { this.context = context; this.layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } public void setTweetList(ArrayList tweetList) { this.studentList = tweetList; } @Override public int getCount() { return studentList.size(); } @Override public Object getItem(int position) { return studentList.get(position); } @Override public long getItemId(int position) { return studentList.get(position).getId(); } @Override public View getView(int position, View convertView, ViewGroup parent) { convertView = layoutInflater.inflate(R.layout.studentrow,parent,false); ((TextView)convertView.findViewById(R.id.id)).setText(studentList.get(position).getNumber()); ((TextView)convertView.findViewById(R.id.name)).setText(studentList.get(position).getName()); ((TextView)convertView.findViewById(R.id.status)).setText(studentList.get(position).getStatus()); return convertView; } }
4 Définir ListView dans Activity ou Fragment
5 Réglez l'adaptateur sur ListView
public class Main2Activity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); Intent intent = this.getIntent(); Integer selectedDay = intent.getIntExtra("selectedDay",0); Log.i("test", selectedDay.toString()); ListView listView = (ListView)findViewById(R.id.listView); ArrayListlist = new ArrayList<>(); CustomAdapter adapter = new CustomAdapter(Main2Activity.this); adapter.setTweetList(list); listView.setAdapter(adapter); Student student = new Student(); student.setNumber("1"); student.setName ("Wada"); student.setStatus ("participation"); list.add(student); adapter.notifyDataSetChanged(); } }
Recommended Posts