-1

I have an application. On the result page there is a button. By clicking the button I want to show a filter option to the users so that they can filter the data !

SampleImage

I am not able to create this layout ,what i have to use for this to create the layout

Please help me with this

After using two listview the design is scattered look in the image TwoListViews

Pooja Dubey
  • 683
  • 2
  • 14
  • 34

3 Answers3

1

enter image description hereIn LinearLayout of Horizontal orientation, embedd the first ListView and assign a layout width of 50dp to 100dp(in bretween),Embedd the second ListView to the right of first ListView in the LinearLayout and assign width wrap_content

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="horizontal">

<ListView
    android:layout_width="84dp"
    android:layout_height="wrap_content"
    android:id="@+id/listView"
    android:layout_gravity="center_vertical" />

<ListView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/listView2"
    android:layout_gravity="center_vertical"
    android:layout_weight="1" />

Now design ListItems of both the lists as per your requirements.

After that relate the itemclickListener of your first ListView to the Second one like this : ListView lv1,lv2;

 lv1.setAdapter(new FirstListAdapter);
    lv1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            if(position==0){
                lv2.setAdapter(new AdapterA);
            }else if(position==1){
                lv2.setAdapter(new AdapteB);
            }

        }
    }); 

Based on the selection of first ListView Item you have to set the adapter of second ListView adapter. This is the basic idea rest do make sure that you clear listviews on time.

Udit Kapahi
  • 2,277
  • 1
  • 27
  • 25
  • how we will relate them and i want apply and clear button also .and should i use dialog to show this filter or should i use something else – Pooja Dubey May 28 '15 at 12:33
  • what do you want to filter ?.... is your filtered result is displayed on the side list ...... is the first listview's item are filter options – Udit Kapahi May 28 '15 at 12:36
  • this is exactly what i need but i am not getting it please elaborate more so that i can understand it and use it – Pooja Dubey May 28 '15 at 12:37
  • i have a result page on that there is a filter option on click of that i want to show a layout like this after clicking on the check boxes from the second list i want user to press apply button then i will send http request – Pooja Dubey May 28 '15 at 12:38
  • see first list is main category and second listview is sub category . – Pooja Dubey May 28 '15 at 12:44
  • It is very simple.. all you need to do is make a adapter ... let say AdapterA which will extend BaseAdapter.. design a listitem for the same consisting of a checkbox and a textview adjacent to each other ..come back to adapter a class... in its getView do add this thing holder.checkbox.setOnClickListener(). to make checkbox clickable. now when you want to use APPLY button in main activity.... now in the Button's on click listener add this... – Udit Kapahi May 28 '15 at 12:50
  • Continued previous comment SparseBooleanArray checked = list.getCheckedItemPositions(); for (int i = 0; i < list.getAdapter().getCount(); i++) { if (checked.get(i)) { // Do something } } – Udit Kapahi May 28 '15 at 12:51
  • Also CHECK THIS LINK FOR REFERENCE http://stackoverflow.com/questions/4831918/how-to-get-all-checked-items-from-a-listview – Udit Kapahi May 28 '15 at 12:55
  • I am not able add 2 buttons on the top right of the listviews with a logo and i don't want to use dialog to show this filter any other thing that we can use – Pooja Dubey May 29 '15 at 03:27
  • Use actionbar items or toolbar items(in case of lollipop)...... Please +1 the answer if it helped you – Udit Kapahi May 29 '15 at 07:40
  • will u please look into this question http://stackoverflow.com/questions/30679726/add-scrollview-and-highlight-on-a-linear-layout-in-android – Pooja Dubey Jun 06 '15 at 06:43
0

I think that this will help you. I Hope!

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    >


    <ListView
        android:layout_width="0dp"
        android:layout_weight="0.5"
        android:layout_height="wrap_content"
        android:id="@+id/listView2"
        android:layout_gravity="right"
        android:choiceMode="multipleChoice" />

    <ListView
        android:layout_weight="0.5"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:id="@+id/listView"
        android:choiceMode="multipleChoice" />
</LinearLayout>

enter image description here

Fartab
  • 4,725
  • 2
  • 26
  • 39
0

A simple way to do that is creating a custom dialog. You can create the dialog with a linear layout and add all the CheckedTextView you need.

final Dialog dialog=new Dialog(context);
dialog.setContentView(R.layout.custom_dialog);
dialog.setTitle("Your title");
CheckedTextView ctv=(CheckedTextView)dialog.findViewById(R.id.ctv);
Button ok=(Button)dialog.findViewById(R.id.button);
btn_blue.setOnClickListener(new View.OnClickListener() {
     @Override
     public void onClick(View v) {
         dialog.dismiss();
     }
});
dialog.show();

You will need to add to this code the listener for the checkedtextview and then pass as variable the status of those checks.

malaka
  • 85
  • 9