【发布时间】:2013-11-06 16:05:13
【问题描述】:
在我的项目中,我有一个不同行的 SQLite 数据库。现在我有一个ListView,它显示了这个数据库的某些项目。这些列表项中仅显示行 name 和 city(代码名为 taskName 和 taskDate)。现在,当您单击它们时,我想显示这些项目的“详细信息”页面。因此,详细信息页面应包含/显示单击项目的所有行,而不仅仅是“名称”和“城市”。到目前为止,我已经这样做了,但是通过.getText() 在详细活动中仅显示名称和城市。
我用intent.putExtra() 得到了这两行,但我不知道如何显示其他行,因为我无法用.getText() 访问它们,因为它们没有显示在ListView 中。
这是我的ListAdapter 的代码(如果您需要更多代码,请告诉我):
public class ServiceAdapter extends ArrayAdapter<ServiceItem> {
private List<ServiceItem> taskList;
private Context context;
public ServiceAdapter(Context context, List<ServiceItem> listItems) {
super(context, R.id.listitem_taskitem, listItems);
this.context = context;
this.taskList = listItems;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.service_task_list, null);
}
ServiceItem task = taskList.get(position);
if (task != null) {
TextView taskName = (TextView) v.findViewById(R.id.task_name);
TextView taskDate = (TextView) v.findViewById(R.id.task_date);
taskName.setText(task.getCity());
taskDate.setText(task.getName());
}
return v;
}
}
这是目前为止的详细活动:
public class ServiceDetails extends Activity {
private TextView city;
private TextView name2;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setupUI();
Bundle extras = getIntent().getExtras();
String name = extras.getString("name").toString();
String description = extras.getString("description").toString();
city.setText(name);
name2.setText(description);
}
private void setupUI() {
setContentView(R.layout.activity_service_details);
city = (TextView) findViewById(R.id.detailName);
name2 = (TextView) findViewById(R.id.detailWww);
}
}
【问题讨论】:
-
您可以在注册
listviewadatper的地方发布您的主要活动吗?因为你必须从listview.setOnItemClickListener获取行信息
标签: android sqlite android-listview