Java 如何将意图传递给包含ListView的布局?(安卓工作室)
我正在尝试将意图从我的mainScreen活动类传递到一个新的android类,该类的布局包含ListView MainActivityScreen代码: 时间传递的格式为“HH:MM:SS”Java 如何将意图传递给包含ListView的布局?(安卓工作室),java,android,listview,android-intent,android-studio,Java,Android,Listview,Android Intent,Android Studio,我正在尝试将意图从我的mainScreen活动类传递到一个新的android类,该类的布局包含ListView MainActivityScreen代码: 时间传递的格式为“HH:MM:SS” public void MoveToShiftsPage(View view) { Intent shiftsIntent=new Intent(this,Shifts.class); shiftsIntent.putExtra("time",TimePassed); star
public void MoveToShiftsPage(View view) {
Intent shiftsIntent=new Intent(this,Shifts.class);
shiftsIntent.putExtra("time",TimePassed);
startActivity(shiftsIntent);
}
MainActivity.xml文件中的MoveToShiftsPage:
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@mipmap/payment"
android:id="@+id/shiftbtn"
android:onClick="MoveToShiftsPage"
/>
Shifts.xml文件包含ListView和发送给它的意图的布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" tools:context=".MainScreen"
>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:id="@+id/MyListView"
android:clickable="true"
style="@style/Base.Widget.AppCompat.ListView.DropDown">
</ListView>
/>
以及获取意图的Shift.class,它应该表示ListView以及经过的时间:
import android.app.Activity;
import android.content.Intent;
import android.app.ListFragment;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import java.util.List;
/**
* Created by user on 19/09/2015.
*/
public class Shifts extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.shifts);
Intent MyIntent=getIntent();
String TimePassed=MyIntent.getStringExtra("time");
String [] timepass=TimePassed.split(":");
ListAdapter theAdapter=new ArrayAdapter<String>
(this,android.R.layout.simple_list_item_activated_1,timepass);
ListView thelist=(ListView)findViewById(R.id.MyListView);
thelist.setAdapter(theAdapter);
}
}
不幸的是,每当我点击图像按钮时,应用程序就会崩溃。图像按钮应该发送到shift活动类,并用ListView表示布局。。
我该怎么办?试试这个,希望它能奏效
Intent MyIntent=this.getIntent 应用程序崩溃了。。我该怎么办使用LogCat检查与崩溃相关的Java堆栈跟踪:可以发布LogCat错误吗