【问题标题】:Listview adding 2 elements from JSoupListview 从 JSoup 添加 2 个元素
【发布时间】:2011-10-22 20:43:58
【问题描述】:

我有 2 个元素标签,我想将它们添加到列表视图的 2 个编辑文本中。 我该怎么做?

String[] from = new String[] {"col_1", "col_2"};
int[] to = new int[] { R.id.editText1, R.id.editText2 };

List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map;

Document doc = Jsoup.parse(test);
Elements tdsFromSecondColumn = doc.select("td:eq(0)"); 
Elements tdsFromSecondColumn1 = doc.select("td:eq(1)");

for (Element tdFromSecondColumn: tdsFromSecondColumn) {
     map = new HashMap<String, String>();
     map.put("col_1", tdFromSecondColumn.text()); 
     map.put("col_2", ?????);
     fillMaps.add(map);

SimpleAdapter adapter = new SimpleAdapter(AndroidLogin.this, fillMaps, R.layout.test, from, to);
kp.setAdapter(adapter);

【问题讨论】:

    标签: android android-listview jsoup


    【解决方案1】:

    为此,我建议您为您的 ListView 创建自定义适配器。

    你知道我为什么建议创建一个自定义适配器吗?仅仅因为它的一次实践,一次你做得很好,那么它将在未来对任何类型的 ListView 有用。

    要为 ListView 创建自定义适配器,请按照以下步骤操作:

    1. 创建一个列表视图行 xml 文件(对于您的情况,它将仅包含 2 个 EditText)。
    2. 现在定义一个自定义适配器类(并扩展 BaseAdapter)并扩展上述列表视图行文件。并且您需要重写 getView() 方法以将所需的值放入 EditText 框中。
    3. 创建此自定义适配器类的对象并将其设置在 ListView 中。

    【讨论】:

    • 嗨 Paresh,嗯好的,我创建了 listview 行 xml 文件。您能否提供有关第 2 点和第 3 点的更多详细信息?也许是一个例子?谢谢。
    • 我希望你能正确理解我的回答,这里有一堆关于 ListView 的文章:goo.gl/00Jhi,我尽力学习这个例子,正如我之前告诉你的那样,创建自定义适配器是一次练习所以请仔细阅读
    • 嗨,Paresh,我想我会深入研究它,看起来并不像我想的那么难 ;)
    • @Lars 并不难,正如我之前所说,创建自定义适配器只是 1 次练习,然后您可以在稍作更改后为 GridView 使用相同的适配器。
    • 我已经应用了一些代码并且运行成功。我只有正确填写列表视图的问题。如果您有兴趣,请参阅:stackoverflow.com/questions/7881884/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-13
    • 1970-01-01
    • 1970-01-01
    • 2015-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多