【问题标题】:Android SQLite display item "details"Android SQLite 显示项“详细信息”
【发布时间】:2013-11-06 16:05:13
【问题描述】:

在我的项目中,我有一个不同行的 SQLite 数据库。现在我有一个ListView,它显示了这个数据库的某些项目。这些列表项中仅显示行 namecity(代码名为 taskNametaskDate)。现在,当您单击它们时,我想显示这些项目的“详细信息”页面。因此,详细信息页面应包含/显示单击项目的所有行,而不仅仅是“名称”和“城市”。到目前为止,我已经这样做了,但是通过.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);
    }
}

【问题讨论】:

  • 您可以在注册listview adatper 的地方发布您的主要活动吗?因为你必须从listview.setOnItemClickListener获取行信息

标签: android sqlite android-listview


【解决方案1】:

我发现你不知道自己在做什么:P 您有一个提供给适配器的 ServiceItem 列表,您可以查看它。

当这些项目包含从数据库中获取的所有数据时,您可以将序列化对象或其所有数据传递给ServiceDetails 活动。

当这些项目仅包含有关名称和城市的信息时,您有 2 个选项:

  • 填写姓名和城市时填写此数据(不要太大)
  • 在 ServiceDetails 活动中,通过对象的名称/ID 或您可以获取的任何内容从数据库中获取对象。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-05
    • 2020-09-05
    • 2012-08-18
    • 1970-01-01
    • 1970-01-01
    • 2016-10-25
    • 1970-01-01
    相关资源
    最近更新 更多