[英]can't start activity in android
When button click I want go to another xml layout file. 当单击按钮时,我要转到另一个xml布局文件。 So i wrote start new activity as following way.
所以我写了如下的开始新活动。
startActivity(new Intent(AndroidPHPConnectionDemo.this, MainActivity.class));
MainAcivity class is, MainAcivity类是,
public class MainActivity extends ListActivity implements FetchDataListener{
private ProgressDialog dialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
}
private void initView() {
// show progress dialog
dialog = ProgressDialog.show(this, "", "Loading...");
String url = "http://10.0.2.2/new/newA.php";
FetchDataTask task = new FetchDataTask(this);
task.execute(url);
}
@Override
public void onFetchComplete(List<Application> data) {
// dismiss the progress dialog
if(dialog != null) dialog.dismiss();
// create new adapter
ApplicationAdapter adapter = new ApplicationAdapter(this, data);
// set the adapter to list
setListAdapter(adapter);
}
@Override
public void onFetchFailure(String msg) {
// dismiss the progress dialog
if(dialog != null) dialog.dismiss();
// show failure message
Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
}
}
So main activity class reference to the listview layout file. 因此,主要活动类对listview布局文件的引用。 When debug the code above startactivity line is executed.
调试时,将执行startactivity行上方的代码。 But the problem is activity is not started.
但是问题是活动没有开始。 It means I can't show the listview
这意味着我无法显示列表视图
pls give answer to overcome this problem 请给出解决这个问题的答案
Do you have your second activity added in AndroidManifest.xml
? 您是否在
AndroidManifest.xml
添加了第二个活动? Your manifest should look something like this: 您的清单应如下所示:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="your.package.name">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".MainActivity" android:label="@string/app_name"></activity>
<activity android:name=".AndroidPHPConnectionDemo"></activity>
</application>
<uses-sdk android:minSdkVersion="4" />
</manifest>
Just add an extra line under the <application>
tag for your activity. 只需为您的活动在
<application>
标记下添加一行。
I got the answer . 我得到了答案。 because i didn't call mainactivity in my mainfist file thanks
因为我没有在mainfist文件中调用mainactivity,谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.