Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 列出数组查看TextView中的所有条目_Android - Fatal编程技术网

Android 列出数组查看TextView中的所有条目

Android 列出数组查看TextView中的所有条目,android,Android,我有一个ArrayList,它以字符串的形式从DB中获取所有条目 List<Amthal> amthal = getAmthalSetFromDb(p); 我想通过单击“下一步”按钮移动到下一步,在TextView中逐个查看这些字符串 我试图查看该数组列表中的任何字符串,但出现了一个错误…“get(I-1)”,它必须返回该数组中的最后一个字符串 tv.setText(amthal.get(i-1)); 我的问题是如何检索和查看这些字符串?我应该将其转换为字符串数组还是什么

我有一个ArrayList,它以字符串的形式从DB中获取所有条目

List<Amthal> amthal = getAmthalSetFromDb(p);
我想通过单击“下一步”按钮移动到下一步,在TextView中逐个查看这些字符串

我试图查看该数组列表中的任何字符串,但出现了一个错误…“get(I-1)”,它必须返回该数组中的最后一个字符串

    tv.setText(amthal.get(i-1));

我的问题是如何检索和查看这些字符串?我应该将其转换为字符串数组还是什么???

您可以使用计数器变量来解决问题,如下所示:

public static int count=0;  //Declare it as class level varaible
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++;  // increase counter here
         }
         else{
            //Reset counter to 0
          }
    }
});
公共静态整数计数=0//将其声明为类级变量
yourbutton.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
如果(计数
请发布您收到的完整错误。在mobile com.example.com.testdb上进行测试时,它会显示在文本视图中。Amthal@40dcd678其中com.example.com.testdb是我的包名,Amthal是我数据库中的表,其中,当我单击next按钮时,字符串40dcd678会发生变化,似乎在ascci中显示它!表示数组列表包含错误的值。我想您需要检查从数据库检索到的ArrayList值是否正确我只尝试了“设置textView”,现在它工作正常,但当我尝试使用“下一步”按钮使用您的解决方案时,这里有一些警告“参数计数的非法修饰符;只允许使用final”,您在其中声明了计数变量?将其声明为类级变量而不是方法级变量
public static int count=0;  //Declare it as class level varaible
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++;  // increase counter here
         }
         else{
            //Reset counter to 0
          }
    }
});