现在,我正在对我的 android 模拟器进行强制关闭。
完成此应用程序后,我将要放入一个自定义字段而不是仅进行测试,但现在我只想从 http 活动中显示测试。
任何帮助都会很棒!
主要活动:
public class MainActivity extends Activity {
public final static String EXTRA_MESSAGE = "com.example.main.MESSAGE";
/*@SuppressLint("ParserError")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
private Button searchBtn;
@Override
protected void onCreate(Bundle savedInstance){
super.onCreate(savedInstance);
setContentView(R.layout.activity_main);
searchBtn = (Button) findViewById(R.id.button1);
searchBtn.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
Intent intent = new Intent(null, http.class);
startActivity(intent);
}
});
}
}
网址:
public class http extends Activity {
public http(){
httpMethod();
}
public void httpMethod(){
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://api.site.com/api/");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
;
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
String test = "hello";
TextView myTextView = (TextView) findViewById(R.id.myTextView);
myTextView.setText(test);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
}
显现:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.example.main.DisplayMessageActivity"/>
<activity android:name="com.example.main.http"/>
</application>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>