【问题标题】:How to clear the all values from class list and int values in android?如何从android中的类列表和int值中清除所有值?
【发布时间】:2014-09-09 08:51:52
【问题描述】:

我在其中创建了一个类,我使用了一个 arraylist hashmap 和 int 计数器变量 如果我想从这个类中清除所有值意味着类变量没有任何值。这里我向你展示我是如何将值存储在列表和计数器变量中的。

我想清除循环类变量中的所有值。

Roundlooping.java

public class Roundlooping {

    ArrayList<HashMap<String, String>> list;
    int counter;

}

Mainactivity.java

Roundlooping rl = new Roundlooping();
ArrayList<HashMap<String, String>> odata = new ArrayList<HashMap<String,String>>();
ArrayList<Roundlooping> data = new ArrayList<Roundlooping>();

 if (cursor.moveToFirst()) 
 {
     do 
     {
         HashMap<String, String> map = new HashMap<String, String>();
         map.put(DB_Constant.MYFILES.FILE_TIMERFROM, cursor.getString(cursor.getColumnIndex(DB_Constant.MYFILES.FILE_TIMERFROM)));
         map.put(DB_Constant.MYFILES.FILE_TIMERTO, cursor.getString(cursor.getColumnIndex(DB_Constant.MYFILES.FILE_TIMERTO)));
         map.put(DB_Constant.MYFILES.FILE_STUDIOFORMAT, cursor.getString(cursor.getColumnIndex(DB_Constant.MYFILES.FILE_STUDIOFORMAT)));
         odata.add(map);
         rl.list=odata;
        if(odata.size()>5)
        {
             rl.counter=odata.size();
             data.add(rl);
        }
        else
        {   
            rl.counter=0; 
            data.add(rl);
        }

   } while (cursor.moveToNext());

}

【问题讨论】:

    标签: android class variables


    【解决方案1】:

    首先你要使用访问器和修改器

    public class Roundlooping {
    
      private  ArrayList<HashMap<String, String>> list;
      private  int counter;
    
      public void setList(ArrayList<HashMap<String,String>> list){
        this.list = list;
    
      }
    
      public ArrayList<HashMap<String,String>> getList(){
        return list;
      }
    
      public void setCounter(int counter){
        this.counter = counter;
      }
    
      public int getCounter(){
        return counter;
      }
    }
    

    要清除值只需调用counterlist的set方法

    Roundlooping rl = new Roundlooping();
    rl.setList(null); or rl.setList(new ArrayList<Hashmap<String,String>>());
    rl.setCounter(0);
    

    【讨论】:

    • 但这是清除所有值或特定位置值我需要清除所有值
    猜你喜欢
    • 1970-01-01
    • 2016-08-31
    • 2010-12-09
    • 2014-06-28
    • 2017-03-13
    • 2011-03-10
    • 1970-01-01
    • 2014-09-24
    • 2010-11-12
    相关资源
    最近更新 更多