如何在Custom ListView中显示数据

时间:2014-09-10 07:16:17

标签: android android-listview

我在第二个自定义textview中创建了两个editText和一个ListView,我想在我的自定义listView中逐个设置值名称,比率,数量已经显示在Toast上,我还有第一个listView,它有5个值,我必须在按钮listView事件上的第二个自定义onClick()上显示..

    int count = lisView1.getAdapter().getCount();
    for(int i=0;i<count;i++)
    {
    LinearLayout itemLayout = (LinearLayout)lisView1.getChildAt(i); // Find by under       LinearLayout
    TextView itemname = (TextView)itemLayout.findViewById(R.id.nm);
    TextView rat = (TextView)itemLayout.findViewById(R.id.rat);
    EditText quan = (EditText)itemLayout.findViewById(R.id.txtInput);
    String     rate = rat.getText().toString();
    String  quant = quan.getText().toString();
    String     name = itemname.getText().toString();
    Toast.makeText(Mmnue.this,name + ", " + rate+ " , " +quant   ,Toast.LENGTH_LONG).show(); 


    }

1 个答案:

答案 0 :(得分:2)

你不能使用for循环。

您需要使用 getView(int position, View convertView, ViewGroup parent)

我建议您阅读ListView中有关自定义适配器的一些教程。

This stackoverflow post 非常简单。易于理解。

this tutorial 应该可以帮助您使用ListViews。