【发布时间】:2016-01-23 10:51:51
【问题描述】:
所以伙计们,我将尝试解释一下我想做的项目的这一部分,以便你们更好地理解我的问题。我正在尝试不为公交车站开发应用程序来显示时间表。为了展示它,我使用了一个 ListView,一个服装。如果我只将字符串传递给适配器,它就可以工作。但是为了只在一个字符串数组中做会占用大量内存,因为我必须构建很多数组。因为,试着想象一下,我有离开某个地方的公共汽车的时间表,但是然后,根据用户选择的目的地,我必须从数组中排除一些项目,因为并非所有公共汽车的终点都在同一个地方,有些赢了'不要去选定的目的地,所以我必须把那些拿出来。因此,如果我打算只在多个阵列中执行此操作,则必须为出发和目的地的每一个可能性构建数十个阵列。所以我想用一个数组列表来做,这样会更容易删除我不想要的项目。 现在的问题是我无法发送到costum listview和arraylist的适配器,像这样:
ArrayList<String> horarios= new ArrayList<String>();
ListAdapter horarioAdapter = new costum_adapter(this, horarios);
ListView horarioListView = (ListView) findViewById(R.id.horario_listView);
horarioListView.setAdapter(horarioAdapter);
它在第二行给了我错误,因为我不能把“horarios”放在适配器中,因为它是一个数组列表。我该如何解决这个问题?希望你们明白我想要做什么。 抱歉描述太长了。
这是我的 costum_adapter,没有太多,只有 2 个 textView,我只是想试试这个,然后添加一些东西。
class costum_adapter extends ArrayAdapter<String>{
public costum_adapter(Context context, String[] horarios) {
super(context, R.layout.costum_listview ,horarios);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater horarioInflater = LayoutInflater.from(getContext());
View costumView = horarioInflater.inflate(R.layout.costum_listview, parent, false);
String singleHorario = getItem(position);
TextView hora = (TextView) costumView.findViewById(R.id.Hora);
TextView nota = (TextView) costumView.findViewById(R.id.Nota);
hora.setText(singleHorario);
nota.setText(" ");
return costumView;
}
}
【问题讨论】:
-
请显示你的
costum_adapter构造函数。 -
你应该只使用数据库/contentProvider和游标适配器,不需要大数组
-
已经发布了构造函数 ChrisStillwell
-
我在 java 和 androidStudio 中有点新的编程,我不太确定你指的是什么。出血182
标签: java android arrays listview arraylist