Custom View Async Task
<pre><code>ublic class SectionsList extends LinearLayout implements OnOffChangeListener,OnClickListener,MessageListener{

private Context mContext;
private Dialog dialog;
private List&lt;TextView&gt; tList = new ArrayList&lt;TextView&gt;();
private List&lt;EditValueButton&gt; editList = new ArrayList&lt;EditValueButton&gt;();
private List&lt;OnOffButton&gt; onOffList = new ArrayList&lt;OnOffButton&gt;();
private List&lt;String&gt; sectionNames = NewsReader.getInstance().getSectionNamesListWithFunStories();
private final int ChangeBannerDeliveryBetweenTimeDialog_ID = 1;
private final int ChangeBannerDeliveryBetweenDateTimeDialog_ID = 2;
private Handler mHandler;
private EditValueButton editButton;
private long startTime;
private View setView;
private OnOffButton Id;
private Boolean sectionOn = false;
private Boolean setOff;
private Boolean checkSection = false;
private String activeSection;
private OnOffButton onOff;
private boolean cancel;
private TextView sectionName;
private TableLayout table;
private Resources resources;
private int textNormalColor;
private HashMap&lt;String, Time&gt; getSectiontime;
private HashMap&lt;String, Time&gt; hm = new HashMap&lt;String, Time&gt;();

@Override
public boolean handleMessage(Message msg) {
    boolean ret;
    Bundle  bundle = msg.getData();
    switch ( msg.what)
    {
    case Constants.message_SetBannerTime:
        startTime = bundle.getLong(Constants.KEY_ARG_1);
        setDisplayDuringLabel(startTime, setView);
        ret = true;
        break;
    case Constants.message_setOff:
        cancel = bundle.getBoolean(Constants.KEY_ARG_1);
        if(cancel){
        setOff();
        ret = true;
        break;
    }
    default:
    {
        ret = false;
        break;
    }
}
    return ret;
}

public SectionsList(Context context) {
    super(context);
    mContext = context;
    init(context, null);
}

public SectionsList(Context context, AttributeSet attrs) {
    super(context, attrs);
    mContext = context;
    init(context, attrs);
}


private void init(Context context,  AttributeSet attrs) {

    //new CustomTask().execute();

    Log.d("secnames", "section names" + sectionNames);
    getSectiontime = PersistedScheduledBannerStore.getInstance().getScheduledBanners();
    resources = context.getResources();
    textNormalColor = resources.getColor(R.color.app_button_normal_text_color);
    if(getSectiontime != null){hm = getSectiontime;}
    LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    layoutInflater.inflate(R.layout.sectiontable, this, true);
    table = (TableLayout) findViewById(R.id.mainTable);
    for(int i =0; i&lt; sectionNames.size();i++){
                TableRow tr = new TableRow(context);
                View line = new View(context);
                line.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 1));
                line.setBackgroundColor(textNormalColor);
                line.setPadding(0, 10, 0, 10);

                layoutInflater.inflate(R.layout.sectiontablerow, tr);
                table.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT));
                table.addView(line);

                setIds(tr);
                setTagstoViews(i);
                addViewstoList();
                setListeners();
                checkIfSectionIsOn(i);
                tList.get(i).setText("sai ram");
            }

}



private void loopThroughViews(Context context, LayoutInflater layoutInflater) {

}

private void checkIfSectionIsOn(int i) {
    if(getSectiontime.containsKey(sectionNames.get(i))){
        String key = sectionNames.get(i);
        Time value = getSectiontime.get(key);
        editList.get(i).setText(DateFormat.format("h:mm a", value).toString());
        onOff.setOn(true);  
    }else{
        editList.get(i).setText("-:-");
    }
}


public void onOffChanged(OnOffButton button, boolean isOn) {
    setView = button;

    if(isOn){
        sectionOn = true;
    }
    else if (!isOn){
        sectionOn = false;
        makeSectionActive(button);
        hm.remove(activeSection);
        getSectiontime.remove(activeSection);
    }
}


 protected Dialog onCreateDialog(int id) {
        switch (id) {
        case ChangeBannerDeliveryBetweenTimeDialog_ID:
        {
            long            curStartTime = 0;
            dialog = new ChangeBannerTimeDialog(getContext(), curStartTime, mHandler,0);                
            break;
        }
        case ChangeBannerDeliveryBetweenDateTimeDialog_ID:
        {
            long            curStartTime = 0;
            dialog = new ChangeBannerdateTimeDialog(getContext(), curStartTime, mHandler, 0);           
            break;
        }
        default:
            dialog = null;
    }
    return dialog;
}

private void setDisplayDuringLabel(long startTime, View v){
    changeTimeText(v, DateFormat.format("h:mm a", startTime).toString());
    Time time = new Time(startTime);
    if(sectionOn){
        hm.put(activeSection, time);
    }

}

@Override
public void onClick(View v) {
    setView = v;
    if(v.getId() == R.id.sectionOnOff){
        if(sectionOn){
            TextView tt = tList.get(Integer.parseInt(v.getTag().toString()));
            String secName = tt.getText().toString();
            showDateTimeDialogIfHoroscopes(secName);
            setOff = true;
            Id = onOffList.get(Integer.parseInt(v.getTag().toString()));
            Id.setOn(true);
            makeSectionActive(v);
        }
    }
    else if(v.getId() == R.id.editTime){
        setView = v;
        Id = onOffList.get(Integer.parseInt(v.getTag().toString()));
        if(Id.isOn()){
        TextView tt = tList.get(Integer.parseInt(v.getTag().toString()));
        String secName = tt.getText().toString();
        showDateTimeDialogIfHoroscopes(secName);
        setOff = false;
        Id.setOn(true);
        makeSectionActive(v);
        }
    }
}

private void showDateTimeDialogIfHoroscopes(String secName) {
    if(secName.equals("Horoscopes")){
        onCreateDialog(ChangeBannerDeliveryBetweenDateTimeDialog_ID).show();
    }else{
        onCreateDialog(ChangeBannerDeliveryBetweenTimeDialog_ID).show();
    }
}

private void setOff() {
    if(setOff){
        Id.setOn(false);
    }
    else if(!setOff){
        Id.setOn(true);
    }
}

private void setIds(TableRow tr){
    onOff = (OnOffButton) tr.findViewById(R.id.sectionOnOff);
    editButton = (EditValueButton) tr.findViewById(R.id.editTime);
    sectionName = (TextView) tr.findViewById(R.id.sectionName);
}

private void setTagstoViews(int i){
    onOff.setTag(""+i);
    editButton.setTag(""+i);
}
private void setListeners(){
    editButton.setOnClickListener(this);
    onOff.setOnOffChangeListener(this);
    onOff.setOnClickListener(this);
}


public HashMap&lt;String, Time&gt; getBannerSectionwithTime(){
    return hm;
}
private void addViewstoList(){
    onOffList.add(onOff);
    editList.add(editButton);
    tList.add(sectionName);
}

private void makeSectionActive(View v){
    TextView tt = tList.get(Integer.parseInt(v.getTag().toString()));
    activeSection = tt.getText().toString();
}

private void changeTimeText(View v, String text){
    EditValueButton tt = editList.get(Integer.parseInt(v.getTag().toString()));
    tt.setText(text);
}

public  boolean checkSectionOn(){
    return checkSection;
}   

private class CustomTask extends AsyncTask&lt;String, Void, Boolean&gt;{
    private ProgressDialog dialog;
    @Override
    protected void onPreExecute() {
        super.onPreExecute();

        dialog=ProgressDialog.show(getContext(), "", "Loading...");
    }

    @Override
    protected void onPostExecute(Boolean result) {
        super.onPostExecute(result);
        dialog.dismiss();
    }

    @Override
    protected Boolean doInBackground(String... params) {
        return null;
    }

}
</code></pre>

<p>}</p>

<p>I want to use Async task to put all Ui in postexecute and loops in doinbackground?
In loop i have my table row which consumens 5secs to 8sec to load so can we somehow add the loop in do in background? Any help would be appreciated. Please provide code sample for better understanding</p>
