再试一次
我有这个代码示例,它不完整,但它应该让我的观点跨越
public class MainActivity extends Activity {
ListView list1;
LazyAdapter adapter;
String nUdid;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
final Context context = this;
setContentView(R.layout.main);
TextView viewtitle1 = (TextView) findViewById(R.id.textView1);
JSONObject j = new JSONObject();
try {
j.put("action", "udid_get_products");
j.put("success", "true");
j.put("content", "udid product list");
j.put("data", nUdid);
} catch (JSONException e1) {
e1.printStackTrace();
}
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.xxxxxxxxx.com/yyyy/test.php");
}
}
这段代码存在于 oncreate 方法中
我需要做的是这个
public class MainActivity extends Activity {
ListView list1;
LazyAdapter adapter;
String nUdid;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
myNewFunction();
}
public void myNewFunction() {
final Context context = this;
TextView viewtitle1 = (TextView) findViewById(R.id.textView1);
JSONObject j = new JSONObject();
try {
j.put("action", "udid_get_products");
j.put("success", "true");
j.put("content", "udid product list");
j.put("data", nUdid);
} catch (JSONException e1) {
e1.printStackTrace();
}
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.xxxxxxxxx.com/yyyy/test.php");
}
}
这会完全按原样工作还是我需要在函数名 myNewFunction 后面的 () 中做一些额外的事情。myNewFunction 语法中是否需要 oncreate 方法中的片段“Bundle savedInstanceState”。