-1

I have 20 images and 20 icons to set in the List view. I know all the procedure How to make the List view. But I have several Problems. Let me tell You my case What I wanted to do.

Case : I want a list view with these twenty icons, two in each row, let say first row has two icons of two fags , say India and America , Now I want when User click on India Flag it should appear in next activity's image view and when user click on America Flag them it should appear. and so on with the other icons of other counteries flags.

What I Have Done : I have created a custom adapter but that working good for list view for single item in a row. Now How to implement the list view in the case I stated above. Some one please share me the Source code or Help me directly. I know its not too lengthy work but little tricky.

stacy queen
  • 280
  • 1
  • 4
  • 19
  • see [this answer](http://stackoverflow.com/questions/30118595/showdialog-in-button-listview-adapter/30119715#30119715) on how to achieve `onClick` of the item you want – hrskrs May 20 '15 at 12:06
  • do you want to show listview as a gridview ? – Anjali Tripathi May 20 '15 at 12:13
  • You need a custom adapter for your ListView ....Create Another layout inflate it in you custom adapter ( getViewmethod ) .... Use Holder and also Post your Code for better clarification – koutuk May 20 '15 at 12:27
  • @koutuk I told you I know I have to implement custom adapter, and I know how to make custom adapter for simple purpose. but Dont know How to implement it in my case. Please read question with open eyes – stacy queen May 20 '15 at 12:45

2 Answers2

1

you can set intent on onClickListener of imageview which will take user to desired activity..

for example :

    holder.ivFlagIndia.setOnClickListener(new OnClickListener{
         @Override
         public void onClick(View view)(
             Intent intent= new Intent(context,IndiaFlagActivity.class);
             context.startActivity(intent);
         )
    })

    holder.ivFlagAmerica.setOnClickListener(new OnClickListener{
             @Override
             public void onClick(View view)(
                 Intent intent= new Intent(context,AmericaFlagActivity.class);
                 context.startActivity(intent);
             )
    })
Naveen Rao
  • 712
  • 6
  • 10
1

Hope this may help.

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                im1 = (ImageView)view.findViewById(R.id.image_view1);
                im2 = (ImageView)view.findViewById(R.id.image_view2);
                if (id == 0)
                   {
                       im1.setOnClickListener(new View.OnClickListener() 
              {
            @Override
            public void onClick(View v) {
                Toast.makeText(v.getContext(),"Tutorials",Toast.LENGTH_SHORT).show();
                Intent i = new Intent(v.getContext(),Tutorial.class);
                startActivity(i);
            }
        });
        im2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {          
      Toast.makeText(v.getContext(),"Message",Toast.LENGTH_SHORT).show();
                Intent i = new Intent(v.getContext(),YourNewActivity.class);
                startActivity(i);
            }
        });
                   }
            }
        });