LTE*_*HUB 53
第一个问题:
使用Intent调用另一个Activity.在Manifest中,你应该添加
<activity android:name="ListViewImage"></activity>
<activity android:name="com.company.listview.ListViewImage">
</activity>
Run Code Online (Sandbox Code Playgroud)
在你目前的活动中,
btListe = (ImageButton)findViewById(R.id.Button_Liste);
btListe.setOnClickListener(new OnClickListener()
{ public void onClick(View v)
{
intent = new Intent(main.this, ListViewImage.class);
startActivity(intent);
finish();
}
});
Run Code Online (Sandbox Code Playgroud)
第二个问题:
sendButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String valueString = editValue.getText().toString();
long value;
if (valueString != null) {
value = Long.parseLong(valueString);
}
else {
value = 0;
}
Bundle sendBundle = new Bundle();
sendBundle.putLong("value", value);
Intent i = new Intent(Activity1.this, Activity2.class);
i.putExtras(sendBundle);
startActivity(i);
finish();
}
});
Run Code Online (Sandbox Code Playgroud)
在Activity2中:
Bundle receiveBundle = this.getIntent().getExtras();
final long receiveValue = receiveBundle.getLong("value");
receiveValueEdit.setText(String.valueOf(receiveValue));
callReceiverButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(Activity2.this, Receiver.class);
i.putExtra("new value", receiveValue - 10);
}
});
Run Code Online (Sandbox Code Playgroud)
Tus*_*kar 10
检查以下代码以从另一个调用一个活动.
Intent intent = new Intent(CurrentActivity.this, OtherActivity.class);
CurrentActivity.this.startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
我在示例应用程序上使用以下代码来启动新活动.
Button next = (Button) findViewById(R.id.TEST);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent( view.getContext(), MyActivity.class);
startActivityForResult(myIntent, 0);
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
155920 次 |
| 最近记录: |