更新可扩展列表的子节点的剩余时间查看每秒android

时间:2015-03-18 14:26:31

标签: android

**代码每秒查看剩余时间但未执行任何操作..我无法折叠组,展开另一组或点击儿童..请给我帮助:( **

Profile Fragment中的

expListView.setOnGroupExpandListener(new OnGroupExpandListener() {    
     @Override
     public void onGroupExpand(final int groupPosition) {
        // notify=true;
        SharedPreferences prefs = rootview.getContext().getSharedPreferences("QuranerUser", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = prefs.edit();
        editor.putInt("center_pos", groupPosition);
        editor.putString("centerid", result.get(0).get(0).get(0).get(groupPosition));
        editor.commit();

        LayoutInflater infalInflater = (LayoutInflater) rootview.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = infalInflater.inflate(R.layout.list_item, null);
        final TextView newtime=(TextView)view.findViewById(R.id.rtime);

        LayoutInflater infalInflater2 = (LayoutInflater)  rootview.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater2.inflate(R.layout.list_group, null);


        m_Runnable = new Runnable() {
            public void run() {                    
                for(int i=0;i<re_result.get(groupPosition).size();i++){                          
                      r_t=Long.parseLong(re_result.get(groupPosition).get(i));
                      r_t=r_t-1;
                      if(r_t>0){
                        re_result.get(groupPosition).set(i, Long.toString(r_t));
                        listAdapter.notifyDataSetChanged();                                 
                        ExpandableListAdapter.formate_Remainig(re_result.get(groupPosition).get(i)));
                        //  resetDataCell(v);

                        }
                        // update every second                    
                }

                m_Handler.postDelayed(m_Runnable, 1000);
            }}; 

         Toast.makeText(getActivity(),
                 listDataHeader.get(groupPosition) + " Expanded",
                 Toast.LENGTH_SHORT).show();
     }
    });


 // Listview Group collasped listener
 expListView.setOnGroupCollapseListener(new OnGroupCollapseListener() {

     @Override
     public void onGroupCollapse(int groupPosition) {
         notify=false;
           Toast.makeText(getActivity(),
                 listDataHeader.get(groupPosition) + " Collapsed",
                 Toast.LENGTH_SHORT).show();

     }
 });

在ExpandableListAdapter中:

final TextView newtime=(TextView)view.findViewById(R.id.rtime);
final Thread testthread = new Thread() {
    @Override
    public void run() {
        android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);       
        try {
            while(true) {
                sleep(1000);
                MyProfileFragment.m_Handler.post(MyProfileFragment.m_Runnable);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
};

testthread.start();

newtime.setText(formate_Remainig(Rem.get(groupPosition).get(childPosition)));
time_schedule=Start_time(Long.parseLong(EN.get(groupPosition).get(childPosition)),Long.parseLong(ST.get(groupPosition).get(childPosition)),Integer.parseInt(offset.get(groupPosition).get(childPosition)));

String check = check_time(Long.parseLong(EN.get(groupPosition).get(childPosition)), Long.parseLong(ST.get(groupPosition).get(childPosition)),Days.get(groupPosition).get(childPosition));

if(check.equalsIgnoreCase("time")){
    newtime.setVisibility(TextView.VISIBLE);
    newtime.setText(formate_Remainig(Rem.get(groupPosition).get(childPosition)));}

1 个答案:

答案 0 :(得分:0)

如何使用 AsyncTask

我在listview中创建了每行的进度条

listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
      public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
download(view);}
}
);

void download{
  TextView tvTitle = (TextView) view.findViewById(R.id.tvTitle);
//use async task to update it
}