在OnPostExecute中加载视图时,为什么图表平移和缩放失败?

时间:2015-08-21 05:50:39

标签: android android-asynctask zoom pinch

我开始构建一个应用程序,该应用程序应该使用图表c / o achartengine显示销量,其中包括"某些"成功。下载数据需要一段时间,并且屏幕只是变黑,但图表会在几秒钟后显示。在我了解ASYNCTASK之前就是这种情况。在OnPostEexecute中移动layout.addview之后,执行似乎更好地与android规则对齐,关于加载UI的时间过长。但奇怪的事情发生了,平移和缩放不再起作用了。我尝试了一些建议,例如addPanListener& addZoomListener无济于事。 mrender.setZoomEnabled(true,true),mrender.setPanEnabled(true,true)也是预定义的。会很感激如何解决这个问题。提前谢谢。

以下是代码:

public class ActivityTREND extends Activity {

ProgressDialog pDialog;


Spinner tedit3;
AutoCompleteTextView tedit1, tedit2;

public static String selReg, selStore, selDays;

String dregion, dstore, ddays;
String defReg="%";
String defStore="%";
int defDays=14;

String mode;

GraphicalView graphicalView1,graphicalView2;
GraphTrend pie1, bar2;

LinearLayout layout1,layout2;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_trend);

    // ALLOW VIOLATION OF THREAD POLICY
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    // FIX ORIENTATION TO PORTRAIT MODE
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);



    tedit1 = (AutoCompleteTextView) findViewById(R.id.trend_edit1);
    tedit2 = (AutoCompleteTextView) findViewById(R.id.trend_edit2);
    tedit3 = (Spinner) findViewById(R.id.trend_edit3);

    //AUTO-COMPLETE REGION
    String[] autoRegion = getResources().getStringArray(R.array.reggrp);

    ArrayAdapter<String> adapter =
            new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, autoRegion);

    tedit1.setAdapter(adapter);


    // AUTO-COMPLETE STORE
    String[] autoStore = getResources().getStringArray(R.array.stores);

    ArrayAdapter<String> adapter2 =
            new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, autoStore);
    tedit2.setAdapter(adapter2);




    ArrayAdapter<CharSequence> adapter3 =  ArrayAdapter.createFromResource(this, R.array.days, android.R.layout.simple_spinner_dropdown_item);
    adapter3.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);

    tedit3.setAdapter(adapter3);

    layout1 = (LinearLayout) findViewById(R.id.trend_graph1);
    layout2 = (LinearLayout) findViewById(R.id.trend_graph2);



// SHOW VOLUME GRAPHICALLY USING DECLARED CONSTANTS
    showVolume(null);

}



public void showVolume(View view){


    new Mytask().execute();


}


public void getVolume(View view) {


    dregion = "" + tedit1.getText().toString();
    if (dregion == null) {
        //String dstore = "" + tedit2.getSelectedItem().toString();
        dregion = "" + defReg;
        dstore = "" + defStore;
        ddays = "" + defDays;
    }else{
        dregion = "" + tedit1.getText().toString();
        dstore = "" + tedit2.getText().toString();
        ddays = "" + tedit3.getSelectedItem().toString();

    }

    selReg = "" + dregion;
    selStore = "" + dstore;
    selDays = "" + ddays;




    // PIE GRAPH
    //GraphTrend pie1 = new GraphTrend();
    pie1 = new GraphTrend();
    graphicalView1 = pie1.getPERprodgrpPIE(this);

    //layout1 = (LinearLayout) findViewById(R.id.trend_graph1);
    //layout1.removeAllViews();
    //layout1.addView(graphicalView1);


    // BAR GRAPH
    //GraphTrend bar2 = new GraphTrend();
    bar2 = new GraphTrend();
    //GraphicalView graphicalView2 = bar2.getPERprod(this);
    graphicalView2 = bar2.getPERprod(this);

    //layout2 = (LinearLayout) findViewById(R.id.trend_graph2);
    //layout2.removeAllViews();
    //layout2.addView(graphicalView2);



}





class Mytask extends AsyncTask<String,Void,Void> {

    @Override
    protected void onPreExecute() {


        // Showing progress dialog before making http request
        pDialog = new ProgressDialog(ActivityTREND.this);
        pDialog.setMessage("Downloading...");
        pDialog.show();


    }

    @Override
    public Void doInBackground(String... params) {


        Looper.prepare();

        getVolume(null);

        return null;
    }

    @Override
    protected void onProgressUpdate(Void... values) {
        super.onProgressUpdate(values);
    }

    @Override
    public void onPostExecute(Void aVoid) {


        layout1.removeAllViews();
        layout1.addView(graphicalView1);

        layout2.removeAllViews();
        layout2.addView(graphicalView2);


        pDialog.hide();
    }
}

0 个答案:

没有答案