我有一个arraylist,每个索引也有一个arraylist。列表视图中列出了每个索引。如何在两个活动之间传递数据?我尝试了这些代码,但是当我点击列表视图时,它就崩溃了。
on my mainAcitivity
FuelView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intents = new Intent(MainActivity.this, EditEntry.class);
String i = String.valueOf(position);
intents.putExtra(KEY, i);
startActivity(intents);`
}
}
on my secondActivity
loadFromFile();
Intent intents = getIntent();
final int index = Integer.valueOf(intents.getStringExtra(MainActivity.KEY));
findEntry(index);
在findEntry函数
上Entrylist Entrylist = Entrylists.get(index);
EditText new_date = (EditText) findViewById(R.id.date);
new_date.setText(Entrylist.getDate().toString());
EditText new_station = (EditText) findViewById(R.id.station);
new_station.setText(Entrylist.getStation().toString());
EditText new_odometer= (EditText) findViewById(R.id.odometer);
new_odometer.setText(Entrylist.getOdometer().toString());
EditText new_grade = (EditText) findViewById(R.id.fuel_grade);
new_grade.setText(Entrylist.getGrade().toString());
EditText new_amount = (EditText) findViewById(R.id.fuel_amount);
new_amount.setText(Entrylist.getAmount().toString());
EditText new_cost = (EditText) findViewById(R.id.unit_cost);
new_cost.setText(Entrylist.getCost().toString());
Button save = (Button) findViewById(R.id.button2);
save.setText("Save");
这是错误
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.larin.aolin1_fueltrack/com.example.larin.aolin1_fueltrack.EditEntry}: java.lang.NumberFormatException: Invalid int: "null"
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NumberFormatException: Invalid int: "null"
at java.lang.Integer.invalidInt(Integer.java:138)
at java.lang.Integer.parseInt(Integer.java:355)
at java.lang.Integer.parseInt(Integer.java:332)
at java.lang.Integer.valueOf(Integer.java:490)
at com.example.larin.aolin1_fueltrack.EditEntry.onCreate(EditEntry.java:41)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
您是否尝试使用?
解析索引@Component({
selector: 'my-app',
directives: [NavbarComponent, ROUTER_DIRECTIVES],
template: `
<my-navbar></my-navbar>
<router-outlet></router-outlet>
})
class AppComponent {
constructor(dcl: DynamicComponentLoader, elementRef: ElementRef) {
dcl.loadNextToLocation(SidebarComponent, elementRef);
}
}
此外,您可以通过意图发送int值:
<my-app>
<my-navbar></my-navbar>
<router-outlet></router-outlet>
</my-app>
<my-sidebar>Sidebar</my-sidebar>