Android列表查看Scrollview内未显示的所有项目

时间:2017-05-11 10:18:41

标签: android listview

我提出了两个listviews并使用json数组获取项目。我想看到我的所有listview项目,但只显示几个项目。第一个listview必须有5个项目,第二个listview必须有12个项目。我怎样才能解决这个问题 ? 这是我的结果屏幕: enter image description here

这是我的适配器代码:

public class ParcaAdapter extends BaseAdapter {

private LayoutInflater inflater;
private List<Parcalar> parcaBilgileri;

public ParcaAdapter(Activity activity, List<Parcalar> parca)
{
    //XML'i alıp View'a çevirecek inflater'ı örnekleyelim
    inflater = (LayoutInflater) activity.getSystemService(
            Context.LAYOUT_INFLATER_SERVICE);
    parcaBilgileri = parca;
}
public int getCount() {
    return parcaBilgileri.size();
}

public Object getItem(int position) {
    return parcaBilgileri.get(position);
}

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

public View getView(int position, View convertView, ViewGroup parent) {
    View satirView;

    satirView = inflater.inflate(R.layout.parcalar_list, null);
    TextView txtTalepTarihi = (TextView)     satirView.findViewById(R.id.txtTalepTarihi);
    TextView txtParca = (TextView) satirView.findViewById(R.id.txtParca);
    TextView txtMiktar = (TextView)     satirView.findViewById(R.id.txtMiktar);
    TextView txtIadeDurumu = (TextView)     satirView.findViewById(R.id.txtIadeDurumu);
    TextView txtAciklama = (TextView)     satirView.findViewById(R.id.txtAciklama);
    TextView txtSonuc = (TextView) satirView.findViewById(R.id.txtSonuc);
    TextView txtSonucTarihi = (TextView)     satirView.findViewById(R.id.txtSonucTarihi);

    Parcalar bilgi = parcaBilgileri.get(position);

    txtTalepTarihi.setText(bilgi.gettaleptarihi());
    txtParca.setText(bilgi.getparca());
    txtMiktar.setText(bilgi.getmiktar());
    txtIadeDurumu.setText(bilgi.getiadedurumu());
    txtAciklama.setText(bilgi.getaciklama());
    txtSonuc.setText(bilgi.getsonuc());
    txtSonucTarihi.setText(bilgi.getsonuctarihi());

    return satirView;
}
}

列出获取数据的类:

public class Parcalar {
private String taleptarihi;
private String parca;
private String miktar;
private String iadedurumu;
private String aciklama;
private String sonuc;
private String sonuctarihi;

public Parcalar(String taleptarihi, String parca, String miktar, String     iadedurumu, String aciklama, String sonuc, String sonuctarihi) {
    super();
    this.taleptarihi = taleptarihi;
    this.parca = parca;
    this.miktar = miktar;
    this.iadedurumu = iadedurumu;
    this.aciklama = aciklama;
    this.sonuc = sonuc;
    this.sonuctarihi = sonuctarihi;
}

public String gettaleptarihi() {
    return taleptarihi;
}

public String getparca() {
    return parca;
}

public String getmiktar() {
    return miktar;
}

public String getiadedurumu() {
    return iadedurumu;
}

public String getaciklama() {
    return aciklama;
}

public String getsonuc() {
    return sonuc;
}

public String getsonuctarihi() {
    return sonuctarihi;
}
}

和.xml:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/scroll"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:layout_width="match_parent"
android:layout_height="fill_parent">

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingLeft="5dp"
    android:paddingRight="5dp"
        tools:context="com.example.cagri.mobilyateknikservis.BildirimActivity"
    android:orientation="vertical"
    android:id="@+id/activity_bildirim">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:text="Müşteri:"
            android:background="@android:color/background_light"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/MusteriAdi"
            android:layout_alignParentTop="true"
            android:layout_alignParentStart="true"
            android:textColor="@android:color/holo_red_dark"
            android:textStyle="normal|bold"
            android:layout_weight="1"
            android:gravity="center_vertical" />

        <TextView
            android:text="TextView"
            android:background="@android:color/background_light"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/txtMusteri"
            android:layout_weight="1"
            android:textSize="12sp"
            android:textColor="@android:color/background_dark"
            android:textAlignment="textStart" />

        <TextView
            android:text="Hizmet Tipi:"
            android:background="@android:color/background_light"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/HizmetTipi"
            android:textColor="@android:color/holo_red_dark"
            android:layout_alignParentTop="true"
            android:textStyle="normal|bold"
            android:layout_weight="1" />

        <TextView
            android:text="TextView"
            android:background="@android:color/background_light"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/txtHizmetTipi"
            android:layout_weight="1"
            android:textSize="12sp"
            android:textColor="@android:color/background_dark"
            android:textAlignment="textStart" />

        <TextView
            android:text="Sipariş Ref. No."
            android:background="@android:color/background_light"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/SiparisRef"
            android:textColor="@android:color/holo_red_dark"
            android:layout_alignParentTop="true"
            android:textStyle="normal|bold"
            android:layout_weight="1" />

        <TextView
            android:text="TextView"
            android:background="@android:color/background_light"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/txtSiparisRef"
            android:layout_weight="1"
            android:textSize="12sp"
            android:textColor="@android:color/background_dark"
            android:textAlignment="textStart" />

    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:text="Firma:"
            android:background="@android:color/background_light"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/Firma"
            android:layout_weight="1"
            android:textColor="@android:color/holo_red_dark"
            android:textStyle="normal|bold" />

        <TextView
            android:text="Firma"
            android:background="@android:color/background_light"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/txtFirma"
            android:layout_weight="2"
            android:textColor="@android:color/background_dark"
            android:textSize="12sp"
            android:textAlignment="viewStart" />

        <TextView
            android:text="Sipariş Tarihi:"
            android:background="@android:color/background_light"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/SiparisTarihi"
            android:layout_weight="1"
            android:textColor="@android:color/holo_red_dark"
            android:textStyle="normal|bold" />

        <TextView
            android:text="Sipariş Tarihi"
            android:background="@android:color/background_light"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/txtSiparisTarihi"
            android:layout_weight="2"
            android:textColor="@android:color/background_dark"
            android:textSize="12sp"
            android:textAlignment="viewStart" />

        <TextView
            android:text="Teslim Tarihi:"
            android:background="@android:color/background_light"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/TeslimTarihi"
            android:layout_weight="1"
            android:textColor="@android:color/holo_red_dark"
            android:textStyle="normal|bold" />

        <TextView
            android:text="Teslim Tarihi"
            android:background="@android:color/background_light"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/txtTeslimTarihi"
            android:layout_weight="2"
            android:textColor="@android:color/background_dark"
            android:textSize="12sp"
            android:textAlignment="viewStart" />

    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:text="Depo:"
            android:background="@android:color/background_light"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/Depo"
            android:layout_weight="1"
            android:textColor="@android:color/holo_red_dark"
            android:textStyle="normal|bold" />

        <TextView
            android:text="Depo"
            android:background="@android:color/background_light"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:id="@+id/txtDepo"
            android:layout_weight="0.98"
            android:textColor="@android:color/background_dark"
            android:textSize="12sp"
            android:gravity="center_vertical" />

        <TextView
            android:text="Telefon:"
            android:background="@android:color/background_light"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/Telefon"
            android:layout_weight="1"
            android:textStyle="normal|bold"
            android:textColor="@android:color/holo_red_dark"
            android:textAlignment="viewStart" />

        <TextView
            android:text="Telefon"
            android:background="@android:color/background_light"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:id="@+id/txtTelefon"
            android:layout_weight="8.5"
            android:textSize="12sp"
            android:textColor="@android:color/background_dark"
            android:gravity="center_vertical" />

    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:text="Adres:"
            android:background="@android:color/background_light"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:id="@+id/Adres"
            android:layout_weight="0.99"
            android:textStyle="normal|bold"
            android:textColor="@android:color/holo_red_dark"
            android:textAllCaps="false"
            android:gravity="center_vertical" />

        <TextView
            android:text="Adres"
            android:background="@android:color/background_light"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:id="@+id/txtAdres"
            android:layout_weight="14.01"
            android:textSize="12sp"
            android:textColor="@android:color/background_dark"
            android:gravity="center_vertical" />
    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:text="Açıklama:"
            android:background="@android:color/background_light"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:id="@+id/Aciklama"
            android:layout_weight="1"
            android:textStyle="normal|bold"
            android:textColor="@android:color/holo_red_dark"
            android:gravity="center_vertical" />

        <TextView
            android:text="Açıklama"
            android:background="@android:color/background_light"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:id="@+id/txtAciklama"
            android:layout_weight="9"
            android:textColor="@android:color/background_dark"
            android:textSize="12sp"
            android:gravity="center_vertical" />

    </LinearLayout>

    <TextView
        android:text="İŞLEMLER"
        android:layout_width="match_parent"
        android:gravity="center_vertical"
        android:id="@+id/Islemler"
        android:textAlignment="center"
        android:background="@android:color/white"
        android:textColor="@color/colorAccent"
        android:layout_height="30dp" />

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:layout_height="match_parent">

        <TextView
            android:text="İşlem"
            android:background="@android:color/background_light"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/Islem"
            android:layout_weight="1"
            android:textAlignment="textStart"
            android:textColor="@android:color/holo_red_dark"
            android:maxWidth="100dp"
            android:minWidth="100dp"
            android:width="100dp" />

        <TextView
            android:text="Açıklama"
            android:background="@android:color/background_light"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/Aciklama2"
            android:layout_weight="4"
            android:textAlignment="textStart"
            android:textColor="@android:color/holo_red_dark"
            android:minWidth="180dp"
            android:width="180dp"
            android:maxWidth="180dp" />

        <TextView
            android:text="Sonuç"
            android:background="@android:color/background_light"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/Sonuc"
            android:layout_weight="1.7"
            android:textAlignment="textStart"
            android:textColor="@android:color/holo_red_dark" />

        <TextView
            android:text="Sonuç Tarihi"
            android:background="@android:color/background_light"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/SonucTarihi"
            android:layout_weight="1"
            android:textAlignment="center"
            android:textColor="@android:color/holo_red_dark" />
    </LinearLayout>

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:listSelector="@android:color/white"
        android:background="@android:color/white"
        android:id="@+id/lstIsl"
        android:layout_weight="1"
        android:scrollbars="none" />

    <TextView
        android:text="PARÇALAR"
        android:layout_width="match_parent"
        android:id="@+id/Parcalar"
        android:gravity="center_vertical"
        android:textAlignment="center"
        android:background="@android:color/white"
        android:textColor="@color/colorAccent"
        android:layout_height="30dp" />

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:text="Talep Tarihi"
            android:background="@android:color/background_light"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/textView8"
            android:layout_weight="1"
            android:textColor="@android:color/holo_red_dark"
            android:textAlignment="textStart" />

        <TextView
            android:text="Parça"
            android:background="@android:color/background_light"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/textView7"
            android:layout_weight="1"
            android:textAlignment="textStart"
            android:textColor="@android:color/holo_red_dark" />

        <TextView
            android:text="Miktar"
            android:background="@android:color/background_light"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/textView6"
            android:layout_weight="1"
            android:textAlignment="textStart"
            android:textColor="@android:color/holo_red_dark" />

        <TextView
            android:text="İade Durumu"
            android:background="@android:color/background_light"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/textView5"
            android:layout_weight="1"
            android:textColor="@android:color/holo_red_dark"
            android:textAlignment="textStart" />

        <TextView
            android:text="Açıklama"
            android:background="@android:color/background_light"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/textView4"
            android:layout_weight="1"
            android:textAlignment="textStart"
            android:textColor="@android:color/holo_red_dark" />

        <TextView
            android:text="Sonuç"
            android:background="@android:color/background_light"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/textView3"
            android:layout_weight="1"
            android:textAlignment="textStart"
            android:textColor="@android:color/holo_red_dark" />

        <TextView
            android:text="Sonuç Tarihi"
            android:background="@android:color/background_light"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/textView2"
            android:layout_weight="1"
            android:textAlignment="textStart"
            android:textColor="@android:color/holo_red_dark" />
    </LinearLayout>

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:listSelector="@android:color/white"
        android:background="@android:color/white"
        android:id="@+id/lstParcalar"
        android:scrollbars="none" />

</LinearLayout>

</ScrollView>

更新 这是我自定义的listview .xml代码之一:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
    android:text="TextView"
    android:background="@android:color/background_light"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/txtTalepTarihi"
    android:layout_weight="1"
    android:maxWidth="100dp"
    android:minWidth="100dp"
    android:width="100dp" />

<TextView
    android:text="TextView"
    android:background="@android:color/background_light"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/txtParca"
    android:layout_weight="1"
    android:width="100dp"
    android:minWidth="100dp"
    android:maxWidth="100dp" />

<TextView
    android:text="TextView"
    android:background="@android:color/background_light"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/txtMiktar"
    android:layout_weight="1"
    android:maxWidth="100dp"
    android:minWidth="100dp"
    android:width="100dp" />

<TextView
    android:text="TextView"
    android:background="@android:color/background_light"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/txtIadeDurumu"
    android:layout_weight="1"
    android:width="100dp"
    android:minWidth="100dp"
    android:maxWidth="100dp" />

<TextView
    android:text="TextView"
    android:background="@android:color/background_light"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/txtAciklama"
    android:layout_weight="1"
    android:minWidth="100dp"
    android:maxWidth="100dp"
    android:width="100dp"
    android:maxLength="15" />

<TextView
    android:text="TextView"
    android:background="@android:color/background_light"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/txtSonuc"
    android:layout_weight="1"
    android:width="100dp"
    android:minWidth="100dp"
    android:maxWidth="100dp" />

<TextView
    android:text="TextView"
    android:background="@android:color/background_light"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/txtSonucTarihi"
    android:layout_weight="1"
    android:maxWidth="100dp"
    android:minWidth="100dp"
    android:width="100dp" />
</LinearLayout>

和我的onCreate方法:

public class BildirimActivity extends LoginActivity {

public List<IslemBilgiler> islemBilgiler = new ArrayList<>();
public static boolean mState = false;
static String bildirimGiris;
public static String sorun;
public static List<Parcalar> parcaBilgiler = new ArrayList<>();
public static String ekipID, ekipKod;
static boolean bitir;
static IslemAdapter islemAdapter;
static ParcaAdapter parcaAdapter;
MyScrollListView lstIslemler;
MyScrollListView lstParcalar;
public static Menu menu;
TextView txtTeslimTarihi, txtAciklama, txtFirma, txtTelefon, txtMusteri,     txtHizmetTipi, txtDepo, txtAdres, txtSiparisTarihi, txtSiparisRefNo;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_bildirim);
    lstIslemler = (MyScrollListView)findViewById(R.id.lstIsl);
    islemAdapter = new IslemAdapter(this, islemBilgiler);
    lstParcalar = (MyScrollListView)findViewById(R.id.lstParcalar);
    parcaAdapter = new ParcaAdapter(this, parcaBilgiler);
    txtTeslimTarihi = (TextView)findViewById(R.id.txtTeslimTarihi);
    txtAciklama = (TextView)findViewById(R.id.txtAciklama);
    txtFirma = (TextView)findViewById(R.id.txtFirma);
    txtTelefon = (TextView)findViewById(R.id.txtTelefon);
    txtMusteri = (TextView)findViewById(R.id.txtMusteri);
    txtHizmetTipi = (TextView)findViewById(R.id.txtHizmetTipi);
    txtDepo = (TextView)findViewById(R.id.txtDepo);
    txtAdres = (TextView)findViewById(R.id.txtAdres);
    txtSiparisTarihi = (TextView)findViewById(R.id.txtSiparisTarihi);
    txtSiparisRefNo = (TextView)findViewById(R.id.txtSiparisRef);
    new BildirimleriGetir().execute();
}

1 个答案:

答案 0 :(得分:2)

您必须创建自定义列表视图:

  public class MyScrollListView extends ListView {

            public MyScrollListView(Context context) {
                super(context);
            }
            public MyScrollListView(Context context, AttributeSet attrs) {
                super(context, attrs);
            }
            public MyScrollListView(Context context, AttributeSet attrs, int defStyle) {
                super(context, attrs, defStyle);
            }
            @Override
            public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                int heightMeasureSpec_custom = MeasureSpec.makeMeasureSpec(
                        Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
                super.onMeasure(widthMeasureSpec, heightMeasureSpec_custom);
                ViewGroup.LayoutParams params = getLayoutParams();
                params.height = getMeasuredHeight();
            }
        }

并且需要在scrollview中使用:

   <com.yourpackege.MyScrollListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:listSelector="@android:color/white"
        android:background="@android:color/white"
        android:id="@+id/lstIsl"
        android:layout_weight="1"
        android:scrollbars="none" />

<com.yourpackege.MyScrollListView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:listSelector="@android:color/white"
    android:background="@android:color/white"
    android:id="@+id/lstParcalar"
    android:scrollbars="none" />

在您的活动中找到列表视图并使用它。

    MyScrollListView listView = (MyScrollListView)findViewById(R.id.....);