Android开启网络:
______________________________________________________________________________________
public void setMobileData(Context pContext, boolean pBoolean) {
try {
ConnectivityManager mConnectivityManager = (ConnectivityManager) pContext.getSystemService(Context.CONNECTIVITY_SERVICE);
Class ownerClass = mConnectivityManager.getClass();
Class[] argsClass = new Class[1];
argsClass[0] = boolean.class;
Method method = ownerClass.getMethod("setMobileDataEnabled", argsClass);
method.invoke(mConnectivityManager, pBoolean);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("移动数据设置错误: " + e.toString());
}
}
——————————————————————————————————————————————————————————————————————————
——————————————————————————————————————————————————————————————————————————————
// 响应DLg中的List item 点击
interface OnItemInDlgClickListener {
public void onItemClick( int position);
}
// 供路线选择的Dialog
class MyTransitDlg extends Dialog {
private List<? extends RouteLine> mtransitRouteLines;
private ListView transitRouteList;
private RouteLineAdapter mTransitAdapter;
private TextView textview_theme;
OnItemInDlgClickListener onItemInDlgClickListener;
public MyTransitDlg(Context context, int theme) {
super(context, theme);
}
public MyTransitDlg(Context context, List< ? extends RouteLine> transitRouteLines, RouteLineAdapter.Type
type) {
this( context, 0);
mtransitRouteLines = transitRouteLines;
mTransitAdapter = new RouteLineAdapter( context, mtransitRouteLines , type);
requestWindowFeature(Window.FEATURE_NO_TITLE);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_transit_dialog);
transitRouteList = (ListView) findViewById(R.id.transitList);
transitRouteList.setAdapter(mTransitAdapter);
textview_theme = (TextView) findViewById(R.id.textview_theme);
transitRouteList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
onItemInDlgClickListener.onItemClick(position);
dismiss();
}
});
}
public void setTextTheme(String textParam){
textview_theme.setText(textParam);
}
public void setOnItemInDlgClickLinster( OnItemInDlgClickListener itemListener) {
onItemInDlgClickListener = itemListener;
}
}
———————————————————————————————————————————————————————————————————————————