androidManifest [snippet]
<activity android:name=".About">
android:label="@string/about_title"
android:theme="@android:style/Theme.Dialog" >
</activity>
<activity android:name=".Exit">
andorid:label="@string/exit_title">
</activity>
<activity android:name=".Options">
</activity>
<activity android:name=".Start">
</activity>
<activity android:name=".Create">
</activity>
</application>
AndroidSQLite
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sql);
TextView listContent = (TextView)findViewById(R.id.contentlist);
mySQLiteAdapter = new SQLiteAdapter(this);
mySQLiteAdapter.openToWrite();
mySQLiteAdapter.deleteAll();
mySQLiteAdapter.insert("ABCDE");
mySQLiteAdapter.insert("FGHIJK");
mySQLiteAdapter.insert("1234567");
mySQLiteAdapter.insert("890");
mySQLiteAdapter.insert("Testing");
mySQLiteAdapter.close();
mySQLiteAdapter = new SQLiteAdapter(this);
mySQLiteAdapter.openToRead();
String contentRead = mySQLiteAdapter.queueAll();
mySQLiteAdapter.close();
listContent.setText(contentRead);
}
sql.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/app_name"
/>
<ListView
android:id="@+id/contentlist"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
main.xml [snippet]
<Button
android:id="@+id/where_button"
android:onClick="WhereCl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/where_label" />
代码负责按钮我在哪里?
mainActivity.java
public class MainActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
View startButton = findViewById(R.id.start_button);
View whereButton = findViewById(R.id.where_button);
View aboutButton = findViewById(R.id.about_button);
View exitButton = findViewById(R.id.exit_button);
}
public void OptionsCl(View v){
startActivity(new Intent(this,Options.class));
}
public void WhereCl(View v){
startActivity(new Intent(this,AndroidSQLite.class));
}
public void StartCl(View v){
Intent idd = new Intent(this,Start.class);
startActivity(idd);
}
public void AboutCl(View v){
startActivity(new Intent(this,About.class));
}
public void ExitCl(View v){
finish();
}
}
我收到的错误类似于提出未注册的操作,但操作已注册[检查代码]
只是“应用程序blabla(menu.dot)意外停止。请再试一次”强行关闭。
答案 0 :(得分:1)
Android SQLite是现成的库。所以你不需要启动任何服务,服务器或恶魔。只是为了启动一个扩展SQLite DatabaseHelper类的数据库类并使用它。
感谢。