我在使用意图浏览屏幕时遇到问题。我想发送一个变量并在另一个类中使用它。
我正在使用一个方法,该方法接受变量,但我不知道如何将其发送到新屏幕,新屏幕将使用它来做一些事情。
主类调用方法:
private void pantallaDetalles(final int identificador)
{
startActivityForResult(new Intent(this,MostrarDetalles.class),REQST_CODE);
}
Mostrar Detalles.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);
}
你有没有看到?我正在谈论这个。我不知道如何通过意图将“identificador”变量从主类发送到第二类。
你能帮我解决这个问题吗?非常感谢您的建议。
JMasia.
在意图中使用额外捆绑包。
Intent i = new Intent(...);
i.putExtra("name_of_extra", myObject);
然后在 onCreate 上:
getIntent.getIntExtra("name_of_extra", -1);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)