Android : update remaining time in childs of Expendable List View every second android

on Wednesday, March 18, 2015


**the code views the remaining time every second but no action has been done ..i can't collapse group , expand another group or click on child ..Please i need help :( **


in 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();

}
});


In 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)));}

0 comments:

Post a Comment