0

Zodiac Sign Imageのようなカスタムデータを表示したいリストビューがあります。ゾディアック タイトル。Zodiac コンテンツといくつかのボタン。問題は、データが表示されないことです。すべての行をデバッグし、アイテムが適切に配列リストに追加され、次にアダプターに追加されますが、リストビューは画面に空で表示されます。

私はandroid google api17ジェリービーンズバージョンを使用しています

私のメイン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>

マイ ListRow XML

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

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;
}

反応を待っています

前もって感謝します

4

2 に答える 2

2

ZodicAdapter クラスの getCount() では、0 として返されます。

それを次のようにします

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return items.size();
}
于 2012-12-12T20:50:33.567 に答える
0

に戻っ0getCount()いるため、リストはアダプタに項目がないと見なしています。

于 2012-12-12T20:48:55.247 に答える