0

我在我的main.xml. 每个片段连续运行单独的线程以绘制动态图。我有一个EditTextin main.xml. EditText输入键时键盘滞后。我正在使用 Android Plot graph jar。我的主线程 UI 似乎阻塞,请帮助。线程可以在片段中使用吗?

主要的.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white" >
<EditText
            android:id="@+id/name"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/white"
            android:textSize="22sp"
            android:hint="@string/name" />

<RelativeLayout
    android:id="@+id/Data"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/name" >

    <fragment
        android:id="@+id/FirstFragment"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:layout_marginTop="2dp"
        class="com.lnt.apms.activities.FirstFragmentActivity" />

    <fragment
        android:id="@+id/SecondFragment"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:layout_below="@id/FirstFragment"
        android:layout_marginTop="2dp"
        class="com.lnt.apms.activities.SecondFragmentActivity" />

    <fragment
        android:id="@+id/ThirdFragment"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:layout_below="@id/SecondFragment"
        android:layout_marginTop="2dp"
        class="com.lnt.apms.activities.ThirdFragmentActivity" />

    <fragment
        android:id="@+id/FourthFragment"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:layout_below="@id/ThirdFragment"
        android:layout_marginTop="2dp"
        class="com.lnt.apms.activities.FourthFragmentActivity" />

      </RelativeLayout>


</RelativeLayout>

片段活动.java

public class FragmentActivity extends Fragment{




  public FragmentActivity() {


}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.main, container, false);

    return view;
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

   plotGraph(.....);//function call


}



void plotGraph(final XYCoordinates Series1,final XYCoordinates Series2,final double[] tempEcg) {

    Thread thread = new Thread() {



        XYCoordinates seriesA = Series1;
        XYCoordinates seriesB = Series2;

        @Override
        public void run() {
            runFlag = true;

            try {

                while (runFlag) {

                    synchronized (seriesA) {

                      //code to process graph.


                        notifier.notifyObservers();//have defined this 
                    }

                    Thread.sleep(3);

                }

            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }

    };
    thread.start();


}

}

4

0 回答 0