M
Massym
Neues Mitglied
- 0
Hallo,
ich bin ein Anfäger und habe kaum erfahrung mit Programmiersprachen. Kämpfe mich seit 2 Monaten durch zahlreiche Foren und Tutarials...nun bin ich dabei Highscore Daten von Parse.com auszulesen und in einer ListView anzuzeigen (das die Liste noch sortiert werden muss und der gleichen ist mir im moment noch egal)... das habe ich auch teilweise hinbekommen aber meine ListView ist im emulator mal sichtbar und mal nicht sichtbar, auf meinem Handy ist sie nie zu sehen! Ich versuche jetzt seit bald 2 Wochen das hinzubekommen, bin mitlerweile wirklich verzweifelt und weiss nicht mehr weiter...
Hier mein Code, vieleicht sieht ja jemand meinen fahler und kann mir weiter helfen:
ich bin ein Anfäger und habe kaum erfahrung mit Programmiersprachen. Kämpfe mich seit 2 Monaten durch zahlreiche Foren und Tutarials...nun bin ich dabei Highscore Daten von Parse.com auszulesen und in einer ListView anzuzeigen (das die Liste noch sortiert werden muss und der gleichen ist mir im moment noch egal)... das habe ich auch teilweise hinbekommen aber meine ListView ist im emulator mal sichtbar und mal nicht sichtbar, auf meinem Handy ist sie nie zu sehen! Ich versuche jetzt seit bald 2 Wochen das hinzubekommen, bin mitlerweile wirklich verzweifelt und weiss nicht mehr weiter...
Hier mein Code, vieleicht sieht ja jemand meinen fahler und kann mir weiter helfen:
Code:
[B]Meine HighscoreActivity.java[/B]
public class HighscoreActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.highscore);
ImageView HS_anim = (ImageView)findViewById(R.id.highscore_anim_view);
final AnimationDrawable HighscoreAnimationDrawable
= (AnimationDrawable)HS_anim.getDrawable();
HS_anim.post(
new Runnable(){
@Override
public void run() {
HighscoreAnimationDrawable.start();
}
});
final List<Score> scores = new ArrayList<Score>(0);
ListView bibliothekLV = (ListView) findViewById(R.id.listView1);
ScoreAdapter adapter = new ScoreAdapter(this.getApplicationContext(), R.layout.listviewadapter, scores);
bibliothekLV.setAdapter(adapter);
ParseQuery<ParseObject> query = ParseQuery.getQuery("Highscore");
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> parseObjectList, ParseException e) {
if (e == null) {
int i = 1;
for (ParseObject highscore : parseObjectList) {
if (i == 1){ Score erster = new Score();
erster.setPlayer(highscore.getString("Player")); erster.setLevel(highscore.getString("LVL"));
erster.setPunkte(highscore.getString("Punkte")); i+=1; scores.add(erster);
Log.d("nummer 1", "OK");
}
if (i == 2){ Score zweiter = new Score();
zweiter.setPlayer(highscore.getString("Player")); zweiter.setLevel(highscore.getString("LVL"));
zweiter.setPunkte(highscore.getString("Punkte")); i+=1; scores.add(zweiter);
Log.d("nummer 2", "OK");
}
if (i == 3){ Score dritter = new Score();
dritter.setPlayer(highscore.getString("Player")); dritter.setLevel(highscore.getString("LVL"));
dritter.setPunkte(highscore.getString("Punkte")); i+=1; scores.add(dritter);
Log.d("nummer 3", "OK");
Log.d("Einträge", "erhalten " + parseObjectList.size() + " Eintrage");
}
}
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});
}
public class ScoreAdapter extends ArrayAdapter<Score> {
Context context;
int layoutResourceId;
List<Score> data=null;
public ScoreAdapter(Context context, int layoutResourceId, List<Score> data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
ScoreHolder holder = null;
if(row == null)
{
LayoutInflater inflater = LayoutInflater.from(context);
row = inflater.inflate(layoutResourceId, parent, false);
holder = new ScoreHolder();
holder.icon = (ImageView)row.findViewById(R.id.listview_icon);
holder.playername = (TextView)row.findViewById(R.id.listview_name);
holder.level = (TextView)row.findViewById(R.id.listview_lvl);
holder.hochstpunkte = (TextView)row.findViewById(R.id.listview_punkte);
row.setTag(holder);
}
else
{
holder = (ScoreHolder)row.getTag();
}
Score score = data.get(position);
holder.playername.setText(score.getPlayer());
holder.level.setText(score.getLevel());
holder.hochstpunkte.setText(score.getPunkte());
if(!(score.getBild()==null))
holder.icon.setImageBitmap(score.getBild());
else
holder.icon.setImageResource(R.drawable.ic_launcher);
return row;
}
}
static class ScoreHolder
{
public TextView playername;
public TextView level;
public TextView hochstpunkte;
public ImageView icon;
}
public class Score {
private long id;
private String player;
private String titel;
private String autor;
private String punkte;
private String lvl;
private String comment;
private Bitmap bild;
private int status;
private int ressource;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getTitel() {
return titel;
}
public void setTitel(String titel) {
this.titel = titel;
}
public String getPlayer() {
return player;
}
public void setPlayer(String player) {
this.player = player;
}
public String getAutor() {
return autor;
}
public void setAutor(String autor) {
this.autor = autor;
}
public String getPunkte() {
return punkte;
}
public void setPunkte(String punkte) {
this.punkte = punkte;
}
public String getLevel() {
return lvl;
}
public void setLevel(String lvl) {
this.lvl = lvl;
}
public String getBeschreibung() {
return comment;
}
public void setBeschreibung(String Beschreibung) {
this.comment = Beschreibung;
}
public Bitmap getBild() {
return bild;
}
public void setBild(Bitmap bild) {
this.bild = bild;
}
public Integer getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public Integer getRessource() {
return ressource;
}
public void setRessource(int ressource) {
this.ressource = ressource;
}
}
}
[B]Meine Highscore.xml datei[/B]:
<?xml version="1.0" encoding="utf-8"?>
<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"
android:weightSum="1"
android:orientation="vertical"
tools:context=".MainActivity"
android:background="#ff75bcf0"
android:id="@+id/frameLayout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:layout_weight="1.44">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<ImageView
android:layout_width="280dp"
android:layout_height="60dp"
android:id="@+id/highscore_anim_view"
android:layout_gravity="center_horizontal"
android:src="@drawable/highscore_title_anim" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="386dp"
android:layout_gravity="center_horizontal"
android:gravity="center">
<ListView
android:layout_height="315dp"
android:layout_width="298dp"
android:id="@+id/listView1" />
</LinearLayout>
</LinearLayout>
[B]Meine listviewadapter.xml datei:[/B]
<?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="wrap_content"
android:orientation="horizontal"
android:paddingTop="10dp"
android:id="@+id/listview_buch"
android:gravity="center|left">
<ImageView
android:id="@+id/listview_icon"
android:layout_width="25dp"
android:layout_height="25dp"
android:src="@drawable/ic_launcher"
android:layout_gravity="center_vertical|left" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="4dp"
android:weightSum="1">
<TextView
android:id="@+id/listview_name"
android:layout_width="120dp"
android:layout_height="match_parent"
android:text="@+id/listview_titel"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffff6923"
android:layout_gravity="bottom|left"
android:gravity="left" />
<TextView
android:id="@+id/listview_lvl"
android:layout_width="60dp"
android:layout_height="match_parent"
android:text="@+id/listview_subtitel"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_weight="11.33"
android:layout_gravity="center_horizontal"
android:gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/listview_punkte"
android:layout_weight="13.08"
android:gravity="right" />
</LinearLayout>
</LinearLayout>