0

在我的应用程序中,我在纵向模式下使用gridview 时显示一列。在横向模式下,新布局定义为显示 2 列。

这就是应用程序的工作原理。当应用程序启动时,会调用进度对话框从 sqlite 数据库加载网站名称,并使用异步从 sqlite db 加载网站。网格视图膨胀后,进度对话框将被关闭。

现在将网站名称加载到 gridview 后,屏幕方向会发生变化,它会重新启动进度对话框

我知道在屏幕方向改变 ondestroy() 然后 oncreate() 被调用。

这是我的应用程序的 src 代码。

public class RSSReaderActivity extends Activity {

    private ProgressDialog pDialog;
    ArrayList<HashMap<String, String>> rssFeedList;
    RSSParser rssParser = new RSSParser();
    RSSFeed rssFeed;
    Button add_rss;
    // array to trace sqlite ids
    String[] sqliteIds;
    public static String TAG_ID = "id";
    public static String TAG_TITLE = "title";
    public static String TAG_LINK = "link";
        GridView gridview;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.site_list);

        add_rss = (Button) findViewById(R.id.add_rss);
        gridview = (GridView) findViewById(R.id.gridview);
        rssFeedList = new ArrayList<HashMap<String, String>>();

        new loadStoreSites().execute();
        gridview.setOnItemClickListener(new OnItemClickListener() {
        ...
        ...
        );

        add_rss.setOnClickListener(new View.OnClickListener() {
            ...
            ...
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        // if result code 100
        if (resultCode == 100) {
            // reload this screen again
            Intent intent = getIntent();
            finish();
            startActivity(intent);
        }
    }
    class loadStoreSites extends AsyncTask<String, String, String> {
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            ...
            ...
        }
        @Override
        protected String doInBackground(String... args) {
            // updating UI from Background Thread
            runOnUiThread(new Runnable() {
                public void run() {
                    RSSDatabaseHandler rssDb = new RSSDatabaseHandler(getApplicationContext());

                    // listing all websites from SQLite
                    List<WebSite> siteList = rssDb.getAllSites();

                    sqliteIds = new String[siteList.size()];

                    // loop through each website
                    for (int i = 0; i < siteList.size(); i++) {

                        WebSite s = siteList.get(i);

                        // creating new HashMap
                        HashMap<String, String> map = new HashMap<String, String>();

                        // adding each child node to HashMap key => value
                        map.put(TAG_ID, s.getId().toString());
                        map.put(TAG_TITLE, s.getTitle());
                        map.put(TAG_LINK, s.getLink());

                        // adding HashList to ArrayList
                        rssFeedList.add(map);

                        // add sqlite id to array
                        // used when deleting a website from sqlite
                        sqliteIds[i] = s.getId().toString();
                    }
                    gridview.setAdapter(new SimpleAdapter(RSSReaderActivity.this,rssFeedList, R.layout.site_list_row,new String[] { TAG_ID, TAG_TITLE, TAG_LINK },new int[] { R.id.sqlite_id, R.id.title, R.id.link }));
                    registerForContextMenu(gridview);
                }
            });
            return null;
        }

        protected void onPostExecute(String args) {
            // dismiss the dialog after getting all products
            pDialog.dismiss();
        }

        }
      }

那么我们如何在这里使用 onsavedinstance() ..请任何人指导我。

4

1 回答 1

2

将此添加到清单文件中

  android:configChanges="keyboardHidden|orientation|screenSize"
于 2013-08-29T10:05:04.283 回答