Android 如何从arraylist的中间值显示列表
我必须像下面这样做Android 如何从arraylist的中间值显示列表,android,Android,我必须像下面这样做 从服务器获取数组(日期(文本视图),小时(编辑文本->添加、删除、更新)) 在第一个屏幕的列表中显示11项-中间的ex current date和5个previous date以及5个future date 下一个按钮和上一个按钮-下一个按钮显示11个未来日期来自数组,并且相同的上一个按钮在每个屏幕上显示11个日期,就像分页一样 我可以显示数据,当按下“下一步”按钮时,它会显示下11项//但我想从当前日期开始设置列表。 然后用户按下“下一步”按钮,它将显示阵列的下一个11项结
loadList(NUM_ITEMS_JUMP);
适配器
公共类ByDayListAdapter扩展了ArrayAdapter{
语境;
列出maByDay;
@凌驾
public int getCount(){
返回maByDay.size();
}
public ByDayListAdapter(上下文上下文、int-resource、int-textViewResourceId){
超级(上下文、资源、textViewResourceId);
}
public ByDayListAdapter(上下文上下文,列表faByDay){
超级(上下文,0,faByDay);
this.context=上下文;
this.maByDay=faByDay;
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
//获取此职位的数据项
ByDay loByDay=getItem(位置);
//检查是否正在重用现有视图,否则会膨胀视图
if(convertView==null){
convertView=LayoutInflater.from(getContext()).flate(R.layout.listitem_byday,parent,false);
}
//数据填充的查找视图
EditText etName=(EditText)convertView.findViewById(R.id.etByDaily);
TextView tvHome=(TextView)convertView.findViewById(R.id.tvByDayDate);
if(Common.getCurrentDate().equalsIgnoreCase(loByDay.getStartDate())){
System.out.println(“从日期--lsStartDate….”+loByDay.getStartDate()+“\nCommon.getCurrentDate()……”+Common.getCurrentDate());
设置字体(Typeface.defaultFromStyle(Typeface.BOLD));
setextcolor(ActivityCompat.getColor(context,R.color.black_light));
}否则{
setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
setextcolor(ActivityCompat.getColor(context,R.color.gray));
}
setText(loByDay.getStartDate());
setxt(loByDay.getHours());
addTextChangedListener(新的EditTextWatcher(loByDay));
//返回要在屏幕上渲染的已完成视图
返回视图;
}
公共类EditTextWatcher实现TextWatcher{
私人的日子一天天过去;
公共EditTextWatcher(按日按日){
this.byDay=byDay;
}
@凌驾
公共无效后文本已更改(可编辑){
byDay.setHours(s.toString());
}
@凌驾
更改前的公共void(字符序列arg0、int arg1、int arg2、,
int arg3){
}
@凌驾
public void onTextChanged(字符序列arg0、int arg1、int arg2、int arg3){
}
}
}
截屏
如何获得这种方法??还有别的办法吗?或者可以通过listview来实现?请帮我做这个
loadList(0);
loadList(NUM_ITEMS_JUMP);
public class ByDayListAdapter extends ArrayAdapter<ByDay> {
Context context;
List<ByDay> maByDay;
@Override
public int getCount() {
return maByDay.size();
}
public ByDayListAdapter(Context context, int resource, int textViewResourceId) {
super(context, resource, textViewResourceId);
}
public ByDayListAdapter(Context context, List<ByDay> faByDay) {
super(context, 0, faByDay);
this.context = context;
this.maByDay = faByDay;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Get the data item for this position
ByDay loByDay = getItem(position);
// Check if an existing view is being reused, otherwise inflate the view
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.listitem_byday, parent, false);
}
// Lookup view for data population
EditText etName = (EditText) convertView.findViewById(R.id.etByDayTime);
TextView tvHome = (TextView) convertView.findViewById(R.id.tvByDayDate);
if (Common.getCurrentDate().equalsIgnoreCase(loByDay.getStartDate())) {
System.out.println("from day -- lsStartDate.... " + loByDay.getStartDate() + "\nCommon.getCurrentDate()....... " + Common.getCurrentDate());
tvHome.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
tvHome.setTextColor(ActivityCompat.getColor(context, R.color.black_light));
} else {
tvHome.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
tvHome.setTextColor(ActivityCompat.getColor(context, R.color.gray));
}
tvHome.setText(loByDay.getStartDate());
etName.setText(loByDay.getHours());
etName.addTextChangedListener(new EditTextWatcher(loByDay));
// Return the completed view to render on screen
return convertView;
}
public class EditTextWatcher implements TextWatcher {
private ByDay byDay;
public EditTextWatcher(ByDay byDay) {
this.byDay = byDay;
}
@Override
public void afterTextChanged(Editable s) {
byDay.setHours(s.toString());
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
}
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
}
}
}