Editing in the ListView

1

I created a separate xml to get better with the ListView .. I just can not relate its id to my onCreate

XML:

<?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">


    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@android:id/text1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceListItemSmall"
        android:gravity="center_vertical"
        android:paddingStart="?android:attr/listPreferredItemPaddingStart"
        android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
        android:minHeight="?android:attr/listPreferredItemHeightSmall"
        android:textColor="@color/corList"
        tools:targetApi="ice_cream_sandwich"
        android:paddingRight="?android:attr/listPreferredItemPaddingRight"
        android:paddingLeft="?android:attr/listPreferredItemPaddingLeft" />


</LinearLayout>

this xml is in /res/layout/modified_result.xml

Java:

package com.allsport.miyonic.allsport;

import android.support.v7.app.AppCompatActivity;
        import android.os.Bundle;
        import android.view.View;
        import android.widget.ArrayAdapter;
        import android.widget.Button;
        import android.widget.ListView;
import android.widget.TextView;

import java.util.List;

        import Base.DbHelper;
        import Base.Esporte;

        import static android.os.FileObserver.DELETE;

public class ResultSimples extends AppCompatActivity {

    private ListView lista;
    private Button apagar;
    public TextView txt;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_result_simples);

        lista = (ListView) findViewById(R.id.ListaTimes);
        apagar = (Button) findViewById(R.id.btndeletar);
        txt = (TextView) findViewById(R.id.text1); 
        apagar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DbHelper dd = new DbHelper(ResultSimples.this);
                dd.delete(); // É necessário passar o parâmetro
            }
        });
    }

    @Override
    public void onResume(){
        super.onResume();

        DbHelper dbhe = new DbHelper(this);
        List<Esporte> listaResultPartida = dbhe.selectTodosResult();

        ArrayAdapter<Esporte> adp = new ArrayAdapter<Esporte>(this, R.layout.resultado_modificado, listaResultPartida);

        lista.setAdapter(adp);
    }
}

Thank you ...

    
asked by anonymous 02.11.2016 / 16:57

1 answer

1

I got help from @Wakim, I needed to pass the id inside the Adpter constructor

this way:

@Override
    public void onResume(){
        super.onResume();

        DbHelper dbhe = new DbHelper(this);
        List<Esporte> listaResultPartida = dbhe.selectTodosResult();
        ArrayAdapter<Esporte> adp = new ArrayAdapter<Esporte>(this, R.layout.resultado_modificado, android.R.id.text1, listaResultPartida);

        lista.setAdapter(adp);
    }
}
    
02.11.2016 / 19:23