Trying this again
I have this samplet of code it is not complete but it should get my point accross
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");
}
}
This snippet of code exists in the oncreate method
What I need to do is this
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");
}
}
Will this work exactly as is or do I need to do something additional in the () following the function name myNewFunction. Is the snippet ‘Bundle savedInstanceState’ in the oncreate method needed in myNewFunction syntax or not.
What you have should be just fine. You would only need to define the myNewFunction method to take a Bundle if you need to reference it in that method. Based upon your example, you currently do not need it in the myNewFunction method.
But unless you need to call the myNewFunction method outside of your MainActivity, I would personally make it private.