Search in sources :

Example 1 with OnHolderListener

use of com.orhanobut.dialogplus.OnHolderListener in project dialogplus by orhanobut.

the class GridHolderTest method testOnItemClick.

@Test
public void testOnItemClick() {
    GridHolder holder = getHolder();
    GridView view = (GridView) holder.getInflatedView();
    //there is no listener, it shouldn't crash
    view.performItemClick(null, 0, 0);
    //with adapter set
    ArrayAdapter<String> adapter = new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, new String[] { "test" });
    holder.setAdapter(adapter);
    view.performItemClick(null, 0, 0);
    //set listener
    holder.setOnItemClickListener(new OnHolderListener() {

        @Override
        public void onItemClick(Object item, View view, int position) {
            assertThat(String.valueOf(item)).isEqualTo("test");
            assertThat(position).isEqualTo(0);
            assertThat(view).isNull();
        }
    });
    view.performItemClick(null, 0, 0);
}
Also used : OnHolderListener(com.orhanobut.dialogplus.OnHolderListener) GridView(android.widget.GridView) GridHolder(com.orhanobut.dialogplus.GridHolder) GridView(android.widget.GridView) View(android.view.View) ArrayAdapter(android.widget.ArrayAdapter) Test(org.junit.Test)

Example 2 with OnHolderListener

use of com.orhanobut.dialogplus.OnHolderListener in project dialogplus by orhanobut.

the class ListHolderTest method testOnItemClick.

@Test
public void testOnItemClick() {
    ListHolder holder = getListHolder();
    ListView listView = (ListView) holder.getInflatedView();
    //with adapter set
    ArrayAdapter<String> adapter = new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, new String[] { "test" });
    holder.setAdapter(adapter);
    //set listener
    holder.setOnItemClickListener(new OnHolderListener() {

        @Override
        public void onItemClick(Object item, View view, int position) {
            assertThat(String.valueOf(item)).isEqualTo("test");
            assertThat(position).isEqualTo(0);
            assertThat(view).isNull();
        }
    });
    listView.performItemClick(null, 0, 0);
}
Also used : OnHolderListener(com.orhanobut.dialogplus.OnHolderListener) ListView(android.widget.ListView) View(android.view.View) ListView(android.widget.ListView) ListHolder(com.orhanobut.dialogplus.ListHolder) ArrayAdapter(android.widget.ArrayAdapter) Test(org.junit.Test)

Example 3 with OnHolderListener

use of com.orhanobut.dialogplus.OnHolderListener in project dialogplus by orhanobut.

the class ListHolderTest method doNotCountHeaderForPositionCalculation.

@Test
public void doNotCountHeaderForPositionCalculation() {
    ListHolder holder = getListHolder();
    holder.addHeader(new View(context));
    ListView listView = (ListView) holder.getInflatedView();
    //with adapter set
    ArrayAdapter<String> adapter = new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, new String[] { "test" });
    holder.setAdapter(adapter);
    //set listener
    holder.setOnItemClickListener(new OnHolderListener() {

        @Override
        public void onItemClick(Object item, View view, int position) {
            assertThat(String.valueOf(item)).isEqualTo("test");
            assertThat(position).isEqualTo(0);
            assertThat(view).isNull();
        }
    });
    listView.performItemClick(null, 1, 0);
}
Also used : OnHolderListener(com.orhanobut.dialogplus.OnHolderListener) ListView(android.widget.ListView) View(android.view.View) ListView(android.widget.ListView) ListHolder(com.orhanobut.dialogplus.ListHolder) ArrayAdapter(android.widget.ArrayAdapter) Test(org.junit.Test)

Aggregations

View (android.view.View)3 ArrayAdapter (android.widget.ArrayAdapter)3 OnHolderListener (com.orhanobut.dialogplus.OnHolderListener)3 Test (org.junit.Test)3 ListView (android.widget.ListView)2 ListHolder (com.orhanobut.dialogplus.ListHolder)2 GridView (android.widget.GridView)1 GridHolder (com.orhanobut.dialogplus.GridHolder)1