My simple HorizontalListView implementation for my Android applications. Warning : it is really simple but not optimized. But it still can be really useful, depending on your needs.
- Import project
- Select repository folder
- Use auto import + use default gradle wrapper
- Add the file HorizontalListView.java file in your project.
- Include the
HorizontalListView
in your layout file :
<com.remifayolle.horizontallistviewsample.HorizontalListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
- In your activity or fragment, implement the
HorizontalListView.OnClickListener
and initialize the listView with an adapter and theOnClickListener
:
public class MainActivity extends Activity implements HorizontalListView.OnListItemClickListener {
private BaseAdapter mAdapter = null;
private HorizontalListView mListView = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Get list view
mListView = (HorizontalListView)findViewById(R.id.listview);
// Create adapter
mAdapter = new BaseAdapter();
// Bind adapter to listview
if (mListView != null) {
mListView.setAdapter(mAdapter);
mListView.registerListItemClickListener(this);
}
else {
Log.e(TAG, "HorizontalListView not found");
}
}
/* ... */
@Override
public void onClick(View v, int position) {
Toast.makeText(this, "Click " + String.valueOf(position), Toast.LENGTH_SHORT).show();
}
}
See LICENSE