新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > Android常用控件之下拉刷新Wifi列表

Android常用控件之下拉刷新Wifi列表

作者: 時間:2016-09-12 來源:網(wǎng)絡 收藏

import android.widget.BaseAdapter;

import android.widget.LinearLayout;

import android.widget.TextView;

import com.example.dropdownrefresh.ui.DropdownListView;

import com.example.dropdownrefresh.ui.DropdownListView.OnRefreshListener;

import com.example.dropdownrefresh.utils.WifiAdmin;

/**

* 使用下拉刷新搜索wifi

* @author Administrator

*

*/

public class MainActivity extends Activity {

WifiAdmin wifiAdmin = null;

private ArrayList

private BaseAdapter adapter;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

wifiAdmin = new WifiAdmin(this);

list = new ArrayList

RefreshList();

final DropdownListView listView = (DropdownListView) findViewById(R.id.listView);

adapter = new BaseAdapter() {

public View getView(int position, View convertView, ViewGroup parent) {

LinearLayout layout = new LinearLayout(getApplicationContext());

layout.setOrientation(LinearLayout.VERTICAL); //垂直布局

HashMap

TextView txtName = new TextView(getApplicationContext());

TextView txtSignal = new TextView(getApplicationContext());

txtName.setText(map.get(wifi_name));

txtSignal.setText(map.get(wifi_signal));

layout.addView(txtName);

layout.addView(txtSignal);

return layout;

}

public long getItemId(int position) {

return 0;

}

public Object getItem(int position) {

return null;

}

public int getCount() {

return list.size();

}

};

listView.setAdapter(adapter);

listView.setonRefreshListener(new OnRefreshListener() {

public void onRefresh() {

new AsyncTask

protected Void doInBackground(Void... params) {

try {

Thread.sleep(1000);

} catch (Exception e) {

e.printStackTrace();

}

list.clear();

RefreshList();

return null;

}

@Override

protected void onPostExecute(Void result) {

adapter.notifyDataSetChanged();

listView.onRefreshComplete();

}

}.execute(null, null, null);

}

});

}

private void RefreshList(){

wifiAdmin.startScan(); // 掃描wifi熱點,前提是wifi已經(jīng)打開

List wifiList = wifiAdmin.getWifiList();

for (int index = 0; index wifiList.size(); index++) {

HashMap

map.put(wifi_name, (wifiList.get(index)).SSID);

map.put(wifi_signal, signal:

+ (-(wifiList.get(index)).level) + %);

list.add(map);

}

}

}



關鍵詞:

評論


相關推薦

技術專區(qū)

關閉