2 つではなく 1 つの項目のみを表示する ListView があります。それは私のMainActivityです:
public class MainActivity extends Activity {
ImageView Add;
ImageView Shadow;
ProgressBar PB;
ListView listView;
String[] valuesUp = { "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
"Sed non justo eros. Praesent a nisl dui" };
String[] valuesDown = { "Quisque ut ante eu arcu sagittis porta eu a dolor...",
"In orci augue facilisis eget fermentum consequat ac..." };
int[] imgValues = {R.drawable.mobileapp_16, R.drawable.mobileapp_19};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ArrayAdapter<String> adapter = new MyAdapter(this, valuesUp, valuesDown, imgValues);
listView = (ListView) findViewById(R.id.listView1);
listView.setAdapter(adapter);
}
それは私のアダプターです:
public class MyAdapter extends ArrayAdapter<String> {
private final Context context;
private final String[] valuesUp;
private final String[] valuesDown;
private final int[] ImageValue;
private TextView textViewUp;
private TextView textViewDown;
private ImageView image;
public MyAdapter(Context context, String[] valuesUP, String[] valuesDown, int[] imageValue) {
super(context, R.layout.rowlayout, valuesUP);
this.context = context;
this.valuesUp = valuesUP;
this.valuesDown = valuesDown;
this.ImageValue = imageValue;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView;
rowView = inflater.inflate(R.layout.rowlayout, parent, false);
textViewUp = (TextView) rowView.findViewById(R.id.row_text_view_up);
textViewDown = (TextView) rowView.findViewById(R.id.row_text_view_down);
image = (ImageView) rowView.findViewById(R.id.image);
textViewUp.setText(valuesUp[position]);
textViewDown.setText(valuesDown[position]);
image.setImageDrawable(context.getResources().getDrawable(ImageValue[position]));
return rowView;
}}
デバッグすると、getView が何度も呼び出され (約 12 回)、常に「位置」が 0 になっていることがわかります。ありがとう!
私は今私の問題を見つけました!それは奇妙だ。リストの高さがおかしい。「wrap_content または match_parent を実行すると、1 つのアイテムが返されますが、たとえば 400dp を入力すると問題ありません。なぜですか?! それが私の XML です:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/progress"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@drawable/topbar_bg" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageView1"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/topbar_leftcircle" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageView1"
android:layout_alignParentTop="true"
android:layout_marginLeft="5dp"
android:layout_toRightOf="@+id/imageView2"
android:src="@drawable/topbar_logo" />
<ImageView
android:id="@+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageView1"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="5dp"
android:scaleType="fitStart"
android:src="@drawable/topbar_menu" />
<ImageView
android:id="@+id/imageView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageView1"
android:layout_alignParentTop="true"
android:layout_marginRight="5dp"
android:layout_toLeftOf="@+id/imageView4"
android:src="@drawable/topbar_key" />
<ScrollView
android:id="@+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_below="@+id/imageView1"
android:layout_centerHorizontal="true" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView1"
android:layout_centerHorizontal="true"
android:background="#00000000"
android:src="@drawable/mobileapp_14" />
<ImageView
android:id="@+id/imageView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageButton1"
android:layout_centerHorizontal="true"
android:scaleType="fitXY"
android:src="@drawable/transparent_bg" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/imageView6"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:maxLines="2"
android:text="Sed at vestibulum elit. Nunc quam erat, gravida ac consequat"
android:textColor="@color/RedText"
android:textSize="15dp" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageButton1"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/textView1"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:maxLines="2"
android:text="Nullam sed erat erat, ut faucibus nunc. Etiam et mi di ante lacinia suscipit. Mauris gravida turpis eget lectus ullam..."
android:textColor="@color/WhiteText"
android:textSize="12dp" />
<ImageView
android:id="@+id/imageView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageButton1"
android:layout_centerHorizontal="true"
android:background="#00000000"
android:scaleType="centerCrop"
android:src="@drawable/mobileapp_15" />
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="600dp"
android:layout_below="@id/imageView7" >
</ListView>
</RelativeLayout>
</ScrollView>