我在启动画面中使用Asynctask将数据库项添加到数据库中。 插入过程进展顺利,但启动视图不会显示。
我在下面发布我的代码,任何建议将不胜感激。 THX
splash.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/splash">
</RelativeLayout>
Splash.java
public class Splash extends Activity {
private ChannelDB mDB;
private TextView loading;
private String channelS_TABLE;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
new SetDB().execute();
}
private class SetDB extends AsyncTask<String, String, String> {
@Override
protected String doInBackground(String... arg0) {
// TODO Auto-generated method stub
try {
if (tabIsExist(channelS_TABLE) !=true){
**some database insert**
}else{
synchronized(this){
Log.i("Splash", "the table is there");
wait(3000);}
Intent i = new Intent();
i.setClassName("com.appkon.hdtvs",
"com.appkon.hdtvs.HDtvs");
finish();
startActivity(i);
}
}catch (Exception e) {
Log.i("Splash", "setDB exception");
Intent i = new Intent();
i.setClassName("com.appkon.hdtvs",
"com.appkon.hdtvs.HDtvs");
finish();
startActivity(i);
}
return null;
}
protected void onPreExecute(String load) {
synchronized (this) { try {
wait(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} }
}
protected void onPostExecute(String finish) {
Intent i = new Intent();
i.setClassName("com.appkon.hdtvs",
"com.appkon.hdtvs.HDtvs");
finish();
startActivity(i);
}
}
public boolean tabIsExist(String tableName){
boolean result = false;
if(tableName == null){
return false;
}
Cursor cursor= ChannelDB.check();
startManagingCursor(cursor);
try {
if(cursor.moveToNext()){
int count = cursor.getInt(0);
if(count>0){
result = true;
}
}
} catch (Exception e) {
Log.e(this.toString(),"error:"+e.toString());
Intent intent = new Intent(this,HDtvs.class);
startActivity(intent);
this.finish();
}
return result;
}
}
我更改了xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/splash">
<ImageView android:id="@+id/bg"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/splash"/>
</LinearLayout>
仍然无效,数据库插入也不起作用。
答案 0 :(得分:0)
RelativeLayout
是一个容器。只有在其中包含一些元素/视图时才会显示其背景。虽然我不确定。但您可以尝试此操作 - 从RelativeLayout
的背景中删除图片,并在ImageView
内创建RelativeLayout
,并将ImageView's
源图片设置为您想要的图片。你应该得到想要的结果。