如何从ListView中的位置int获取TextView的值?

问题描述:

我有一个Button,点击时会执行一个addQty方法,在这个方法中,我需要在按下Button的同一行上设置一个TextView的值。我有position整数可用于我,但我不能解决如何获得TextView。 我有一个自定义ArrayAdapter这台本的getView方法:如何从ListView中的位置int获取TextView的值?

ImageButton plus = (ImageButton) v.findViewById(R.id.qtyPlus); 
plus.setTag(position); 

我的布局,然后执行以下操作:

<ImageButton 
    android:id="@+id/qtyPlus" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/plus" 
    android:onClick="addQty" /> 

addQty方法:

public void addQty(View v) { 
     int position = Integer.parseInt(v.getTag().toString()); 

     Item tmp = (Item)adapter.getItem(position); 
     Log.d("MyApp",tmp.getName()); 

} 

这个工程,我我能够获得列表中单击行的项目对象,但我现在如何设置TextViewListView排?

+0

我不明白这个问题。你能否正确地格式化它?你的要求是什么?根据平铺您需要textview中存在于特定位置的值。每个适配器将连接一个集合对象,其中包含每行的完整信息。您可以通过使用该集合对象将数据获取到任何行位置。 – Pavandroid 2012-03-25 10:20:30

你不设置直接在列表行新TextView值,而不是你用新的值更新Item元素,然后调用notifyDataSetChanged()(适配器对象)来通知你修改的东西适配器,它应该更新ListView

+0

谢谢。这是完美的。 – 2012-03-25 10:19:21