0

私がやろうとしているのは、子タブからアクセスできるJSONObjectを用意して、情報を入力できるようにすることだけです。

 public class Example extends TabActivity{
            private JSONObject testtt = new JSONObject();
        public void writeJSON(String key, String value) throws JSONException {
         testtt.put(key, value);
         }
        public String getJSON(){
            return testtt.toString();
        }
     public void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);
            setContentView(R.layout.example);
                    //Creating the tabs and everything
                    //Is Here
     }
    }

タブの1つを前後にナビゲートするよりも、次へ/前へのボタンがあります。

public void onClick(View v) {
 //Pre-alertDialog.setmessage stuff here.
   alertDialog.setMessage(Example.this.getJSON());
// Example.this gives this error: No enclosing instance of the type Example is accessible in scope
}

私はたくさんの代替手段を試し、助けを求めるところまで来ました(私にとっては非常にまれです)。また、私がAndroid開発に比較的慣れていないこともおそらく明らかです。

編集:Class extendsApplication{を介してグローバル変数を試行する場合 logcat編集

4

1 に答える 1

1

最も簡単なのは、 Applicationオブジェクトを使用することです。JSON を Application オブジェクトの共有変数に貼り付け、そこから他のアクティビティでアクセスします。

于 2012-04-19T20:47:30.273 に答える