如何命令活动中的按钮打开另一个活动,而不是通过编写代码,只使用属性菜单或右键单击按钮(图中所示)image。 我还在src文件中创建了一个新活动(.java文件)。 是否可以或我必须编写代码?
答案 0 :(得分:0)
要调用其他活动,您需要编写代码,即像这样的Intent,您可以调用另一个活动
Intent intent = new Intent(this,anotherActivity.class);
startActivity(intent);
答案 1 :(得分:0)
你必须。但它只有1行代码。将其添加到按钮的onClick
<table class="table table-striped, table-hover">
<thead>
<tr>
<td><strong>Product_Id</strong></td>
<td><strong>Product_Name</strong></td>
<td><strong>Picture</strong></td>
<td><strong>Options</strong></td>
</tr>
</thead>
<tbody>
<?php foreach ($products as $p): ?>
<tr>
<td><?php echo $p['product_id']; ?></td>
<td><?php echo $p['product_name']; ?></td>
<?php $images = explode(",", $p['images']); ?>
<td>
<?php foreach($images as $image) { ?>
<img src="<?php echo base_url('uploads/images/').$image; ?>" />
<?php } ?>
</td>
<td>
<a href="<?php echo site_url('#'); ?>">View</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
答案 2 :(得分:0)
在layout
xml文件内的按钮写属性android:onClick
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MyButton"
android:onClick="YourMethodName" />
和活动内部
public void YourMethodName(View v) {
// ButtonClickAction
}
这将在单击按钮时调用该方法
我怎么建议使用Intent
答案 3 :(得分:0)
你必须编写代码,没有逃避。要在单击按钮后打开另一个活动,请在按钮的OnClickListener上添加以下内容:
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(ActivityA.this, ActivityB.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
}
});
请记住在AndroidManifest.xml文件中添加下一个活动,如下所示,否则活动将无法运行:
<activity android:name=".ActivityB"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar.BlackActionBar" />