1

我有一个 Asynctask,它应该使用 onProgressUpdate 将 Rowlayout 添加到 Scrollingview 内的 Tablelayout。在 Asynctask 工作期间,行被添加到 tablelayout 并且一切都很好。但是在 Asynctask 工作期间,尽管我看到添加的行,但我无法滚动 Scrollview。如果 Asynctask 完成,我只能滚动。

异步任务

  private class DownloadWebPageTask extends AsyncTask<Integer, String, String> 
  {
    @Override
    protected String doInBackground(Integer... params) {        
        Integer k = 0;
        for(int i = 0; i < 100; i++)
        {
            if(i == 80)
            {
                System.out.println("Debug Breakpoint");
            }
            publishProgress("hey");
        }       
        return k.toString();
    }
    @Override
    protected void onProgressUpdate(String... ProduktListe)
    {
        writeSomeThing();
    }
    @Override
    protected void onPostExecute(String result) 
    {             

    }   
  }

创建行

  public void writeSomeThing() 
  {     
            //make here breakpoint
            MainActivity context = this;


            TableLayout searchBody = (TableLayout) context.findViewById(R.id.tableLayout);

            LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);

            TableRow rowView = (TableRow)inflater.inflate(R.layout.reintuding, null);

            searchBody.addView(rowView);    
  }

main_activity.xml

<?xml version="1.0" encoding="utf-8"?>

    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/Gesamt"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#0099cc" >

        <ScrollView
            android:id="@+id/scroll"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:fadingEdge="vertical"
            android:minHeight="610dp">

            <TableLayout
                android:id="@+id/tableLayout"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:fitsSystemWindows="true"
                android:stretchColumns="0" >

            </TableLayout>


        </ScrollView>

    </RelativeLayout>

reintuding.xml

<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="button" />

</TableRow>
4

0 回答 0