Also ich glaube im Großen und Ganzen habe ich es verstanden, aber es klappt trotzdem noch nicht ganz.
Ich habe jetzt folgende Activitys:
Team.java (Hier werden alle Player in einer listView angezeigt)
package manager.scg;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class Team extends Activity implements Serializable
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.team);
playerdatasource = new PlayerDataSource(this);
Team.this.ListTeam(null);
Button prev = (Button) findViewById(R.id.prev_team);
prev.setOnClickListener(new View.OnClickListener()
{
public void onClick(View view)
{
Intent intent = new Intent();
setResult(RESULT_OK, intent);
finish();
}
});
Button addplayer = (Button) findViewById(R.id.addplayer);
addplayer.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), Add_Player.class);
startActivityForResult(myIntent, 0);
}
});
Button adddata = (Button) findViewById(R.id.adddatateam);
adddata.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
playerdatasource.open();
playerdatasource.InsertDataPlayer();
playerdatasource.close();
}
});
}
private PlayerDataSource playerdatasource;
List<Entry> PlayerList = new ArrayList<Entry>();
public void ListTeam (View view) {
setContentView(R.layout.team);
PlayerList.clear();
try {
playerdatasource.open();
PlayerList = playerdatasource.getAllEntriesPlayer();
playerdatasource.close();
}
catch (Exception ex) {
Toast.makeText(this, ex.toString(), Toast.LENGTH_SHORT).show();
}
ArrayAdapter<Entry> adapterVerlauf = new ArrayAdapter<Entry>(Team.this, android.R.layout.simple_list_item_1, PlayerList);
ListView lPlayer = (ListView) findViewById(R.id.listViewPlayer);
lPlayer.setAdapter(adapterVerlauf);
lPlayer.setTextFilterEnabled(true);
lPlayer.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent myIntent = new Intent(getApplicationContext(), Player.class);
myIntent.putExtra("PlayerList", PlayerList.get(position));
startActivityForResult(myIntent, 1);
}
});
}
}
Alles anzeigen
und Player.java:
package manager.scg;
//import java.util.ArrayList;
//import java.util.List;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import manager.scg.Entry;
import manager.scg.R.string;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
//import android.widget.AdapterView;
//import android.widget.AdapterView.OnItemClickListener;
//import android.widget.ArrayAdapter;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
//import android.widget.ListView;
//import android.widget.Toast;
//import android.widget.ArrayAdapter;
//import android.widget.AdapterView.OnItemClickListener;
public class Player extends Activity implements Serializable {
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.player);
List<Entry> PlayerList = getIntent().getSerializableExtra("PlayerList");
Button prev = (Button) findViewById(R.id.prev_player);
prev.setOnClickListener(new View.OnClickListener()
{
public void onClick(View view)
{
Intent intent = new Intent();
setResult(RESULT_OK, intent);
finish();
}
});
Button test = (Button) findViewById(R.id.test);
test.setOnClickListener(new View.OnClickListener()
{
public void onClick(View view)
{
try{
Player.this.readPlayer();
} catch (NumberFormatException ex) {
}
}
});
}
public void readPlayer(){
Iterator<Entry> myIterator = PlayerList.iterator();
while (myIterator.hasNext()) {
Entry player = myIterator.next();
String name = player.getName();
Toast.makeText(this, player.getName(), Toast.LENGTH_LONG).show();
}
}
}
Alles anzeigen
In der Team.java übergebe ich nun in der
mit
myIntent.putExtra("PlayerList", PlayerList.get(position));
die PlayerList an die Player.java. Ich hoffe das das soweit richtig ist?!
Und in der Player.java nehme ich die Liste mit
List<Entry> PlayerList = getIntent().getSerializableExtra("PlayerList");
entgegen.
Und dann lasse ich den Iterator in der
drüberlaufen um die einzelnen Einträge "rauszufiltern".
Allerdings sagt er mir beim getIntent: "Type mismatch: cannot convert from Serializable to List<Entry>"
Also ganz richtig kann es noch nicht sein
Und was genau muss ich implements Serializable setzten?