过去两天,我一直在试图让我的大脑工作。 基本上我想让我的按钮调用'添加密码功能'。试图通过按钮调用一个活动onClick
如果您想查看我的完整代码,请访问github.com/servingbaby/UPM-Epassafe。
这里是我的main.xml(按钮成功地显示出来但是推没事的时候发生) main.xml中
<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:id="@android:id/empty"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:gravity="center"
android:text="@string/no_accounts" />
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_gravity="center"
android:text="@string/add_account" android:id="@+id/add" android:minWidth="125dip"></Button>
<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
这里是我的AndroidManifest精简下来到我相信是部分我要去的地方错误。
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.epassafe.upm"
android:versionCode="3"
android:versionName="1.2">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="16"/>
<application android:icon="@drawable/upm"
....>
<activity android:name=".AppEntryActivity">
</activity>
<activity android:name=".FullAccountList">
<meta-data android:name="android.app.default_searchable"
android:value=".SearchResults" />
</activity>
<activity android:name=".AddEditAccount">
</activity>
</application>
</manifest>
这是我的MainActivity.Java,我相信我应该调用正确的代码。
public abstract class MainActivity extends Activity implements OnClickListener{`
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button countButton = (Button) findViewById(R.id.add);
countButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,AddEditAccount.class);
MainActivity.this.startActivity(intent);
}
});
}
}
但按下按钮什么都没有发生,就像我所期待的。没有错误或逼近,所以我现在真的很茫然。谢谢!
**编辑 谢谢大家如何帮助我。我已经尝试了许多建议的解决方案,但仍然没有弄明白。我已经把我的文件上传到了github上,并对我所做的一些尝试性修改进行了评论。基本上我只是想弄清楚如何添加一个按钮,并让它运行必要的代码来添加一个帐户。 (原代码运行良好,但我想改进它,很抱歉,我的能力水平仍然很低,但试图学习我的最好:)如果有人能帮助我,我真的很感激!谢谢^^
**编辑2 再次感谢您的建议和意见。我想出了一个简单的解决方案。我最终使用Menu Wrapper创建了一个按钮单击事件,而且事实证明我正在编辑错误的Java文档,当时我试图将正确的代码添加到另一个似乎几乎完成相同的代码事情。每天学些新东西。
尝试,Intent intent = new Intent(getApplicationContext(),AddEditAccount.class); – krammer
我可以看到AddEditAccount吗? – Blackbelt
在Android清单中,我无法找到活动MainActivity的声明,这可能是原因。请检查它。 – deepak825