setadapter 関数が呼び出されるたびにアプリがクラッシュし続けますが、その理由がわかりません。誰か助けてもらえますか? 私が実行しているエミュレーターは、アプリが予期せず停止したとだけ言っています。
これが私のメインです
public class MainActivity extends Activity {
private ListView listView1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Ride ride_data[] = new Ride[]
{
new Ride("LA Trip", "la man"),
new Ride("SD Trip", "sd man"),
new Ride("SF Trip", "sf man")
};
RideAdapter adapter = new RideAdapter(this,
R.layout.listview_item_row,ride_data);
listView1 = (ListView)findViewById(R.id.listView1);
View header = (View)getLayoutInflater().inflate(R.layout.listview_header_row, null);
listView1.addHeaderView(header);
listView1.setAdapter(adapter);
}
}
これが私のアダプターです
public class RideAdapter extends ArrayAdapter<Ride>{
Context context;
int layoutResourceId;
Ride data[] = null;
public RideAdapter(Context context, int layoutResourceId, Ride[] data)
{
super(context,layoutResourceId,data);
this.context = context;
this.layoutResourceId = layoutResourceId;
this.data = data;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View row = convertView;
RideHolder holder = null;
if(row == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new RideHolder();
holder.rideName = (TextView)row.findViewById(R.id.txtRideName);
holder.personName = (TextView)row.findViewById(R.id.txtPersonName);
row.setTag(holder);
}
else
{
holder = (RideHolder)row.getTag();
}
Ride ride = data[position];
holder.rideName.setText(ride.rideName);
holder.personName.setText(ride.personName);
return row;
}
public static class RideHolder
{
TextView rideName;
TextView personName;
}
}
これは私のライドクラスです
public class Ride {
public String rideName;
public String personName;
public Ride()
{
}
public Ride(String rideName, String personName)
{
super();
this.rideName=rideName;
this.personName=personName;
}
}
そして最後に、これは私のリストアイテムビューです
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="10dp"
>
<Textview
android:id="@+id/txtRideName"
android:layout_width ="wrap_content"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
/>
<Textview
android:id="@+id/txtPersonName"
android:layout_width ="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
/>
</LinearLayout>
どんな助けでも大歓迎です!