Reputation: 127
Everything seems to be okay (other than being quite laggy) except the fact that I am unable to see the last few views of my ListView app. I tried to change the height of my custom view layout for each ListView item and I realized that the smaller the height, the more views I could not see. This meant that there was a fixed length of height at the bottom of my ListView that I am unable to scroll to and I have no idea why.
Code from MainActivity.java
public class MainActivity extends AppCompatActivity {
String[] titles;
String[] descriptions;
int[] drawables = {R.drawable.number0, R.drawable.number2, R.drawable.number3, R.drawable.number4, R.drawable.number5, R.drawable.number6, R.drawable.number7, R.drawable.number8, R.drawable.number9, R.drawable.number10};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Resources res = getResources();
titles = res.getStringArray(R.array.title);
descriptions = res.getStringArray(R.array.description);
ListView l = (ListView) findViewById(R.id.listview);
myadapter myadapter = new myadapter(this, titles, drawables, descriptions);
l.setAdapter(myadapter);
}
}
class myadapter extends ArrayAdapter<String>{
Context c;
int[] drawables;
String[] titles;
String[] descriptions;
public myadapter(Context context, String[] titles, int[] drawables, String[] descriptions ) {
super(context,R.layout.single_row, R.id.title,titles);
c=context;
this.drawables = drawables;
this.titles = titles;
this.descriptions = descriptions;
}
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater i = (LayoutInflater) c.getSystemService(c.LAYOUT_INFLATER_SERVICE);
v = i.inflate(R.layout.single_row, parent, false);
}
ImageView image = (ImageView) v.findViewById(R.id.image);
TextView title = (TextView) v.findViewById(R.id.title);
TextView description = (TextView) v.findViewById(R.id.description);
image.setImageResource(drawables[position]);
title.setText(titles[position]);
description.setText(descriptions[position]);
return v;
}
}
Code from custom layout xml file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/relative_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
<ImageView
android:id="@+id/image"
android:layout_width="90dp"
android:layout_height="90dp"
app:srcCompat="@drawable/number0" />
<TextView
android:id="@+id/title"
android:layout_width="332dp"
android:layout_height="36dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_toEndOf="@+id/image"
android:layout_toRightOf="@+id/image" />
<TextView
android:id="@+id/description"
android:layout_width="320dp"
android:layout_height="49dp"
android:layout_below="@+id/title"
android:layout_alignStart="@id/title"
android:layout_alignLeft="@id/title"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_toEndOf="@+id/image"
android:layout_toRightOf="@+id/image" />
</RelativeLayout>
The activity_main.xml file simply contains a listview.
Upvotes: 2
Views: 60
Reputation: 467
the video tutorial uses a png file format, he might have used smaller files instead. Your list view might be slow because it takes time to draw so many resources to display it? Did u try just displaying the text only?
sorry this is more like a comment than a answer, but I can't post comments till I've reached 50 reps
Upvotes: 1