Пользовательские элементы списка Listview не отображаются

У меня есть список, в котором я хочу отображать пользовательские данные, такие как изображение знака зодиака. Зодиакальный титул. Zodiac Content и несколько кнопок. Проблема в том, что данные не отображаются. Я отлаживаю каждую строку, и элементы правильно добавляются в массив, а затем в адаптер, но список отображается пустым на экране.

Я использую версию Android google api17 jelly beans

Мой основной XML

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/tools"
    android:id="@+id/scrollView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    app:context=".AdminPage.Hilariouscope" >

    <TableLayout
        android:id="@+id/tableRow_Main"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TableRow
            android:id="@+id/tableRow_tittle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <RelativeLayout
                android:id="@+id/Relativelayout_watch"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="1" >

                <Button
                    android:id="@+id/btn_topic_horro_Back"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="GoToHome"
                    android:text="@string/RegisterBack" />

                <TextView
                    android:id="@+id/txt_title_screen"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignBaseline="@+id/btn_topic_horro_Back"
                    android:layout_alignBottom="@+id/btn_topic_horro_Back"
                    android:layout_centerHorizontal="true"
                    android:text="@string/title_activity_hilariouscope"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

            </RelativeLayout>

        </TableRow>

        <ListView
            android:id="@+id/horror_listview"
            android:layout_width="wrap_content"
            android:layout_height="371dp" >
        </ListView>

    </TableLayout>

</ScrollView>

Мой XML-файл ListRow

  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<TextView
    android:id="@+id/txt_zodic_Tittle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:text="Large Text"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textColor="#ab2130"
    android:textSize="32sp" />

<TextView
    android:id="@+id/txt_zodic_date"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/txt_zodic_Tittle"
    android:text="Medium Text"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<TableRow
    android:id="@+id/tableRow_content"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/txt_zodic_date" >

    <TextView
        android:id="@+id/txt_main_content"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight=".2"
        android:text="@string/Main_laugh"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textSize="22sp"
        android:textStyle="normal" />

    <ImageView
        android:id="@+id/zodic_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight=".5"
        android:adjustViewBounds="true"
        android:cropToPadding="true"
        android:scaleType="fitCenter"
        android:src="@drawable/lighthouse" />

</TableRow>

<TableRow
    android:id="@+id/tableRow_footer"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true" >

    <RelativeLayout
        android:id="@+id/RelativeLayout03"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:background="#bababa" >

        <Button
            android:id="@+id/Btn_share_fun"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Share"
            app:ignore="HardcodedText" />

        <ImageButton
            android:id="@+id/btn_facebook_fun"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_toLeftOf="@+id/btn_twitter_fun"
            android:src="@drawable/pic2"
            app:ignore="ContentDescription" />

        <ImageButton
            android:id="@+id/btn_twitter_fun"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignTop="@+id/btn_facebook_fun"
            android:src="@drawable/pic3"
            app:ignore="ContentDescription" />
    </RelativeLayout>
</TableRow>

My custom Class For Zodic

public class Hilariouscope_Items {
private boolean checked;
private int zodicImage;
private String ZodicDate, ZodicTitle, ZodicContent;

public Hilariouscope_Items(String Title, String Date, String Content) {
    this.ZodicTitle = Title;
    // this.zodicImage = ZodicImage;
    this.ZodicDate = Date;
    this.ZodicContent = Content;
}

public void setChecked(boolean checked) {
    this.checked = checked;
}

public boolean isChecked() {
    return checked;
}

public void setTitleName(String name) {
    this.ZodicTitle = name;
}

public void setZodicDate(String date) {
    this.ZodicDate = date;
}

public void setZodicContent(String Content_Text) {
    this.ZodicContent = Content_Text;
}

public String getTitle() {
    return ZodicTitle;
}

public String getZodicDate() {
    return ZodicDate;
}

public String getZodicContent() {
    return ZodicContent;
}

public void toggle() {
    this.checked = !this.checked;
}

public int getZodicImage() {
    return zodicImage;
}

Мой класс ZodicAdapter

import java.util.List;
import com.example.laysapp.R;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


 public class horrorItemAdapter extends BaseAdapter {

private final List<Hilariouscope_Items> items;

public horrorItemAdapter(final Context context, final int itemResId,
        final List<Hilariouscope_Items> items) {
    this.items = items;
}

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return 0;
}

@Override
public Object getItem(int arg0) {
    // TODO Auto-generated method stub
    return null;
}

@Override
public long getItemId(int position) {
    // TODO Auto-generated method stub
    return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final Hilariouscope_Items item = this.items.get(position);
    View itemView = null;

    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) parent.getContext()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        itemView = inflater.inflate(R.layout.horror_list_row, null);
    } else {
        itemView = convertView;
    }

    // Set the text of the item
    TextView txtName = (TextView) itemView
            .findViewById(R.id.txt_zodic_Tittle);
    txtName.setText(item.getTitle());

    // Set the text of the item
    TextView txtDate = (TextView) itemView
            .findViewById(R.id.txt_zodic_date);
    txtDate.setText(item.getZodicDate());

    // Set the text of the item
    TextView txtContent = (TextView) itemView
            .findViewById(R.id.txt_main_content);
    txtContent.setText(item.getZodicContent());

    // Set the check-icon
    ImageView imgView = (ImageView) itemView.findViewById(R.id.zodic_image);

    imgView.setImageResource(item.getZodicImage());
    /*
     * imgViewChecked.setImageResource(item.isChecked() ? R.drawable.checked
     * : R.drawable.unchecked);
     */
    return itemView;
}

 }

Мой основной класс

    public class Hilariouscope extends Activity {

private ListView mainListView;
private horrorItemAdapter itemAdapter;
private ArrayAdapter<Hilariouscope_Items> listAdapter;

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

    ArrayList<Hilariouscope_Items> items = new ArrayList<Hilariouscope_Items>();
    /*
     * items.add(new Hilariouscope_Items("AQUARIUS", R.drawable.hydrangeas,
     * "MAR 21 - APR 19", "sample text Aquarius")); items.add(new
     * Hilariouscope_Items("Aries", R.drawable.jellyfish, "MAR 21 – APR 20",
     * "sample text Aries")); items.add(new Hilariouscope_Items("Taurus",
     * R.drawable.penguins, "APR 21 – MAY 21", "sample text Taurus"));
     * items.add(new Hilariouscope_Items("Gemini", R.drawable.lighthouse,
     * "MAY 22 – JUN 21", "sample text Gemini"));
     */

    items.add(new Hilariouscope_Items("AQUARIUS", "MAR 21 - APR 19",
            "sample text Aquarius"));
    items.add(new Hilariouscope_Items("Aries", "MAR 21 – APR 20",
            "sample text Aries"));
    items.add(new Hilariouscope_Items("Taurus", "APR 21 – MAY 21",
            "sample text Taurus"));
    items.add(new Hilariouscope_Items("Gemini", "MAY 22 – JUN 21",
            "sample text Gemini"));

    itemAdapter = new horrorItemAdapter(getApplicationContext(),
            R.layout.horror_list_row, items);

    mainListView = (ListView) findViewById(R.id.horror_listview);
    // listAdapter = new ArrayAdapter<Hilariouscope_Items>(this,
    // R.layout.horror_list_row, items);
    mainListView.setAdapter(itemAdapter);
    /*
     * View header = (View) getLayoutInflater().inflate(
     * R.layout.horror_list_row, null);
     * 
     * lv.addHeaderView(header);
     */

    mainListView.setTextFilterEnabled(true);
    mainListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapter, View v, int pos,
                long id) {

            // Toggle the state of the item and refresh the view
            /*
             * Hilariouscope_Items item = (Hilariouscope_Items) mainListView
             * .getItemAtPosition(pos);
             * Toast.makeText(getApplicationContext(),
             * item.getTitle().toString(), Toast.LENGTH_SHORT).show(); //
             * itemAdapter.notifyDataSetChanged();
             */
        }

    });

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_hilariouscope, menu);
    return true;
}

жду вашего ответа

заранее спасибо


person Aftab Ali    schedule 12.12.2012    source источник
comment
getCount() вы возвращаете как 0.   -  person Padma Kumar    schedule 13.12.2012
comment
Вы используете ListView в ScrollView, по мере роста вашего списка вы не сможете увидеть весь ListView, так как эти представления будут сражаться друг с другом...   -  person Sam    schedule 13.12.2012


Ответы (2)


В вашем классе ZodicAdapter getCount() вы возвращаете значение 0.

сделай это как

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return items.size();
}
person Padma Kumar    schedule 12.12.2012

Вы возвращаете 0 в getCount(), поэтому список считает, что в адаптере нет элементов.

person Ridcully    schedule 12.12.2012