JMa*_*sia 6 variables android class android-intent
我在使用Intent导航屏幕时遇到问题.我想发送一个变量并在其他类中使用它.
我正在使用一个方法,该方法接受变量,但我不知道如何将其与意图发送到新屏幕,这将使用它来做一些事情.
主类调用metod:
private void pantallaDetalles(final int identificador)
{
startActivityForResult(new Intent(this,MostrarDetalles.class),REQST_CODE);
}
Run Code Online (Sandbox Code Playgroud)
MostrarDetalles.class是*.java,它将获取变量.我这样开头:
public class MostrarDetalles extends Activity {
SQLiteDatabase db;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.detalles);
//more code...
Cursor c = db.rawQuery("SELECT * FROM table WHERE _id="+ identificador, null);
}
Run Code Online (Sandbox Code Playgroud)
你看到吗?我在说这个.我不知道如何通过Intent将"identify"变量从主类发送到第二类.
你能帮帮我吗?非常感谢你的建议.
JMasia.
Che*_*mon 12
在意图中使用extras包.
Intent i = new Intent(...);
i.putExtra("name_of_extra", myObject);
Run Code Online (Sandbox Code Playgroud)
然后on onCreate:
getIntent.getIntExtra("name_of_extra", -1);
Run Code Online (Sandbox Code Playgroud)
屏幕1:
Intent i=new Intent("com.suatatan.app.Result");
i.putExtra("VAR_RESULT", "Added !");
startActivity(i);
Run Code Online (Sandbox Code Playgroud)
屏幕2 :(接收者):
TextView tv_sonuc = (TextView) findViewById(R.id.tv_sonuc);
Bundle bundle = getIntent().getExtras();
String var_from_prev_intent = bundle.getString("VAR_RESULT");
tv_sonuc.setText(var_from_prev_intent);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
12145 次 |
最近记录: |