当前位置: 动力学知识库 > 问答 > 编程问答 >

Android : How to create advance (complex) Listview and to handle?

问题描述:

I am working android app, where i need a Listview which contain different types of view sets.

They have to update dynamically. i.e , initially i have some list of views, with one header.

Next when i click button i have to add new view set with different header. So can any one tell me . how to achive this complex listview.

ex.

My list looks like

initially looks like this

Countries (Header)

(Each row contain text and image)

  • India
  • Australia
  • America

next when i click button , i have to update listView like ....

Countries (Header)

(Each row contain text and image)

  • India
  • Australia
  • America

Currencies(Header)

(Each row contain textview button , progressBar)

  • Rupee
  • Australia dollar
  • Dollar

Can any one help me to resolve this ?

With some example ?

Thanking you,

Srinivas

网友答案:

You should set an Adapter to your ListView. Adapter will contain something like State member. In getView() State could be checked and the corresponding layout will be inflated to each item in the list. Does it fit your needs?

Example:

public enum States{
  Countries,
  Currencies
}

private States mState;

public View getView(int position, View convertView, ViewGroup parent)
{
LayoutInflater layoutInflater = LayoutInflater.from(context);
if( mState == States.Countries )
   {
      return layoutInflater.inflate(R.layout.countrie_layout, parent, false);
   }else if( mState == States.Currencies )
   {
      return layoutInflater.inflate(R.layout.currencie_layout, parent, false);
   }
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: