當前位置:首頁 » 安卓系統 » androidviewpost

androidviewpost

發布時間: 2022-04-23 07:42:40

㈠ android webview中的loadUrl方法是get請求還是post請求

我寫過的一般是get請求 因為一般這個loadUrl就是請求的完整地址 如果其實也很容易看 ,請求的時候介面端給你的介面是拼接了參數 的是get 請求 如果沒有拼接參數的話 可以是get也可以是post 這個咨詢下你們的寫介面的那個人也可以的 ,

㈡ 怎樣實現android http-post方法實例說明

代碼如下:

package com.hl;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class SimplePOST extends Activity {
private TextView show;
private EditText txt;
private Button btn;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
show = (TextView)findViewById(R.id.show);
txt = (EditText)findViewById(R.id.txt);
btn = (Button)findViewById(R.id.btn);
btn.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
dopost(txt.getText().toString());

}
});
}

private void dopost(String val){
//封裝數據
Map<String, String> parmas = new HashMap<String, String>();
parmas.put("name", val);

DefaultHttpClient client = new DefaultHttpClient();//http客戶端
HttpPost httpPost = new HttpPost("http://mhycoe.com/test/post.php");

ArrayList<BasicNameValuePair> pairs = new ArrayList<BasicNameValuePair>();
if(parmas != null){
Set<String> keys = parmas.keySet();
for(Iterator<String> i = keys.iterator(); i.hasNext();) {
String key = (String)i.next();
pairs.add(new BasicNameValuePair(key, parmas.get(key)));
}
}

try {
UrlEncodedFormEntity p_entity = new UrlEncodedFormEntity(pairs, "utf-8");
/*
* 將POST數據放入HTTP請求
*/
httpPost.setEntity(p_entity);
/*
* 發出實際的HTTP POST請求
*/
HttpResponse response = client.execute(httpPost);
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
String returnConnection = convertStreamToString(content);
show.setText(returnConnection);
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

}

private String convertStreamToString(InputStream is) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
}

㈢ android httppost類在哪

雖然在登錄系統中使用了Web Service與服務端進行交互。但是在傳遞大量的數量時,Web Service顯得有些笨拙。在本節將介紹移動電子相冊中使用的另外一種與資料庫交互的方法。直接發送HTTP GET或POST請求。這就要用到HttpGet、HttpPost以及HttpURLConnection這些類。
15.3.1 HttpGet類和HttpPost類
本節將介紹Android SDK集成的Apache HttpClient模塊。要注意的是,這里的Apache HttpClient模塊是HttpClient 4.0(org.apache.http.*),而不是Jakarta Commons HttpClient 3.x(org.apache.commons.httpclient.*)。
在HttpClient模塊中用到了兩個重要的類:HttpGet和HttpPost。這兩個類分別用來提交HTTP GET和HTTP POST請求。為了測試本節的例子,需要先編寫一個Servlet程序,用來接收HTTP GET和HTTP POST請求。讀者也可以使用其他服務端的資源來測試本節的例子。
假設192.168.17.81是本機的IP,客戶端可以通過如下的URL來訪問服務端的資源:
http://192.168.17.81:8080/querybooks/QueryServlet?bookname=開發
在這里bookname是QueryServlet的請求參數,表示圖書名,通過該參數來查詢圖書信息。
現在我們要通過HttpGet和HttpPost類向QueryServlet提交請求信息,並將返回結果顯示在TextView組件中。
無論是使用HttpGet,還是使用HttpPost,都必須通過如下3步來訪問HTTP資源。
1.創建HttpGet或HttpPost對象,將要請求的URL通過構造方法傳入HttpGet或HttpPost對象。
2.使用DefaultHttpClient類的execute方法發送HTTP GET或HTTP POST請求,並返回HttpResponse對象。
3.通過HttpResponse介面的getEntity方法返回響應信息,並進行相應的處理。

㈣ 如何在android程序中執行adb shell命令

在android程序中執行adb shell命令:

package net.gimite.nativeexe;

import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import net.gimite.nativeexe.R;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;

public class MainActivity extends Activity {

private TextView outputView;
private Button localRunButton;
private EditText localPathEdit;
private Handler handler = new Handler();
private EditText urlEdit;
private Button remoteRunButton;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

outputView = (TextView)findViewById(R.id.outputView);
localPathEdit = (EditText)findViewById(R.id.localPathEdit);
localRunButton = (Button)findViewById(R.id.localRunButton);
localRunButton.setOnClickListener(onLocalRunButtonClick);


}

private OnClickListener onLocalRunButtonClick = new OnClickListener() {
public void onClick(View v) {
String output = exec(localPathEdit.getText().toString());
output(output);
// try {
//
// // Process process = Runtime.getRuntime().exec(localPathEdit.getText().toString());
//
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
}
};


// Executes UNIX command.
private String exec(String command) {
try {
Process process = Runtime.getRuntime().exec(command);
BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
int read;
char[] buffer = new char[4096];
StringBuffer output = new StringBuffer();
while ((read = reader.read(buffer)) > 0) {
output.append(buffer, 0, read);
}
reader.close();
process.waitFor();
return output.toString();
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}

private void download(String urlStr, String localPath) {
try {
URL url = new URL(urlStr);
HttpURLConnection urlconn = (HttpURLConnection)url.openConnection();
urlconn.setRequestMethod("GET");
urlconn.setInstanceFollowRedirects(true);
urlconn.connect();
InputStream in = urlconn.getInputStream();
FileOutputStream out = new FileOutputStream(localPath);
int read;
byte[] buffer = new byte[4096];
while ((read = in.read(buffer)) > 0) {
out.write(buffer, 0, read);
}
out.close();
in.close();
urlconn.disconnect();
} catch (MalformedURLException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

private void output(final String str) {
Runnable proc = new Runnable() {
public void run() {
outputView.setText(str);
}
};
handler.post(proc);
}

}

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

效果圖:

㈤ Android view.post(runnable)方法不理解,請幫助解釋,謝謝!

樓主 你要明白 textview 和 button 都屬於view 其實這個方法 只要是個view都可以 不僅 這兩個 還包括 imageview之類的都可以

㈥ JS怎樣調用Android本地原生方法

在android中調用本地js文件里的方法並得到返回值其方法如下:

Android中內置了WebKit模塊,而該模塊的Java層視圖類就是WebView,所有需要使用Web瀏覽器功能的Android都需要創建該視圖類對象顯示和處理請求的網路資源。目前WebKit支持Http、Https、Ftp和JavaScript請求。下面是在Android中調用JavaScript方法以及如何在js中調用本地方法。

1、在Assets下放一個簡單的html文件jstest.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html40/strict.dtd">
<HTML>
<HEAD>
<meta name="viewport" content="width=device-width, target-densitydpi=device-dpi" />
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script>
function showMsg(){
alert("hello world!");
}
function showMsgInAndroid(){
myjs.showMsg('hello in android!');
}
</script>
</HEAD>
<BODY>
<span>測試js使用</span>

<button id='btntest' onclick='showMsgInAndroid()'>調用android方法</button>
</BODY>
</HTML>
2、布局文件main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/rl_main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<WebView
android:id="@+id/wv_test"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/btn_showmsg"/>
<Button
android:id="@+id/btn_showmsg"
android:layout_width="200dip"
android:layout_height="40dip"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="調用html中js方法"/>
</RelativeLayout>

3、然後是Activity,MainActivity.java
package com.harold.jstest;

import com.harold.base.JSKit;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.Button;

public class MainActivity extends Activity {

private WebView mWebView;
private Button btnShowInfo;
private JSKit js;
private Handler mHandler = new Handler();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//初始化控制項
mWebView = (WebView) findViewById(R.id.wv_test);
btnShowInfo = (Button) findViewById(R.id.btn_showmsg);
//實例化js對象
js = new JSKit(this);
//設置參數
mWebView.getSettings().setBuiltInZoomControls(true);
//內容的渲染需要webviewChromClient去實現,設置webviewChromClient基類,解決js中alert不彈出的問題和其他內容渲染問題
mWebView.setWebChromeClient(new WebChromeClient());
mWebView.getSettings().setJavaScriptEnabled(true);
//把js綁定到全局的myjs上,myjs的作用域是全局的,初始化後可隨處使用
mWebView.addJavascriptInterface(js, "myjs");

mWebView.loadUrl("file:///android_asset/jstest.html");

btnShowInfo.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
mHandler.post(new Runnable() {
@Override
public void run() {
//調用 HTML 中的javaScript 函數
mWebView.loadUrl("javascript:showMsg()");
}
});
}
});
}

}

4、最後是綁定全局js的類JSKit.java
package com.harold.base;

import android.widget.Toast;

import com.harold.jstest.MainActivity;

public class JSKit {
private MainActivity ma;

public JSKit(MainActivity context) {
this.ma = context;
}

public void showMsg(String msg) {
Toast.makeText(ma, msg, Toast.LENGTH_SHORT).show();
}
}

例子比較簡單,代碼里都加了注釋,這里就不多說了,本示例用的本地的html,如果訪問網路中的網頁,別忘記在AndroidManifest.xml中加許可權
<uses-permission android:name="android.permission.INTERNET"/>

㈦ android 怎麼在oncreate中獲得view的坐標

這個問題大家肯定遇到過不止一次,其實很簡單,解決它也很容易,但是咱們追求的畢竟不是解決它,而是找到幾種方法去解決,並且這么解決的原理是什麼。
這里列出4種解決方案:
Activity/View#onWindowFocusChanged
這個函數的含義是:view已經初始化完畢了,寬/高已經准備好了,這個時候去獲取寬高是可以成功獲取的。但是需要注意的是onWindowFocusChanged函數會被調用多次,當Activity的窗口得到焦點和失去焦點時均會被調用一次,如果頻繁地進行onResume和onPause,那麼onWindowFocusChanged也會被頻繁地調用。
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
L.i("onWindowFocusChanged : v_view1.getWidth():" + v_view1.getWidth()
+ " v_view1.getHeight():" + v_view1.getHeight());
}123456

view.post(runnable)
通過post可以將一個runnable投遞到消息隊列的尾部,然後等待UI線程Looper調用此runnable的時候,view也已經初始化好了。
v_view1.post(new Runnable() {
@Override
public void run() {
L.i("post(Runnable) : v_view1.getWidth():" + v_view1.getWidth()
+ " v_view1.getHeight():" + v_view1.getHeight());
}
});1234567

ViewTreeObserver
使用ViewTreeObserver的眾多回調可以完成這個功能,比如使用OnGlobalLayoutListener這個介面,當view樹的狀態發生改變或者view樹內部的view的可見性發生改變時,onGlobalLayout方法將被回調,因此這是獲取view的寬高一個很好的時機。需要注意的是,伴隨著view樹的狀態改變等,onGlobalLayout會被調用多次。
v_view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
L.i("ViewTreeObserver : v_view1.getWidth():" + v_view1.getWidth()
+ " v_view1.getHeight():" + v_view1.getHeight());
}
});1234567

再來詳細介紹一下ViewTreeObserver這個類,這個類是用來注冊當view tree全局狀態改變時的回調監聽器,這些全局事件包括很多,比如整個view tree視圖的布局,視圖繪制的開始,點擊事件的改變等等。還有千萬不要在應用程序中實例化ViewTreeObserver對象,因為該對象僅是由視圖提供的。
ViewTreeObserver類提供了幾個相關函數用來添加view tree的相關監聽器:
public void addOnDrawListener (ViewTreeObserver.OnDrawListener listener)
該函數為api 16版本中添加,作用是注冊在該view tree將要繪制時候的回調監聽器,注意該函數和相關的remove函數不能在監聽器回調的onDraw()中調用。
public void (ViewTreeObserver.OnGlobalFocusChangeListener listener)
該函數用來注冊在view tree焦點改變時候的回調監聽器。
public void addOnGlobalLayoutListener (ViewTreeObserver.OnGlobalLayoutListener listener)
該函數用來注冊在該view tree中view的全局布局屬性改變或者可見性改變時候的回調監聽器。
public void addOnPreDrawListener (ViewTreeObserver.OnPreDrawListener listener)
該函數用來注冊當view tree將要被繪制時候(view 的 onDraw 函數之前)的回調監聽器。
public void addOnScrollChangedListener (ViewTreeObserver.OnScrollChangedListener listener)
該函數用來注冊當view tree滑動時候的回調監聽器,比如用來監聽ScrollView的滑動狀態。
public void addOnTouchModeChangeListener (ViewTreeObserver.OnTouchModeChangeListener listener)
該函數用來注冊當view tree的touch mode改變時的回調監聽器,回調函數onTouchModeChanged (boolean isInTouchMode)中的isInTouchMode為該view tree的touch mode狀態。
public void addOnWindowAttachListener (ViewTreeObserver.OnWindowAttachListener listener)
api 18添加,該函數用來注冊當view tree被附加到一個window上時的回調監聽器。
public void (ViewTreeObserver.OnWindowFocusChangeListener listener)
api 18添加,該函數用來注冊當window中該view tree焦點改變時候的回調監聽器。
而且對應每一個add方法都會有一個remove方法用來刪除相應監聽器。

view.measure(int widthMeasureSpec, int heightMeasureSpec)
通過手動對view進行measure來得到view的寬/高,這種情況比較復雜,這里要分情況處理,根據view的layoutparams來分:
match_parent
直接放棄,無法measure出具體的寬/高。原因很簡單,根據view的measure過程,構造此種MeasureSpec需要知道parentSize,即父容器的剩餘空間,而這個時候我們無法知道parentSize的大小,所以理論上不可能測量處view的大小。
wrap_content
int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec((1<<30)-1, View.MeasureSpec.AT_MOST);
int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec((1<<30)-1, View.MeasureSpec.AT_MOST);
v_view1.measure(widthMeasureSpec, heightMeasureSpec);123

注意到(1<<30)-1,我們知道MeasureSpec的前2位為mode,後面30位為size,所以說我們使用最大size值去匹配該最大化模式,讓view自己去計算需要的大小。
具體的數值(dp/px)
這種模式下,只需要使用具體數值去measure即可,比如寬/高都是100px:
int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(100, View.MeasureSpec.EXACTLY);
int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(100, View.MeasureSpec.EXACTLY);
v_view1.measure(widthMeasureSpec, heightMeasureSpec);123

源碼和結果
demo代碼如下
xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/v_view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"/>

<View
android:id="@+id/v_view2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@mipmap/ic_launcher"/>

</LinearLayout>12345678910111213141516171819

activity:
public class MainActivity extends BaseActivity{
private View v_view1;
private View v_view2;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

v_view1 = findViewById(R.id.v_view1);
v_view2 = findViewById(R.id.v_view2);

L.i("normal: v_view1.getWidth():" + v_view1.getWidth()
+ " v_view1.getHeight():" + v_view1.getHeight());

v_view1.post(new Runnable() {
@Override
public void run() {
L.i("post(Runnable) : v_view1.getWidth():" + v_view1.getWidth()
+ " v_view1.getHeight():" + v_view1.getHeight());
}
});

v_view1.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
L.i("ViewTreeObserver : v_view1.getWidth():" + v_view1.getWidth()
+ " v_view1.getHeight():" + v_view1.getHeight());
}
});

int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec((1<<30)-1, View.MeasureSpec.AT_MOST);
int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec((1<<30)-1, View.MeasureSpec.AT_MOST);
v_view1.measure(widthMeasureSpec, heightMeasureSpec);
L.i("measure : v_view1.getMeasuredWidth():" + v_view1.getMeasuredWidth()
+ " v_view1.getMeasuredHeight():" + v_view1.getMeasuredHeight());
v_view2.measure(widthMeasureSpec, heightMeasureSpec);
L.i("measure : v_view2.getMeasuredWidth():" + v_view2.getMeasuredWidth()
+ " v_view2.getMeasuredHeight():" + v_view2.getMeasuredHeight());

}

@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
L.i("onWindowFocusChanged : v_view1.getWidth():" + v_view1.getWidth()
+ " v_view1.getHeight():" + v_view1.getHeight());
}
}
041424344454647484950

log日誌:
I/[PID:2659]: [TID:1] MainActivity.onCreate(line:28): normal: v_view1.getWidth():0 v_view1.getHeight():0
I/[PID:2659]: [TID:1] MainActivity.onCreate(line:50): measure : v_view1.getMeasuredWidth():144 v_view1.getMeasuredHeight():144
I/[PID:2659]: [TID:1] MainActivity.onCreate(line:53): measure : v_view2.getMeasuredWidth():16777215 v_view2.getMeasuredHeight():16777215
I/[PID:2659]: [TID:1] 2.onGlobalLayout(line:42): ViewTreeObserver : v_view1.getWidth():144 v_view1.getHeight():144
I/[PID:2659]: [TID:1] 1.run(line:34): post(Runnable) : v_view1.getWidth():144 v_view1.getHeight():144
I/[PID:2659]: [TID:1] MainActivity.onWindowFocusChanged(line:61): onWindowFocusChanged : v_view1.getWidth():144 v_view1.getHeight():144123456

界面:

小的為view_1,大的為view_2,從log日誌中就發現有問題了:view_2視圖使用measure之後計算出來的寬高是錯誤的,所以View類的視圖使用measure計算出來的結果是不準確的,這點需要特別特別注意。

㈧ 如何在Android Shell命令行中斷運行中的程序

android程序執行adb shell命令(實例源碼)
package net.gimite.nativeexe;

import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import net.gimite.nativeexe.R;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;

public class MainActivity extends Activity {

private TextView outputView;
private Button localRunButton;
private EditText localPathEdit;
private Handler handler = new Handler();
private EditText urlEdit;
private Button remoteRunButton;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

outputView = (TextView)findViewById(R.id.outputView);
localPathEdit = (EditText)findViewById(R.id.localPathEdit);
localRunButton = (Button)findViewById(R.id.localRunButton);
localRunButton.setOnClickListener(onLocalRunButtonClick);

}

private OnClickListener onLocalRunButtonClick = new OnClickListener() {
public void onClick(View v) {
String output = exec(localPathEdit.getText().toString());
output(output);
// try {
//
// // Process process = Runtime.getRuntime().exec(localPathEdit.getText().toString());
//
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
}
};

// Executes UNIX command.
private String exec(String command) {
try {
Process process = Runtime.getRuntime().exec(command);
BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
int read;
char[] buffer = new char[4096];
StringBuffer output = new StringBuffer();
while ((read = reader.read(buffer)) > 0) {
output.append(buffer, 0, read);
}
reader.close();
process.waitFor();
return output.toString();
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}

private void download(String urlStr, String localPath) {
try {
URL url = new URL(urlStr);
HttpURLConnection urlconn = (HttpURLConnection)url.openConnection();
urlconn.setRequestMethod("GET");
urlconn.setInstanceFollowRedirects(true);
urlconn.connect();
InputStream in = urlconn.getInputStream();
FileOutputStream out = new FileOutputStream(localPath);
int read;
byte[] buffer = new byte[4096];
while ((read = in.read(buffer)) > 0) {
out.write(buffer, 0, read);
}
out.close();
in.close();
urlconn.disconnect();
} catch (MalformedURLException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

private void output(final String str) {
Runnable proc = new Runnable() {
public void run() {
outputView.setText(str);
}
};
handler.post(proc);
}

}

㈨ android中handler.post();和view.post();有經驗的開發者受累解答下~~~

AsyncTask 分前台任務和後台任務, 後台任務是通過線程池實現的, 運行時你可以通過ddms查看

handler 處理方式很單一, 就是個消息處理. 處理線程是調用loop()方法的那條.
就想了這么多了...

㈩ android開發問題。。關於handler的sendmessage

此代碼是創建新線程,執行run方法後,在發送消息到handler,有handlerMessage()回調方法處理,你線程中無循環,怎麼會循環執行呢,以上請採納

熱點內容
phpmysql長連接 發布:2025-05-16 10:51:50 瀏覽:731
android橫屏全屏 發布:2025-05-16 10:47:43 瀏覽:473
伺服器直鏈下載搭建 發布:2025-05-16 10:47:38 瀏覽:174
編譯不成功怎麼辦 發布:2025-05-16 10:35:54 瀏覽:612
如何修改密碼找回 發布:2025-05-16 10:35:53 瀏覽:569
怎麼才能編譯本書 發布:2025-05-16 10:27:47 瀏覽:759
ssd伺服器電腦 發布:2025-05-16 10:26:25 瀏覽:829
水果忍者源碼 發布:2025-05-16 10:26:22 瀏覽:473
python中ord函數 發布:2025-05-16 10:14:25 瀏覽:340
電腦啟動後無法連接伺服器 發布:2025-05-16 10:06:39 瀏覽:985