请高手来帮我看看我的问题啊
我的ArrayList中从DB中获取字符串
List<Amthal> amthal = getAmthalSetFromDb(p);
我能得知包含字符串的数量
int i= amthal.size();
我想实现的是在TextView中查看这些字符串,通过逐条点击,
用tv.setText(amthal.get(i-1));
返回了一个错误。
能不能将这些字符串转换,然后可以获取查看的?
first Amthal need implement toString, otherwise will return hash string.
second tv.setText(amthal.get(i-1).toString());
用计数器变量应该可以解决,试试:
public static int count=0; //声明类级变量
yourbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(count < amthal.size())
{
tv.setText(amthal.get(count).toString()); //set textView Text here
count++; // 增加计数器
}
else{
//重置计数器为0
}
}
});