ListActivity mit einen BaseAdapter

  • 0 Antworten
  • Letztes Antwortdatum
M

mscholz

Neues Mitglied
0
Guten Abend!,
ich programmieren gerade an einer Verwaltungsapp und komme nicht weiter.

Ich habe mir einen Adapter geschrieben, der mir ein Array auflisten soll.

Code:
public class DienstplanAdapter extends BaseAdapter {
    private LayoutInflater mInflater;
    private List<Arbeitsschicht> schichtListe;

    public DienstplanAdapter(Context context, List<Arbeitsschicht> schichten) {
        this.mInflater = LayoutInflater.from(context);
        this.schichtListe = schichten;
    }

    @Override
    public int getCount() {
        return schichtListe.size();
    }

    @Override
    public Object getItem(int position) {
        return schichtListe.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        ViewHolder holder;
        if (convertView == null) {
            view = mInflater.inflate(R.layout.activity_dienstplan, parent,
                    false);
            holder = new ViewHolder();
            holder.datum = (TextView) view
                    .findViewById(R.id.dienstplan_datum);
            holder.name = (TextView) view.findViewById(R.id.dienstplan_name);
            holder.bereich = (TextView) view
                    .findViewById(R.id.dienstplan_bereich);
            holder.uhrzeit = (TextView) view
                    .findViewById(R.id.dienstplan_uhrzeit);
            view.setTag(holder);
        } else {
            view = convertView;
            holder = (ViewHolder) view.getTag();
        }
        Arbeitsschicht schicht = schichtListe.get(position);

        holder.name.setText(schicht.getMitarbeiter().getVorname() + " "
                + schicht.getMitarbeiter().getNachname());
        holder.bereich.setText(schicht.getBereich().getName());
        holder.datum.setText(schicht.getFormatiert_StartDatum());
        holder.uhrzeit.setText(schicht.getFormatiert_StartUhrzeit() + "-"
                + schicht.getFormatiert_EndeUhrzeit());

        return view;
    }


    /**
     * Hilfe Klasse fuers ViewHolder-Pattern aus Performancegruenden.
     * 
     */
    private class ViewHolder {
        public TextView datum;
        public TextView bereich;
        public TextView uhrzeit;
        public TextView name;
    }
Das ist die xml File dazu:

Code:
<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:background="@drawable/backround_klein"
    android:gravity="center_horizontal"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="280dp"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dip"
            android:layout_marginTop="20dip"
            android:background="@drawable/customborder"
            android:orientation="vertical" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/blue"
                android:orientation="vertical" >

                <CalendarView
                    android:id="@+id/dienstplan_calendarView"
                    android:layout_width="match_parent"
                    android:layout_height="234dp"
                    android:layout_marginBottom="12dip"
                    android:layout_marginLeft="-10dip"
                    android:layout_marginTop="-12dip" />
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>

   <RelativeLayout
       android:id="@+id/diensitplan_zeiten"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:orientation="horizontal"
       android:padding="5dip" >

       <TextView
           android:id="@+id/dienstplan_datum"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_alignParentLeft="true"
           android:gravity="left"
           android:text="@string/beispielDatum"
           android:textColor="#040404"
           android:textSize="15dip"
           android:textStyle="bold"
           android:typeface="sans" />

       <TextView
           android:id="@+id/dienstplan_bereich"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_below="@id/dienstplan_datum"
           android:layout_marginLeft="2dip"
           android:layout_marginTop="1dip"
           android:text="@string/beispielBereich"
           android:textSize="10dip" />

       <TextView
           android:id="@+id/dienstplan_uhrzeit"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_alignParentRight="true"
           android:layout_alignTop="@id/dienstplan_datum"
           android:layout_marginRight="5dip"
           android:gravity="right"
           android:text="@string/beispielUhrzeiten"
           android:textSize="12dip"
           android:textStyle="bold" />

       <TextView
           android:id="@+id/dienstplan_name"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_alignParentRight="true"
           android:layout_below="@+id/dienstplan_uhrzeit"
           android:layout_marginRight="3dip"
           android:layout_marginTop="4dip"
           android:text="@string/beispielVollstaendigerName"
           android:textSize="10dip" />
   </RelativeLayout>

</LinearLayout>
Und diese Activity setzt mein Adapter:


Code:
public class DienstplanActivity extends ListActivity  {
    private List<Arbeitsschicht> schichtListe;
    private DienstplanAdapter adapter;
    private Unternehmen unternehmen;
    
    private String vollerName;
    private String entfernen;
    private String annehmen;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        Intent intent = getIntent();
        vollerName = intent.getStringExtra("vollerName");
        setUnternehmen();
        setSchichtenliste();
        adapter = new DienstplanAdapter(this, schichtListe);
        setListAdapter(adapter);
        registerForContextMenu(getListView());


    }
    private void setUnternehmen() {
        unternehmen = UnternehmenSpeicher.getUnternehmen();

    }
    private void setSchichtenliste() {
        schichtListe = UnternehmenSpeicher.getTauschboersen_liste();
    }


    @Override
    public void onCreateContextMenu(ContextMenu menu, View v,
            ContextMenu.ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
        if (v.getId() == this.getListView().getId()) {
            AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
            Arbeitsschicht schicht = (Arbeitsschicht) getListView()
                    .getItemAtPosition(info.position);

            String abbrechen = (String) getResources().getString(
                    R.string.abbrechen);
            if (schicht.getMitarbeiter().getvollstaendigenNamen()
                    .equals(this.vollerName)) {
                String ihreSchicht = (String) getResources().getString(
                        R.string.dasIstIhreSchicht);
                entfernen = (String) getResources().getString(
                        R.string.entfernen);
                menu.setHeaderTitle(ihreSchicht);
                menu.add(0, 0, 0, entfernen);
                menu.add(0, 0, 0, abbrechen);
            } else {
                String arbeitschicht = (String) getResources().getString(
                        R.string.arbeitsschicht);
                annehmen = (String) getResources().getString(R.string.annehmen);
                menu.setHeaderTitle(arbeitschicht);
                menu.add(0, 0, 0, annehmen);
                menu.add(0, 0, 0, abbrechen);

            }

        }
    }
}
Wie ihr sehen koennt auf den Bildern bewegt sich die ganze Activity. :huh:

Ich weiß nicht was ich wie ich das hinbekomme.

Ich habe schon folgendes versucht:

Code:
        RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.diensitplan_zeiten);
        adapter = new DienstplanAdapter(relativeLayout.getContext(), schichtListe);
Aber da stuerzt das Programm ab.

Was muss ich machen?
 

Anhänge

  • Screenshot_2015-01-11-01-57-07.png
    Screenshot_2015-01-11-01-57-07.png
    152,3 KB · Aufrufe: 261
  • Screenshot_2015-01-11-01-57-14.png
    Screenshot_2015-01-11-01-57-14.png
    186,4 KB · Aufrufe: 180
Zurück
Oben Unten