好吧,我正在看这个教程:http ://www.youtube.com/watch?v=9ew_Ajpqwqg#t=5m25s
这里可以看到他写的是Intent i = new Intent……
但我的应用程序不能那样工作:/
这是我的代码
MainActivity.java
public class MainActivity extends Activity implements OnClickListener {
Button btnAddCategory, btnViewCategory;
EditText txtCategories;
TextView viewMain, viewAllCategories;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtCategories = (EditText) findViewById(R.id.txtCategories);
viewMain = (TextView) findViewById(R.id.viewMain);
btnAddCategory = (Button) findViewById(R.id.btnAddCategory);
btnViewCategory = (Button) findViewById(R.id.btnViewCategory);
viewAllCategories = (TextView) findViewById(R.id.viewAllCategories);
btnAddCategory.setOnClickListener(this);
btnViewCategory.setOnClickListener(this);
}
public void onClick(View arg0) {
switch(arg0.getId())
{
case R.id.btnAddCategory:
boolean didItWork = true;
try {
Categories entry = new Categories(MainActivity.this);
entry.open();
entry.createEntry(txtCategories.getText().toString());
entry.close();
} catch(Exception e) {
didItWork = false;
} finally {
if (didItWork)
{
Dialog d = new Dialog(MainActivity.this);
d.setTitle("New Category Created");
TextView tv = new TextView(MainActivity.this);
tv.setText("Success");
d.setContentView(tv);
d.show();
}
}
break;
case R.id.btnViewCategory:
Intent i = new Intent("android.intent.action.SQLVIEW");
startActivity(i);
break;
}
}
}
SQLView.Java
public class SQLView extends Activity {
protected void OnCreate(Bundle savedInstanceSatate) {
super.onCreate(savedInstanceSatate);
setContentView(R.layout.sqlview);
TextView tv = (TextView) findViewById(R.id.infosFromDb);
Categories info = new Categories(this);
info.open();
String data = info.getData();
info.close();
tv.setText(data);
} }
显现
<activity
android:name=".SQLView" android:label="@string/app_name">
<action android:name="android.intent.action.SQLVIEW" />
<category android:name="android.intent.category.LAUNCHER" />
</activity>
我在这里读过一个帖子,有人遇到同样的问题,所以我将其更改为:
case R.id.btnViewCategory:
Intent i = new Intent(MainActivity.this, SQLView.class);
startActivity(i);
break;
所以,现在我没有得到任何异常,但我得到了一个空视图。我只能看到我的应用程序的名称,但就是这样,视图中的所有 TextViews 等都消失了。
有没有人知道如何处理这个问题?
提前致谢