android远程连接mysql_Android 远程连接数据库。。。。。

代码----

packagecom.example.administrator.demo1;importandroid.os.Handler;importandroid.support.v7.app.AlertDialog;importandroid.support.v7.app.AppCompatActivity;importandroid.os.Bundle;importandroid.util.AttributeSet;importandroid.view.View;importandroid.widget.FrameLayout;importandroid.widget.LinearLayout;importandroid.widget.TabHost;importandroid.widget.TabWidget;importandroid.widget.TextView;importandroid.widget.Toast;importorg.whm.db.DbUtils;importjava.util.ArrayList;importjava.util.List;importjava.util.Map;importjava.util.Objects;importjava.util.jar.Attributes;public class MainActivity extendsAppCompatActivity {//钩子线程

Handler handler = null;

@Overrideprotected voidonCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);//Example of a call to a native method//TextView tv = (TextView) findViewById(R.id.tabhost);//tv.setText(stringFromJNI());

TabHost tabHost =(TabHost) findViewById(R.id.tabhost);

tabHost.setup();//FrameLayout frameLayout = (FrameLayout) findViewById(R.id.tabcontent);//int childCount = frameLayout.getChildCount();

LinearLayout l1 =(LinearLayout) findViewById(R.id.tab1);

LinearLayout l2=(LinearLayout) findViewById(R.id.tab2);

handler= newHandler();//在lambda中尽量不要抛出异常。。。。

new Thread(() ->{

List> list =getData(l1);

handler.post(new Thread(() ->{

darwView(list, l1);

}));

}).start();

TabHost.TabSpec tabSpec1= tabHost.newTabSpec("tabSpec1").setIndicator("视频").setContent(R.id.tab1);

TabHost.TabSpec tabSpec2= tabHost.newTabSpec("tabSpec2").setIndicator("直播").setContent(R.id.tab2);

tabHost.addTab(tabSpec1);

tabHost.addTab(tabSpec2);

}/*** A native method that is implemented by the 'native-lib' native library,

* which is packaged with this application.*/

public nativeString stringFromJNI();//从远程服务器获取数据

private List>getData(LinearLayout l) {

List> list = null;try{

list= DbUtils.execQuery("select * from video", null);

}catch(Exception e) {

e.printStackTrace();

Toast.makeText(getApplicationContext(),"发生了错误", Toast.LENGTH_LONG).show();

}returnlist;

}//绘制ui

private void darwView(List>list, LinearLayout view) {

list.forEach((map)->{

TextView tv= newTextView(getApplicationContext());

tv.setText((String) map.get("title"));

view.addView(tv);

});

}//Used to load the 'native-lib' library on application startup.

static{

System.loadLibrary("native-lib");

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值