I'm adding a launcher with about 10 icons to my application and got it to work vertically but can't find a solid simple solution to rotate it so that it scrolls the 10 icons horizontally.
Java:
private PackageManager manager;
private List<AppDetail> apps;
private ListView list;
private void loadListView(){
//list = (ListView)findViewById(R.id.apps_list);//was apps_list
list = (ListView) findViewById(R.id.apps_list);//was apps_list
ArrayAdapter<AppDetail> adapter = new ArrayAdapter<AppDetail>(this,
R.layout.list_item,
apps) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null){
convertView = getLayoutInflater().inflate(R.layout.list_item, null);
}
ImageView appIcon = (ImageView)convertView.findViewById(R.id.item_app_icon);
appIcon.setImageDrawable(apps.get(position).icon);
TextView appLabel = (TextView)convertView.findViewById(R.id.item_app_label);
appLabel.setText(apps.get(position).label);
TextView appName = (TextView)convertView.findViewById(R.id.item_app_name);
appName.setText(apps.get(position).name);
return convertView;
}
};
list.setAdapter(adapter); //Put the list on the screen
}
Inside the XML Layout
<ListView
android:id="@+id/apps_list"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="50dp"
android:layout_marginEnd="29dp"
android:orientation="horizontal"/>
I saw something called a HorizontalScrollView but it doesn't seem to be a direct replacement and just crashes the app.
It looks like I'm supposed to use a RecyclerView and maybe something like this.
Java:
private void loadListView(){
mRecyclerView = (RecyclerView) findViewById(R.id.apps_list);
ArrayAdapter<AppDetail> mAdapter = new ArrayAdapter<AppDetail>(this,
R.layout.list_item,
apps) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null){
convertView = getLayoutInflater().inflate(R.layout.list_item, null);
}
ImageView appIcon = (ImageView)convertView.findViewById(R.id.item_app_icon);
appIcon.setImageDrawable(apps.get(position).icon);
TextView appLabel = (TextView)convertView.findViewById(R.id.item_app_label);
appLabel.setText(apps.get(position).label);
TextView appName = (TextView)convertView.findViewById(R.id.item_app_name);
appName.setText(apps.get(position).name);
return convertView;
}
};
mRecyclerView.setAdapter(mAdapter); //Put the list on the screen
}
XML:
<android.support.v7.widget.RecyclerView
android:id="@+id/apps_list"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="50dp"
android:layout_marginEnd="29dp"
android:orientation="horizontal"
android:scrollbars="horizontal"/>
but I'm getting the error:
Error:(1212, 34) error: incompatible types: ArrayAdapter cannot be converted to Adapter
Thanks for any guidance.